Computing Science 1P Lecture 21: Friday 20 th April Simon Gay Department of Computing Science University of Glasgow 2006/07.

Slides:



Advertisements
Similar presentations
Introduction to Programming Languages Nai-Wei Lin Department of Computer Science and Information Engineering National Chung Cheng University.
Advertisements

CS0004: Introduction to Programming Introduction to Programming.
Programming TBE 540 Farah Fisher. Objectives After viewing this presentation, the learner will be able to… Given a task, create pseudocode Given pseudocode,
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Python Programming Chapter 1: The way of the program Saad Bani Mohammad Department of Computer Science Al al-Bayt University 1 st 2011/2012.
CS 330 Programming Languages 10 / 16 / 2008 Instructor: Michael Eckmann.
Reasons to study concepts of PL
COMP 14: Primitive Data and Objects May 24, 2000 Nick Vallidis.
String Escape Sequences
CSE 1301 J Lecture 2 Intro to Java Programming Richard Gesick.
Python. What is Python? A programming language we can use to communicate with the computer and solve problems We give the computer instructions that it.
PYTHON: LESSON 1 Catherine and Annie. WHAT IS PYTHON ANYWAY?  Python is a programming language.  But what’s a programming language?  It’s a language.
CS190/295 Programming in Python for Life Sciences: Lecture 1 Instructor: Xiaohui Xie University of California, Irvine.
CSE 131 Computer Science 1 Module 1: (basics of Java)
ITP © Ron Poet Lecture 1 1 IT Programming Introduction.
Language Evaluation Criteria
Python Mini-Course University of Oklahoma Department of Psychology Day 1 – Lesson 2 Fundamentals of Programming Languages 4/5/09 Python Mini-Course: Day.
Introduction to Python Lecture 1. CS 484 – Artificial Intelligence2 Big Picture Language Features Python is interpreted Not compiled Object-oriented language.
Chapter 8 High-Level Programming Languages (modified by Erin Chambers)
Computing Science 1P Large Group Tutorial 17 Simon Gay Department of Computing Science University of Glasgow 2006/07.
1-1 University of Hail College of Computer Science and Engineering Department of computer Science and Software Engineering Course: ICS313: Fundamentals.
Introduction to Computers and Programming – Computer Programming.
CSC3315 (Spring 2009)1 CSC 3315 Programming Languages Hamid Harroud School of Science and Engineering, Akhawayn University
©Xiaoying Gao, Peter Andreae First Java Program COMP 102 #2 2014T2 Xiaoying Sharon Gao Computer Science Victoria University of Wellington.
Programming Languages: History & Traditional Concepts CSC 2001.
Computer Science 101 Introduction to Programming.
Session One Introduction. Personal Introduction Role of programmers Robot Examination HUD & HID Uploading Code.
First Java Program COMP 102 #2 2015T2 Xiaoying Sharon Gao Computer Science Victoria University of Wellington.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 13: An Introduction to C++
Computing Science 1P Lecture 18: Friday 2 nd March Simon Gay Department of Computing Science University of Glasgow 2006/07.
CSE 131 Computer Science 1 Module 1: (basics of Java)
Computer Science 101 Introduction to Programming.
Basics of Java IMPORTANT: Read Chap 1-6 of How to think like a… Lecture 3.
By the end of this session you should be able to...
Computing Science 1P Lecture 17: Friday 23 rd February Simon Gay Department of Computing Science University of Glasgow 2006/07.
Computing Science 1P Lecture 21: Wednesday 18 th April Simon Gay Department of Computing Science University of Glasgow 2006/07.
Chapter 6 Programming Languages (1) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
COMP 171: Data Types John Barr. Review - What is Computer Science? Problem Solving  Recognizing Patterns  If you can find a pattern in the way you solve.
Computing Science 1P Lecture 14: Friday 2 nd February Simon Gay Department of Computing Science University of Glasgow 2006/07.
Types in programming languages1 What are types, and why do we need them?
Computing Science 1P Large Group Tutorial: Lab Exam & Class Test Simon Gay Department of Computing Science University of Glasgow 2006/07.
ECET – Dynamic Programming with Python Spring 2013 Lecture L1 – Introduction to Python Page 1 Welcome! This is Professor Jai P. Agrawal. I will walk.
Computing Science 1P Large Group Tutorial 13 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Computing Science 1P Large Group Tutorial 14 Simon Gay Department of Computing Science University of Glasgow 2006/07.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
Programming Languages
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
CPS120: Introduction to Computer Science Variables and Constants.
Software Development Introduction
Objective You will be able to define the basic concepts of object-oriented programming with emphasis on objects and classes by taking notes, seeing examples,
The single most important skill for a computer programmer is problem solving Problem solving means the ability to formulate problems, think creatively.
CSE 130 : Winter 2009 Programming Languages Lecture 11: What’s in a Name ?
CS 106 Introduction to Computer Science I 09 / 10 / 2007 Instructor: Michael Eckmann.
Types and Programming Languages Lecture 3 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Python Programming Language by Vasu Chetty. Origins of Python Created by: Guido van Rossum, a Dutch Programmer Created during: Christmas Break, 1989 Created.
Programming Languages Salihu Ibrahim Dasuki (PhD) CSC102 INTRODUCTION TO COMPUTER SCIENCE.
Topic: Python’s building blocks -> Variables, Values, and Types
Topic: Programming Languages and their Evolution + Intro to Scratch
Topic: Python’s building blocks -> Variables, Values, and Types
Programming Mehdi Bukhari.
Introduction to Programmng in Python
Lecturer: Mukhtar Mohamed Ali “Hakaale”
College of Computer Science and Engineering
First Python Program Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming: An.
CS110D Programming Language I
General Computer Science for Engineers CISC 106 Lecture 03
PRESENTED BY ADNAN M. UZAIR NOMAN
Programming for Business Computing Introduction
Presentation transcript:

