COSC 1306 COMPUTER SCIENCE AND PROGRAMMING

Slides:



Advertisements
Similar presentations
Programming for Beginners
Advertisements

Chapter 2: Your First Program! Hello World: Let’s Program  All programs must have the extension.java  Our first program will be named: HelloWorld.java.
Python Programming Chapter 1: The way of the program Saad Bani Mohammad Department of Computer Science Al al-Bayt University 1 st 2011/2012.
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.1 Introduction to Java.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
Compilers and Interpreters. Translation to machine language Every high level language needs to be translated to machine code There are different ways.
CS107 Introduction to Computer Science Java Basics.
Introduction to Programming (in C++) Introduction Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC.
C++ Crash Course Class 1 What is programming?. What’s this course about? Goal: Be able to design, write and run simple programs in C++ on a UNIX machine.
COSC 1306—COMPUTER SCIENCE AND PROGRAMMING FLOATING-POINT NUMBERS Jehan-François Pâris
CS190/295 Programming in Python for Life Sciences: Lecture 1 Instructor: Xiaohui Xie University of California, Irvine.
Computer Science 101 Introduction to Programming.
Python Mini-Course University of Oklahoma Department of Psychology Day 1 – Lesson 2 Fundamentals of Programming Languages 4/5/09 Python Mini-Course: Day.
Introducing Java.
An intro to programming. The purpose of writing a program is to solve a problem or take advantage of an opportunity Consists of multiple steps:  Understanding.
Introduction to Python
General Programming Introduction to Computing Science and Programming I.
Introduction to Computational Linguistics Programming I.
Computer Science 101 Introduction to Programming.
Programming Lifecycle
Java Programming, Second Edition Chapter One Creating Your First Java Program.
Week 1 - Friday.  What did we talk about last time?  Our first Java program.
Python From the book “Think Python”
Computer Science 101 Introduction to Programming.
Component 4: Introduction to Information and Computer Science Unit 5: Overview of Programming Languages, Including Basic Programming Concepts Lecture 2.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
A Python Tour: Just a Brief Introduction "The only way to learn a new programming language is by writing programs in it." -- B. Kernighan and D. Ritchie.
The single most important skill for a computer programmer is problem solving Problem solving means the ability to formulate problems, think creatively.
Lecture1 Instructor: Amal Hussain ALshardy. Introduce students to the basics of writing software programs including variables, types, arrays, control.
1. COMPUTERS AND PROGRAMS Rocky K. C. Chang September 6, 2015 (Adapted from John Zelle’s slides)
ITP 109 Week 2 Trina Gregory Introduction to Java.
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
CHAPTER 3 COMPLETING THE PROBLEM- SOLVING PROCESS AND GETTING STARTED WITH C++ An Introduction to Programming with C++ Fifth Edition.
Computer Programming Week 1: The Basics of CP 1 st semester 2012 School of Information Technology Website:
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
And now for something completely different…
Chapter 1. Introduction.
Information and Computer Sciences University of Hawaii, Manoa
Lecture 1b- Introduction
Introduction to Computing Science and Programming I
14 Compilers, Interpreters and Debuggers
Topic: Python’s building blocks -> Variables, Values, and Types
A Python Tour: Just a Brief Introduction
Topic: Programming Languages and their Evolution + Intro to Scratch
Introduction to programming
Lecture 1 Introduction Richard Gesick.
Introduction to Computer Science
Programming Language Hierarchy, Phases of a Java Program
CSCI-235 Micro-Computer Applications
Lecture 1: Introduction to JAVA
COSC 1306 COMPUTER SCIENCE AND PROGRAMMING
Data types and variables
A451 Theory – 7 Programming 7A, B - Algorithms.
Programming Concepts and Languages
COSC 1306 COMPUTER SCIENCE AND PROGRAMMING
CS190/295 Programming in Python for Life Sciences: Lecture 1
String Output ICS 111: Introduction to Computer Science I
Introduction CSC 111.
Programming.
PROGRAMMING FUNDAMENTALS Lecture # 03. Programming Language A Programming language used to write computer programs. Its mean of communication between.
15-110: Principles of Computing
Tonga Institute of Higher Education IT 141: Information Systems
Tonga Institute of Higher Education IT 141: Information Systems
Chapter 1: Programming Basics, Python History and Program Components
Computer Programming-1 CSC 111
1.3.7 High- and low-level languages and their translators
Programming language translators
Instructor: Alexander Stoytchev
Dasar-Dasar Pemrograman 2: Java Basics
Week 1 - Friday COMP 1600.
Presentation transcript:

