Week 7 - Friday.  What did we talk about last time?  Software engineering  Testing  Programming languages.

Slides:



Advertisements
Similar presentations
What is a Computer Program? For a computer to be able to do anything (multiply, play a song, run a word processor), it must be given the instructions.
Advertisements

Chapter 1: Introduction
Week 9: Methods 1.  We have written lots of code so far  It has all been inside of the main() method  What about a big program?  The main() method.
Programming Creating programs that run on your PC
Chapter Chapter Goals Describe the layers of a computer system Describe the concept of abstraction and its relationship to computing Describe.
1 Lecture 1  Getting ready to program  Hardware Model  Software Model  Programming Languages  The C Language  Software Engineering  Programming.
1 Chapter 1 The Big Picture. 2 2 Computing systems are dynamic entities used to solve problems and interact with their environment. They consist of devices,
SOFTWARE SYSTEMS SOFTWARE APPLICATIONS SOFTWARE PROGRAMMING LANGUAGES.
CSE 1301 J Lecture 2 Intro to Java Programming Richard Gesick.
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.
CS102 Introduction to Computer Programming
Chapter 01 Nell Dale & John Lewis.
Principles of Programming Chapter 1: Introduction  In this chapter you will learn about:  Overview of Computer Component  Overview of Programming 
History of Programming Languages
Programming Languages – Coding schemes used to write both systems and application software A programming language is an abstraction mechanism. It enables.
Introduction COMP104: Fundamentals and Methodology.
COMPUTER PROGRAMMING Source: Computing Concepts (the I-series) by Haag, Cummings, and Rhea, McGraw-Hill/Irwin, 2002.
1 Computing Software. Programming Style Programs that are not documented internally, while they may do what is requested, can be difficult to understand.
Introduction to Computers and Programming – Computer Programming.
Chapter 1 The Big Picture.
Chapter 1 CSIS-120: Java Intro. What is Programming?  A: It is what makes computer so useful.  The flexibility of a computer is amazing  Write a term.
Week 1 - Friday.  What did we talk about last time?  Our first Java program.
Visual C++ Programming: Concepts and Projects
1 ENERGY 211 / CME 211 Lecture 26 November 19, 2008.
Guide to Programming with Python Chapter One Getting Started: The Game Over Program.
INTRODUCTION TO COMPUTING CHAPTER NO. 04. Programming Languages Program Algorithms and Pseudo Code Properties and Advantages of Algorithms Flowchart (Symbols.
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.
Chapter 4 Software. Introduction Program: is a set of sequence instructions that tell the computer what to do. Software: is a collection of programs,
Chapter 11  Getting ready to program  Hardware Model  Software Model  Programming Languages  Facts about C++  Program Development Process  The Hello-world.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
PROBLEM SOLVING WARM-UP Fill in the spaces using any operation to solve the following (!, (), -/+,÷,×): = 6.
Week 7 - Wednesday.  What did we talk about last time?  Euler paths and cycles  Minimum spanning trees  Shortest paths.
Week 7 - Wednesday CS 113.
Evolution and History of Programming Languages
Topic 2: Hardware and Software
CSC 222: Object-Oriented Programming
Development Environment
Chapter 1 The Big Picture
CSCI-235 Micro-Computer Applications
Introduction to Python
Key Ideas from day 1 slides
Chapter 1 Introduction to Computers, Programs, and Java
A451 Theory – 7 Programming 7A, B - Algorithms.
Functions CIS 40 – Introduction to Programming in Python
Application Development Theory
Chapter 4 Computer Software.
Programming COMP104: Fundamentals and Methodology Introduction.
Chapter 2: Operating-System Structures
Developing Applications
TRANSLATORS AND IDEs Key Revision Points.
Computer Programming.
Software Programming J. Holvikivi 2014.
Learning to Program in Python
CS105 Introduction to Computer Concepts Intro to programming
The Programming Process
Introduction to Computer Programming
Von Neumann Architecture
Lecture 8 Programming Paradigm & Languages. Programming Languages The process of telling the computer what to do Also known as coding.
ICT Gaming Lesson 2.
Tonga Institute of Higher Education IT 141: Information Systems
Lecture 1 Runtime environments.
Tonga Institute of Higher Education IT 141: Information Systems
System calls….. C-program->POSIX call
Instructions.
Class code for pythonroom.com cchsp2cs
Functions, Procedures, and Abstraction
Programming Fundamentals Lecture #2 Overview of Computer Programming
Web Application Development Using PHP
Week 7 - Friday CS 113.
Week 1 - Friday COMP 1600.
Presentation transcript:

Week 7 - Friday

 What did we talk about last time?  Software engineering  Testing  Programming languages

 Object orientated programming (OOP) is a way of organizing code into objects containing  Data  Methods to manipulate the data  OOP is used  To protect data inside of objects from being changed in unexpected ways  To safely reuse code  It's hard to see why OOP is useful until you've programmed a big project  The shapes in Visual Python are examples of objects ball = sphere(color=color.red) ball.pos.x = 10 #data inside the ball ball = sphere(color=color.red) ball.pos.x = 10 #data inside the ball

 The very earliest programming languages used punch cards for player pianos and looms  A mechanical computer, the Analytical Engine, would have used punch cards, but it was never completed  Work was done on the Engine during the mid to late 19 th century  Ada Lovelace described an algorithm for it and is considered by some to be the first programmer

 Early electronic computers were built in the 1940s and 1950s  They were programmed directly in the machine language of 1s and 0s that they would understand  Machine language was succeeded by assembly language  Had human readable commands like load, store, and add  But the commands were specific to machines and very low level

 The third generation of languages is a set of general-purpose, high-level languages still used today  Pioneered in the 1960s and 1970s  Although they are written with a computer now, programs in these languages were written on punch cards before PCs existed  Examples: CC  FORTRAN  LISP

 Java and Python are actually newer additions to the third generation of general purpose languages  Fourth generation languages are for specific purposes  SQL for talking to databases  Unix shell for interacting with a Unix file system  Fifth generation languages are given constraints on a problem and use artificial intelligence to solve it  Prolog is the best known example

LanguageDescriptionTyping C/C++Fast and powerful systems language, prone to nasty bugs Static JavaPlatform independent OO language, uses virtual machine Static Objective-CApple language for writing Mac, iPhone, and iPad apps Static C#Microsoft language for applications and the web, like Java Static PythonInterpreted language with unusual syntax, easy to read Dynamic PerlScripting language, good at processing text Dynamic RubyInterpreted language, popular for making websites Dynamic PHPInterpreted, C-like language that runs on web servers Dynamic JavaScriptInterpreted language that runs on web browsers Dynamic Visual BasicMicrosoft language, good at making GUIs Static SQLLanguage for talking to databases Static

 We can classify languages on a spectrum from low to high  High level languages allow you to give more abstract commands that are more like human thought processes or mathematics  Low level languages are closer to the computer world and give explicit instructions for the hardware to follow MLJavaC++C Assembly Language Machine Code LowHigh

 We use a program called a compiler to turn a high level language into a low level language  Usually, the low level language is machine code  Python uses an interpreter instead of a compiler  An interpreter runs the program line by line instead of turning it into a machine code file that the OS can run

Computer! Solve a problem; Compile Execute Source Code Machine Code Hardware

 Functions allow you to package up some code to run over and over  Functions usually take some input (like numbers or text) so that they can be customized  Functions often give back an answer (like the square root of a number)  Also called methods in some other languages  The customizable purple blocks played the role of functions in Scratch

 More modular programming  Break a program into separate tasks  Each task could be assigned to a different programmer  Code reusability  Use code over and over  Even from other programs  Less code duplication  Improved readability  Each function can do a few, clear tasks

def name( arg1, …, argn ): statement1 statement2 … statementm Function name Name of last argument Name of 1 st argument Required syntax Code done by function (must be indented)

 Given two numbers, find the smaller: def smaller(a, b): if a < b: return a else: return b def smaller(a, b): if a < b: return a else: return b

 It is possible to divide functions into two types:  Functions that return values  Functions that don't return values  Functions that do return values give an answer:  It's as if the function is replaced by whatever answer is returned x = 3 y = 4 small = smaller(x, y) #small contains 3 x = 3 y = 4 small = smaller(x, y) #small contains 3

 A function doesn't have to return an answer:  This function only prints things to the screen  A function that doesn't return anything does some task but doesn't give back an answer def callForHelp(times): for i in range(times): print("Help!") def callForHelp(times): for i in range(times): print("Help!")

 Like most code in Python, the code inside of a function executes line by line  Of course, you are allowed to put if statements and loops inside methods  You can also put in return statements  A function will stop executing and jump back to wherever it was called from when it hits a return  The return statement is where you put the value that will be given back to the caller

 Defining a function is only half the game  You have to call functions to use them  Calling a function means giving it the parameters (or arguments) it needs and then waiting for its answer  By now, you have done many function calls  print()  You can call your own functions the same way

 You type the name of the function and then its arguments in parentheses  If it's a value returning function, you can store the answer it gives back  The arguments you give can be values or variables  You have to give the function the right number of arguments or the program will have an error callForHelp(3) #calls for help 3 times result = smaller(9, 2)

 Every function starts with def  Then comes the name of the function  Followed by the names of the arguments in parentheses  Followed by a colon ( : )  Like loops and if statements, the code inside a function is indented one level  Call the function in other code by typing the name and the correct number of arguments in parentheses

 Lets say we want to make a function that will draw three balls stacked on top of each other  The bottom one is green, the middle is orange, and the top is red  We want the function to take a radius and a position  The bottom ball will be drawn at the position with the radius given  The middle ball will be above it with half the radius  The top ball will be above that with one quarter the radius

 Here's the function stacks() which takes a radius and a position and draws the balls def stacks(radius, position): sphere(radius=radius, pos=position, color=color.green) newPosition=vector(position.x, position.y + 3*radius/2,position.z) sphere(radius=radius/2, pos=newPosition, color=color.orange) newPosition=vector(position.x, position.y + 9*radius/4, position.z) sphere(radius=radius/4, pos=newPosition, color=color.red) def stacks(radius, position): sphere(radius=radius, pos=position, color=color.green) newPosition=vector(position.x, position.y + 3*radius/2,position.z) sphere(radius=radius/2, pos=newPosition, color=color.orange) newPosition=vector(position.x, position.y + 9*radius/4, position.z) sphere(radius=radius/4, pos=newPosition, color=color.red)

 Now we can call the function several times  Each time, it will draw a stack with the size and location we specify  Result shown to the right stacks(1, vector(0,0,0)) stacks(.5, vector(2,3,1)) stacks(.2, vector(-2,1,2)) stacks(1, vector(0,0,0)) stacks(.5, vector(2,3,1)) stacks(.2, vector(-2,1,2))

 Moore's law  Multicore computers  Complex decisions

 Finish Project 2  Due tonight before midnight!  Reading Python Chapter 7  Think about what you want to do for your Final Project  Proposal due by 10/18