Computing Science 1P Lecture 21: Friday 20 th April Simon Gay Department of Computing Science University of Glasgow 2006/07

Computing Science 1P Lecture 21 - Simon Gay2 What's coming up? Fri 20 th April (today):lecture Mon 23 rd April, :FPP demo session; PRIZES! Mon 23 rd – Wed 25 th April:labs: exam preparation / lab exam preparation Wed 25 th April:lecture / tutorial Friday 27 th April:lecture: revision / questions with Peter Saffrey Mon 30 th April – Wed 2 nd May:Lab Exam Wed 2 nd May:No lecture Fri 4 th May:No lecture THE END

2006/07Computing Science 1P Lecture 21 - Simon Gay3 Life after Python Python is just one of a huge range of programming languages that have been introduced during the last 50 years. If you continue with Computing Science in your second year, you will learn a different language: Java. (You will also learn C in third year, and perhaps others.)

2006/07Computing Science 1P Lecture 21 - Simon Gay4 John Backus, inventor of Fortran John Backus developed Fortran, one of the first high-level programming languages, in John Backus died on 17th March 2007.

2006/07Computing Science 1P Lecture 21 - Simon Gay5 Python vs Java The basic ideas of programming, learnt in Python, are also essential for Java: variables statements and expressions sequencing, loops, conditionals, functions data structures: lists, dictionaries problem-solving and planning testing and debugging But there are some important differences, too.

2006/07Computing Science 1P Lecture 21 - Simon Gay6 Differences between Python and Java 1. The programming environment 2. Java uses static typing 3. Object-oriented programming

2006/07Computing Science 1P Lecture 21 - Simon Gay7 The programming environment Recall the difference between an interpreter and a compiler. An interpreter looks at your program one statement at a time, and does whatever it should do. Example: the interpreter for the drawing language, in the Unit 13 exercise. A compiler translates your whole program into machine language, giving you something that can be executed independently. Example: most software development

2006/07Computing Science 1P Lecture 21 - Simon Gay8 The programming environment The Python system we have been using (IDLE) is an interactive interpreter: you can type programs straight into the shell window. The normal way of using Java is with a compiler. There is nowhere you can simply type expressions to see what they do. Java programmers usually use an integrated development environment (IDE) such as Eclipse. In Level 2 CS, you can expect a Java IDE which is more powerful than IDLE, but may be a little harder to learn.

2006/07Computing Science 1P Lecture 21 - Simon Gay9 Static typing Types are very important in almost all programming languages. Examples in Python: int, string, float, list, … All data naturally has a type and this determines which operations make sense. 1 + “hello” is meaningless (unless we invent some new meaning for + )