COSC 1306 COMPUTER SCIENCE AND PROGRAMMING Jehan-François Pâris jfparis@uh.edu Fall 2016 1

THE ONLINE BOOK CHAPTER I GENERAL INTRODUCTION

Algorithms Problem solving is coming with an algorithm that can serve as a general solution

High-level languages Very few programs are written in machine language Prefer to use a more human-friendly high-level language Cannot be directly executed by any computer Must be first translated Two approaches Compiled languages Interpreted languages

Compiled languages (I) Programs written in old Fortran, C, C++ and so on must go through a program that translates them into directly executable code The compiler Doing g++ myprogram.cpp –o myprogram produces an executable file called myprogram that can run anytime No need to recompile

Compiled languages (II) C program C compiler Executable

Advantages The executable can run on any computer with Same CPU instruction set Same—or compatible—operating system We can sell copies of the executable without revealing the secrets of our program Reverse engineering is possible but very time-consuming

Interpreted languages (I) Languages like Basic, Perl, Python and Ruby are not compiled Translated again and again into bytecode Each time we execute them Bytecode is interpreted by the language interpreter

Interpreted languages (II) Python Program Byte code Python Interpreter: translates program into bytecode then executes it

Advantages Platform independence: Bytecode can run on any platform for which there is an interpreter Dynamic typing: Same variable can refer to a string then an integer then … Smaller executable sizes

Disadvantages Portability limitations : Bytecode will not run on any machine on which the interpreter was not installed. Speed: Bytecode is not optimized for a specific architecture Just-in-time compilation introduces delays Cannot sell a copies of a program without revealing its source code

A partial solution In many cases, speed is not an issue outside of loops than get executed thousand and thousands of times Loops inside other loops Can rewrite code for these inner loops in C and include this code into a Python program Use Python C API

Neither fish nor fowl Java is compiled Like Fortran, C, … into bytecode Like Perl and Python Bytecode is executed by Java Virtual Machine

A comparison Compiled languages Translate once the whole program into an executable Fast Can run on any machine having same architecture and same OS Interpreted languages Translate programs line by line each time they are executed Much slower Can run on any machine having the interpreter installed

My first program print(“My first program adds two numbers, 2 and 3”) It’s “print” and not “Print” Cannot use smart quotes Semicolons are optional and nobody uses them

Types of instructions Input & output name = input(“Enter your name: ”) Print(“Hello!”) Math and logic celsius = (fahrenheit - 32)* 5/9 Conditional execution if celsius > 100 : Repetition For all lines in file:

Debugging Finding what’s wrong in your program Finding the roof of the problem Fixing the error

Types of error Syntax errors print(“Hello!” “How are you:”) # missing comma Run-time errors Division by zero Semantic errors Your solution is wrong You expressed it poorly

Experimental debugging (I) Modify your program until it works?

Experimental debugging (II) Look at your program Try to explain it to yourself, to friends Do not let them copy your code! Add print statements after each step Remove them or better comment them out when they are not needed anymore.

Interactive Python Requires Javascript to be authorized for at least interactivepython.org

Natural and formal languages Natural languages are complex, tolerate ambiguities, often have to be taken figuratively I am literally dying of thirst Could you bring me a glass of water? Formal languages are simpler, have much more strict syntax rules, and want to be unambiguous What they say will be taken literally

Natural language ambiguities KIDS MAKE NUTRITIOUS SNACKS STOLEN PAINTING FOUND BY TREE QUEEN MARY HAVING BOTTOM SCRAPED MILK DRINKERS ARE TURNING TO POWDER SQUAD HELPS DOG BITE VICTIM

Commenting Main purpose To help human readers understand your programs Becomes more important as program sizes grow To record who wrote the program, when it happened and so on

In-line comments Anything following a pound sign (“#”) is ignored by the Python interpreter print (“Hello World!”) print (“Hello World!”) # not very original r = d/2 # compute radius of circle #Begin main loop

Multi-line comments Anything between three double quotes—”””—is ignored by the Python interpreter “”” Tell what the program does Jehan-Francois Paris Assignment # 1 COSC 1306 MW 2:30-4:00 Fall 2016 “”” At the beginning of each program