1 Computer Programming Course Details An Introduction to Computational Tools Prof. Mauro Gaspari:
2 Road map for today The skills that we would like you to acquire: to think like a computer scientist. Course organization. Exams. Course material. An introduction to computational tools. Getting started.
3 To think like a Computer Scientist... To understand computational tools and terminology. To use these basic tools to write small scale programs. To understand programs written by others. To understand both capabilities and limitations of computational tools. To map (qf) problems into computational solutions.
4 Python Computational solution will be implemented in Python a modern programming language. This course is not about Python (e.g. studying Python details), but it is about using it to think and build computational solutions. Warning!!! reading the textbook is not enough, exercises are fundamental.
5 Course Organization Interactive approach learning by doing Interactive Lectures: Exercises solved in class (workgroup sessions) Individual support (tutor: Dr. Giulio Pellitta Home assigments (warning home work is mandatory!!!)
6 Course Material TextBook: How to Think Like a Computer Scientist: Learning with Python, by Allen Downey, Jeff Elkner and Chris Meyers. Gree Tea Press (available online here: Web site: Slides Readings and Links Online software and documentation: Python site: There is an Italian version too:
7 Exam The Exam of Computer Programming is organized in two sequential steps: A PROGRAMMING TEST (yes/no) A DISCUSSION OF A PROJECT Passing the PROGRAMMING TEST is mandatory for the PROJECT assignment and thus for starting the second step. Home work assignments are also evaluated: They are assigned at the end of each week (Thursday); They must be completed and sent by to and before the first lesson of the next week (11am Wednesday).
8 Exam: discussion of a (qf) project Procedure: Discussion: Set up a group (2 or 3 students for each group). Propose a (qf) problem and submit a specification of what the program will do. When approved implement a computational solution. Group discussion (problem and solution) => GroupVote Individual verifications for each student (s) in the group => Decrement(s) Individual home work assignment ( 1 penalty for each home work not completed) for each student (s) => HWP(s) Vote(s) = GroupVote Decrement(s) HWP(s)
9 Computational tools and problem solving Computational tools are used for problem solving. Humans are problem solvers: we use knowledge to solve problems. What is knowledge? We can divide knowledge into at least two categories: Declarative knowledge Imperative knowledge
10 Example: Greatest Common Divisor DECLARATIVE KNOWLEDGE: A, B are positive integer, X = GCD(A,B) then: The remainder of both A/X and B/X is equal to 0 and, If exists Y X such that the remainder of both A/Y and B/Y is equal to 0 then X > Y IMPERATIVE KNOWLEDGE (EUCLID) IF A<B, exchange A and B. Divide A by B and get the remainder, R. If R=0, GCD(A,B) = B. Replace A by B and replace B by R. Return to the previous step. IMPERATIVE KNOWLEDE IS THE RECIPE!
11 What is a Computation? A computation is a recipe: a sequence of (simple) instructions (this is also called program). Is it possible to build a mechanical process to capture that set of computations? Yes, for example building a simple circuit to do this: fixed-program computer (for example a dishwasher program). General purpose computer are more complex, they are circuit able to take a recipe (list of simple instructions) as an input, reconfigure themselves and act as the recipe.
12 How they work? Registers IR CU PC Program instr1 instr instrn PC ALU R A M Capacity in Bytes (8 bit) Von Neumann Machine CPU MEMORY BUS Op code. op1 op2 ris Speed in Hertz Instructions How many instructions in a second
13 What is a program? Programs are written using programming languages. Source code: instructions of a given program. Program Tombstone Diagrams A program P written In a Language L P L Source code of a program P written In language L is usually stored in file and loaded in memory
14 Which Programming Languages? High level Languages Python, C, C++, Perl, Java, Lisp, Prolog. Thus there is also a low level Machine language Assembler
15 High-level vs low-level High-level Languages... print b*h/2... Low-level Languages LOAD r1,b LOAD r2,h MUL r1,r2 DIV r1,#2 RET Assembler Machine Language
16 Machine Language Computer are only able to execute machine language instructions. Different computers may have different machine languages. Computer Tombstone Diagram A computer having a machine language M is represented with the following tombstone diagram M
17 Program execution A computer can only execute programs written in its machine language P M M
18 Problems of machine languages Write programs in machine language is almost impossible. The first computers were programmed in this way. Now low level languages are used only for a few specialized applications. Almost all programs are written in high level programming languages. Rapid development Portable code
19 However Apparently high level languages cannot be directly executed on computers. A program P written in L cannot be executed on a machine M. P L M
20 Programming Language Processors Specific tools to support the execution of highlevel programming languages: Interpreters. Compilers.
21 Interpreter An interpreter for a language L is a program that takes as input a program written in L and executes it instraction by instraction. An interpreter can be written in machine language. Interpreter Tombstone Diagram An interpreter for a language L written in M. L M
22 Executing Python programs The python interpreter allows a user to execute a program P written in Python in computer M. This means that Python an interpreted language. P Python Python M M
23 Compilers A compiler is a program which translates source code (usually written in a given high level language) into object code usually written in machine language. Compiler Tombstone Diagram A compiler which translates source code written in a langusge L into object code written in machine language M. L -> M M
24 Using a compiler Source code P L L -> M P M Executable object code Note that a compiler is a program, thus it must be executed on the right machine as other programs are. M M M
25 Instructions input: Get data from the keyboard, a file, or some other device. output: Display data on the screen or send data to a file or other device. math: Perform basic mathematical operations like addition and multiplication. conditional execution: Check for certain conditions and execute the appropriate code. repetition: Perform some action repeatedly, usually with some variation. Programming = the process of breaking a complex task into smaller and smaller subtasks until the subtasks are simple enough to be performed with one of these basic instructions.
26 Bugs and Debugging! Bugs Debugging (the process of tracking down bugs) Why we introduce this concept here? Is an essential skill associated to computer programming. In principle all the programs may have bugs! Bugs are frequent in programming, but they can be solved with debugging!
27 Different kinds of errors Syntax errors: Python can only execute a program if the syntax is correct; otherwise, the interpreter displays an error message. Syntax refers to the structure of a program and the rules about that structure. If there is a single syntax error anywhere in your program, Python will display an error message and quit. Runtime errors: these errors do not appear until after the program has started running. These errors are also called exceptions because they usually indicate that something exceptional (and bad) has happened. Semantic errors: If there is a semantic error in your program, it will run successfully (without error messages), but it will not do the right thing. It will do something else. The meaning of the program (its semantics) is wrong. Identifying semantic errors can be very tricky.
28 Debugging Debugging is like detective work: you are confronted with clues, and you have to infer the processes and events that led to the results you see. Experimental science; you have an idea about what is going wrong, you modify your program and try again. If your hypothesis was correct, then you can predict the result of the modification, and you take a step closer to a working program. If your hypothesis was wrong, you have to come up with a new one. Sherlock Holmes When you have eliminated the impossible, whatever remains, however improbable, must be the truth. Programming => debugging: programming is the process of gradually debugging a program until it does what you want.
29 Formal languages Natural languages are the languages people speak, such as English, Spanish, and French. They were not designed by people they evolved naturally. Formal languages are languages that are designed by people for specific applications. For example, the notation that mathematicians use is a formal language that is particularly good at denoting relationships among numbers and symbols. Programming languages are formal languages that have been designed to express computations.
30 Syntax Formal languages tend to have strict rules about syntax. For example, = 6 is a syntactically correct mathematical statement, but 3+ = 3$6 is not. Two levels of syntax rules: Tokens are the basic elements of the language, such as words, numbers, and chemical elements. One of the problems with 3+ = 3$6 is that $ is not a legal token in mathematics. Structure of a statement: the way the tokens are arranged. The statement 3+ = 3 is illegal because even though + and = are legal tokens, you can t have one right after the other. Parsing: is the process that analyse a sentence finding and understanding its structure.
31 Formal Languages vs Natural Languages Although formal and natural languages have many features in common tokens, structure, syntax, and semantics there are some differences: ambiguity: Natural languages are full of ambiguity, which people deal with by using contextual clues and other information. Formal languages are designed to be nearly or completely unambiguous. redundancy: In order to make up for ambiguity and reduce misunderstandings, natural languages employ lots of redundancy. As a result, they are often verbose. Formal languages are less redundant and more concise. literalness: Natural languages are full of idiom and metaphor. Formal languages mean exactly what they say.
32 Semantics Semantics: concerns the meaning of instructions, thus the meaning of the constructs of the language. Semantics of programming languages: Informal semantics (manual). Formal semantics (computer scientists): useful for building programming languages processors.
33 Getting Started Python installation you should install the last 2.7 version The last version of python is 3.3. and it is slightly different from version 2.7. The most significant differences are reported in the textbook. Python interpreter Python IDE: include a text editor specific for programming and debugging tools.
34 The python interpreter Python is an interpreted language. There are two ways to use the interpreter: Interactive mode: you type Python programs and the interpreter displays the result: >>> Script mode: you can store code in a file and use the interpreter to execute the contents of the file (script). By convention, Python scripts have names that end with.py.
35 Script execution To execute the script, you have to tell the interpreter the name of the file. If you have a script named hello.py alond you are working in a UNIX command window, you type: python hello.py In other development environments, the details of executing scripts are different. Environment based on graphical user interfaces usually have a specific run botton or menu item to execute the script. You can find instructions for your environment at the Python website
36 The first program Traditionally, the first program you write in a new language is called Hello, World! because it just prints this sentence. In Python, the implementation is very simple: print 'Hello, World!' This is an example of a print statement, which displays a value on the screen (output statement). The quotation marks in the program mark the beginning and end of the text to be displayed.
37 Exercises Try the interpreter. Run the Hello World program both in the interpreter and as a script.
CSCI 3136 Principles of Programming Languages Faculty of Computer Science Dalhousie University Winter 2013 CSCI 3136 Principles of Programming Languages Faculty of Computer Science Dalhousie University
CS 40 Computing for the Web Art Lee January 20, 2015 Announcements Course web on Sakai Homework assignments submit them on Sakai Email me the survey: See the Announcements page on the course web for instructions
COMP150: Practical Programming (in Python) Jeffrey Elkner Allen B. Downey Chris Meyers Brendan McCane Iain Hewson Nick Meek June 22, 2009 ii Contents 1 The way of the program 1 1.1 The Python programming
Overview Introduction Motivation Why study programming languages? Some key concepts What is a programming language? Artificial language" Computers" Programs" Syntax" Semantics" What is a programming language?...there
http://www.webcartoonmaker.com Copyright Information This book is an Open Source Textbook (OST). Permission is granted to reproduce, store or transmit the text of this book by any means, electrical, mechanical,
INTRODUCTION 1 Programming languages have common concepts that are seen in all languages This course will discuss and illustrate these common concepts: Syntax Names Types Semantics Memory Management We
Introduction to Programming and Algorithms Module 1 CS 146 Sam Houston State University Dr. Tim McGuire Module Objectives To understand: the necessity of programming, differences between hardware and software,
Computer Science 217 Midterm Exam Fall 2009 October 29, 2009 Name: ID: Instructions: Neatly print your name and ID number in the spaces provided above. Pick the best answer for each multiple choice question.
How to Think Like a Computer Scientist C Version Allen B. Downey C-Version by Thomas Scheffler Version 1.08 November 25th, 2012 2 Copyright (C) 1999 Allen B. Downey This book is an Open Source Textbook
Think Java How to Think Like a Computer Scientist Allen B. Downey 5.1.2 Copyright 2012 Allen Downey. Permission is granted to copy, distribute, transmit and adapt this work under a Creative Commons Attribution-NonCommercial-ShareAlike
How to Think Like a Computer Scientist Java Version ii How to Think Like a Computer Scientist Java Version Allen B. Downey Version 4.0 March 6, 2003 Copyright c 2003 Allen Downey. Permission is granted
Chapter 1 CS-4337 Organization of Programming Languages Dr. Chris Irwin Davis Email: email@example.com Phone: (972) 883-3574 Office: ECSS 4.705 Chapter 1 Topics Reasons for Studying Concepts of Programming
Semester Review CSC 301, Fall 2015 Programming Language Classes There are many different programming language classes, but four classes or paradigms stand out:! Imperative Languages! assignment and iteration!
Chapter 1 INTRODUCTION TO COMPUTING AND ENGINEERING PROBLEM SOLVING Outline Objectives 1. Historical Perspective 2. Recent Engineering Achievements 3. Computing Systems 4. Data Representation and Storage
CS 16: Assembly Language Programming for the IBM PC and Compatibles First, a little about you Your name Have you ever worked with/used/played with assembly language? If so, talk about it Why are you taking
Welcome to Introduction to Computers and Programming Course using Python V22.0002, Section 3, Spring 2010 Course Introduction Professor: Sana Odeh firstname.lastname@example.org Office hours: Mondays 2:00 pm - 4
Programming Languages Qing Yi Course web site: www.cs.utsa.edu/~qingyi/cs3723 cs3723 1 A little about myself Qing Yi Ph.D. Rice University, USA. Assistant Professor, Department of Computer Science Office:
CS 51 Intro to CS Art Lee September 2, 2014 Announcements Course web page at: http://www.cmc.edu/pages/faculty/alee/cs51/ Homework/Lab assignment submission on Sakai: https://sakai.claremont.edu/portal/site/cx_mtg_79055
CS101 Lecture 24: Thinking in Python: Input and Output Variables and Arithmetic Aaron Stevens 28 March 2011 1 Overview/Questions Review: Programmability Why learn programming? What is a programming language?
An Introduction to Computer Science and Computer Organization Comp 150 Fall 2008 Computer Science the study of algorithms, including Their formal and mathematical properties Their hardware realizations
Understanding Computers Today and Tomorrow 12 th Edition Chapter 13: Program Development and Programming Languages Learning Objectives Understand the differences between structured programming, object-oriented
How to Think Like a Computer Scientist How to Think Like a Computer Scientist: Learning with Python 2nd Edition documentation next index How to Think Like a Computer Scientist: Learning with Python 2nd
15 th Edition Understanding Computers Today and Tomorrow Comprehensive Chapter 13: Program Development and Programming Languages Deborah Morley Charles S. Parker Copyright 2015 Cengage Learning Learning
Course Organization Introduction CSE 307: Principles of Programming Languages Spring 2015 R. Sekar Course Organization Introduction 1 / 34 Topics 1. Course Organization Info and Support Course Description
River Dell Regional School District Computer Programming with Python Curriculum 2015 Mr. Patrick Fletcher Superintendent River Dell Regional Schools Ms. Lorraine Brooks Principal River Dell High School
Python Programming: An Introduction to Computer Science Chapter 1 Computers and Programs 1 Objectives To understand the respective roles of hardware and software in a computing system. To learn what computer
Levels of Programming Languages Gerald Penn CSC 324 Levels of Programming Language Microcode Machine code Assembly Language Low-level Programming Language High-level Programming Language Levels of Programming
As you arrive: 1. Start up your computer and plug it in. 2. Log into Angel and go to CSSE 120. Do the Attendance Widget the PIN is on the board. 3. Go to the Course Schedule web page. Open the Slides for
Fall 2012 Q530 Programming for Cognitive Science Aimed at little or no programming experience. Improve your confidence and skills at: Writing code. Reading code. Understand the abilities and limitations
LING115 Lecture Note Session #4 Python (1) 1. Introduction As we have seen in previous sessions, we can use Linux shell commands to do simple text processing. We now know, for example, how to count words.
How to think like a computer scientist Allen B. Downey November 2012 2 How to think like a computer scientist C++ Version Copyright (C) 2012 Allen B. Downey Permission is granted to copy, distribute, and/or
Computer Programming I & II* Career Cluster Information Technology Course Code 10152 Prerequisite(s) Computer Applications, Introduction to Information Technology Careers (recommended), Computer Hardware
How to Think Like a Computer Scientist: Learning with Python Documentation Jeffrey Elkner, Allen B. Downey and Chris Meyers October 21, 2015 CONTENTS 1 Learning with Python 3 1.1 Copyright Notice...................................
Software Engineering Architectural Design 1 Software architecture The design process for identifying the sub-systems making up a system and the framework for sub-system control and communication is architectural
Python Programming: An Introduction to Computer Science Chapter 1 Computers and Programs 1 The Universal Machine n A computer -- a machine that stores and manipulates information under the control of a
Embedded Systems A Review of ANSI C and Considerations for Embedded C Programming Dr. Jeff Jackson Lecture 2-1 Review of ANSI C Topics Basic features of C C fundamentals Basic data types Expressions Selection
Python Programming: An Introduction to Computer Science Chapter 1 Computers and Programs Objectives Introduction to the class Why we program and what that means Introduction to the Python programming language
Lecture 14 Let s put together a Manual Processor Hardware Lecture 14 Slide 1 The processor Inside every computer there is at least one processor which can take an instruction, some operands and produce
1 INTRODUCTION 1.1 What is a Programming Language? 1.2 Abstractions in Programming Languages 1.3 Computational Paradigms 1.4 Language Definition 1.5 Language Translation 1.6 Language Design How we communicate
Chapter 12 Programming Concepts and Languages Chapter 12 Programming Concepts and Languages Paradigm Publishing, Inc. 12-1 Presentation Overview Programming Concepts Problem-Solving Techniques The Evolution
CSC 3210 Computer Organization and Programming Introduction and Overview Dr. Anu Bourgeois (modified by Yuan Long) Administrative Issues Required Prerequisites CSc 2010 Intro to CSc CSc 2310 Java Programming
Introduction Welcome to our Python sessions. University of Hull Department of Computer Science Wrestling with Python Week 01 Playing with Python Vsn. 1.0 Rob Miles 2013 Please follow the instructions carefully.
Lesson Unit 1: INTRODUCTION TO COMPUTERS Computer History Create a timeline illustrating the most significant contributions to computing technology Describe the history and evolution of the computer Identify
3 SOFTWARE AND PROGRAMMING LANGUAGES 3.1 INTRODUCTION In the previous lesson we discussed about the different parts and configurations of computer. It has been mentioned that programs or instructions have
4 Programming Languages & Tools Almost any programming language one is familiar with can be used for computational work (despite the fact that some people believe strongly that their own favorite programming
Embedded Software development Process and Tools: Lesson-3 Host and Target Machines 1 1. Host-Target Based Development Approach 2 Host-Target System Development Approach During development process, a host
Concepts of Programming Languages Robert W. Sebesta Chapter 1 Preliminaries Reasons for studying the underlying concepts of programming languages The Study of Programming Languages Increases our ability
The programming language C sws1 1 The programming language C invented by Dennis Ritchie in early 1970s who used it to write the first Hello World program C was used to write UNIX Standardised as K&C (Kernighan
CHAPTER 1 ENGINEERING PROBLEM SOLVING Computing Systems: Hardware and Software The processor : controls all the parts such as memory devices and inputs/outputs. The Arithmetic Logic Unit (ALU) : performs
Principles of Programming Languages Prof: S. Arun Kumar Department of Computer Science and Engineering Indian Institute of Technology Delhi Lecture no 7 Lecture Title: Syntactic Classes Welcome to lecture
CHAPTER 1 Chapter Goals To learn about computers and programming To compile and run your first Java program To recognize compile-time and run-time errors To describe an algorithm with pseudocode In this
Algorithms Algorithms 1 Algorithms are the threads that tie together most of the subfields of computer science. Something magically beautiful happens when a sequence of commands and decisions is able to
J.NAWROCKI, M. ANTCZAK, H. ĆWIEK, W. FROHMBERG, A. HOFFA, M. KIERZYNKA, S. WĄSIK IMPERATIVE PROGRAMMING C LANGUAGE EX. 1. Write in C language programs described below, compile them and tentatively debug:
CS101 Lecture 26: Low Level Programming John Magee 30 July 2013 Some material copyright Jones and Bartlett 1 Overview/Questions What did we do last time? How can we control the computer s circuits? How
Answer first, then check at the end. Review questions for Chapter 9 True/False 1. A compiler translates a high-level language program into the corresponding program in machine code. 2. An interpreter is
CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 18: Intermediate Code 29 Feb 08 CS 412/413 Spring 2008 Introduction to Compilers 1 Summary: Semantic Analysis Check errors not detected by lexical
Chapter 13 Computer Programs and Programming Languages Discovering Computers 2012 Your Interactive Guide to the Digital World Objectives Overview Differentiate between machine and assembly languages Identify
Oracle Academy Introduction to Database Programming with Instructor Resource Guide INSTRUCTOR NOTES FOR SLIDES SECTION 1 LESSON 1 Introduction to Slide 1: Introduction to Slide 2: What Will I Learn? Slide
CE 504 Computational Hydrology Computational Environments and Tools Fritz R. Fiedler 1) Operating systems a) Windows b) Unix and Linux c) Macintosh 2) Data manipulation tools a) Text Editors b) Spreadsheets
C H A P T E R 4 Software: Systems and Application Software Software and Hardware Software can represent 75% or more of the total cost of an IS. Less costly hdwr. More complex sftwr. Expensive developers
Scripting with TCL, Part 1 Axel Kohlmeyer Center for Molecular Modeling University of Pennsylvania SBS 2007 @ JNCASR, Bangalore The VMD Execution Model GUI (FLTK) Internal State Visualization Python Interpreter
1 Introduction The purpose of this assignment is to write an interpreter for a small subset of the Lisp programming language. The interpreter should be able to perform simple arithmetic and comparisons
1.1 McGraw-Hill The McGraw-Hill Companies, Inc., 2000 Objectives: To describe the evolution of programming languages from machine language to high-level languages. To understand how a program in a high-level
CS 106 Introduction to Computer Science I 01 / 21 / 2014 Instructor: Michael Eckmann Today s Topics Introduction Homework assignment Review the syllabus Review the policies on academic dishonesty and improper
Language Processing Systems Evaluation Active sheets 10 % Exercise reports 30 % Midterm Exam 20 % Final Exam 40 % Contact Send e-mail to email@example.com Course materials at www.u-aizu.ac.jp/~hamada/education.html
Introduction & Procedural Programming Sample Courseware Introduction to Software Paradigms & Procedural Programming Paradigm This Lesson introduces main terminology to be used in the whole course. Thus,
PHP Debugging Draft: March 19, 2013 2013 Christopher Vickery Introduction Debugging is the art of locating errors in your code. There are three types of errors to deal with: 1. Syntax errors: When code
How to make the computer understand? Fall 2005 Lecture 15: Putting it all together From parsing to code generation Write a program using a programming language Microprocessors talk in assembly language
CS 3530 Operating Systems L02 OS Intro Part 1 Dr. Ken Hoganson Chapter 1 Basic Concepts of Operating Systems Computer Systems A computer system consists of two basic types of components: Hardware components,
High level code and machine code Teacher s Notes Lesson Plan x Length 60 mins Specification Link 2.1.7/cde Programming languages Learning objective Students should be able to (a) explain the difference
Building Applications Using Micro Focus COBOL Abstract If you look through the Micro Focus COBOL documentation, you will see many different executable file types referenced: int, gnt, exe, dll and others.
An Overview of a Compiler Department of Computer Science and Automation Indian Institute of Science Bangalore 560 012 NPTEL Course on Principles of Compiler Design Outline of the Lecture About the course
Unit- I Introduction to c Language: C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating
M01_GADD7119_01_SE_C01.QXD 1/30/08 12:55 AM Page 1 CHAPTER 1 Introduction to Computers and Programming TOPICS 1.1 Introduction 1.2 Hardware and Software 1.3 How Computers Store Data 1.4 How a Program Works
High-Level Programming Languages Nell Dale & John Lewis (adaptation by Michael Goldwasser) Low-Level Languages What are disadvantages of low-level languages? (e.g., machine code or assembly code) Programming
COMP 356 Programming Language Structures Notes for Chapter 4 of Concepts of Programming Languages Scanning and Parsing The scanner (or lexical analyzer) of a compiler processes the source program, recognizing
Chapter 11: Input/Output Organisation Lesson 06: Programmed IO Objective Understand the programmed IO mode of data transfer Learn that the program waits for the ready status by repeatedly testing the status
Programming Languages Programming languages bridge the gap between people and machines; for that matter, they also bridge the gap among people who would like to share algorithms in a way that immediately
A Python Tour: Just a Brief Introduction CS 303e: Elements of Computers and Programming "The only way to learn a new programming language is by writing programs in it." -- B. Kernighan and D. Ritchie "Computers
CSC230 Getting Starting in C Tyler Bletsch What is C? The language of UNIX Procedural language (no classes) Low-level access to memory Easy to map to machine language Not much run-time stuff needed Surprisingly