2006/07Computing Science 1P Lecture 21 - Simon Gay10 Static typing The programmer might try 1 + “hello” (by mistake?) so what should the language do? Three possibilities. 1. Untyped languages (e.g. machine language) Ignore the problem. Just do the calculation of + on whatever bit-patterns are given. Meaningless answers.

2006/07Computing Science 1P Lecture 21 - Simon Gay11 Static typing The programmer might try 1 + “hello” (by mistake?) so what should the language do? 2. Dynamically typed languages (e.g. Python) At runtime, before doing a + operation, check that the types of the operands are suitable. If not, produce an error message. Some type errors might remain undetected for a long time.

2006/07Computing Science 1P Lecture 21 - Simon Gay12 Static typing The programmer might try 1 + “hello” (by mistake?) so what should the language do? 3. Statically typed languages (e.g. Java) At compile time, check the types of the operands of every + operation. If they are wrong, produce an error message and do not generate an executable program. Sometimes the compiler thinks there is an error but the programmer can see that it is OK.

2006/07Computing Science 1P Lecture 21 - Simon Gay13 Static typing in Java Java requires many type declarations. The type of every variable must be declared. The type of every function parameter must be declared. The result type of every function must be declared.

2006/07Computing Science 1P Lecture 21 - Simon Gay14 Example: sum of the integers from 1 to n Python: def sum(n): s = 0 while n > 0: s = s + n n = n - 1 return s Java: int sum(int n) { int s = 0; while (n > 0) { s = s + n; n = n - 1; } return s; }

2006/07Computing Science 1P Lecture 21 - Simon Gay15 Object-oriented programming Our programming with Python: we have data we have functions which operate on data Object-oriented programming: an object combines data and operations on it (which are called methods)

2006/07Computing Science 1P Lecture 21 - Simon Gay16 Objects and methods We have already seen that Python uses objects and methods. d = { “a”:10, “b”:20, “c”: 30 } d.keys() >>> [ “a”, “b”, “c” ]

2006/07Computing Science 1P Lecture 21 - Simon Gay17 Example of objects: shapes Imagine a program working with shapes: squares, circles, … Each shape could be represented by an object. Possible methods: area, perimeter It’s useful to be able to write s.area() even if we don’t know what kind of shape s is.

2006/07Computing Science 1P Lecture 21 - Simon Gay18 Classes Most object-oriented languages (including Java) use the idea of a class. Think of a class as a type for objects. class Square { float side; float area() { return side*side; } Square(float s) { side = s; } }

2006/07Computing Science 1P Lecture 21 - Simon Gay19 class Square { float side; float area() { return side*side; } Square(float s) { side = s; } } Square sq = new Square(5.0); print sq.area()

2006/07Computing Science 1P Lecture 21 - Simon Gay20 Inheritance A very important idea in object-oriented programming. It allows us to define a new kind of object, based on an old kind of object. Example: Shape is a generic shape Square is a particular kind of Shape Circle is another particular kind of Shape

2006/07Computing Science 1P Lecture 21 - Simon Gay21 Inheritance class Shape { float area() { return 0.0; } } class Square extends Shape { float side; float area() { return side*side; } Square(float s) { side = s; } } class Circle extends Shape { float radius; float area() { return pi*radius*radius; } Circle(float r) { radius = r; } }

2006/07Computing Science 1P Lecture 21 - Simon Gay22 Inheritance Shape s; if (...) s = new Square(5.0); else s = new Circle(4.0); print s.area();

2006/07Computing Science 1P Lecture 21 - Simon Gay23 Object-oriented programming … turns out to be a very powerful combination of ideas Classes and inheritance give a very natural way of modelling real-world entities. “ x is just like y except that…” First object-oriented language: Simula ( ) Also influential: Smalltalk (1980) Became standard from late 1980s onwards.

2006/07Computing Science 1P Lecture 21 - Simon Gay24 Object-oriented programming in Python … is possible, and we have already seen that lists and dictionaries are objects. Tkinter is very object-oriented. Because of Python’s dynamic type system, the role of classes is not quite the same as in Java. Java seems to be a better language for teaching object-oriented programming. (Python seems better for teaching the fundamental concepts of imperative programming.)