CS 115 Lecture 2 Fundamentals of computer science, computers, and - - PowerPoint PPT Presentation

cs 115 lecture 2
SMART_READER_LITE
LIVE PREVIEW

CS 115 Lecture 2 Fundamentals of computer science, computers, and - - PowerPoint PPT Presentation

CS 115 Lecture 2 Fundamentals of computer science, computers, and programming Neil Moore Department of Computer Science University of Kentucky Lexington, Kentucky 40506 neil@cs.uky.edu 1 September 2015 What is programming? CS 115 is titled


slide-1
SLIDE 1

CS 115 Lecture 2

Fundamentals of computer science, computers, and programming Neil Moore

Department of Computer Science University of Kentucky Lexington, Kentucky 40506 neil@cs.uky.edu

1 September 2015

slide-2
SLIDE 2

What is programming?

CS 115 is titled “Introduction to Computer Programming”. What is that?

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 2 / 27

slide-3
SLIDE 3

What is programming?

CS 115 is titled “Introduction to Computer Programming”. What is that? Telling a computer what to do?

◮ But every time I click on a button, or press a key,

I am telling the computer what to do.

◮ That’s not quite what we mean by programming. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 2 / 27

slide-4
SLIDE 4

What is programming?

CS 115 is titled “Introduction to Computer Programming”. What is that? Telling a computer what to do?

◮ But every time I click on a button, or press a key,

I am telling the computer what to do.

◮ That’s not quite what we mean by programming.

Writing computer programs.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 2 / 27

slide-5
SLIDE 5

What is programming?

CS 115 is titled “Introduction to Computer Programming”. What is that? Telling a computer what to do?

◮ But every time I click on a button, or press a key,

I am telling the computer what to do.

◮ That’s not quite what we mean by programming.

Writing computer programs.

◮ What’s that? ◮ What is a “program” outside of computing? Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 2 / 27

slide-6
SLIDE 6

What is programming?

CS 115 is titled “Introduction to Computer Programming”. What is that? Telling a computer what to do?

◮ But every time I click on a button, or press a key,

I am telling the computer what to do.

◮ That’s not quite what we mean by programming.

Writing computer programs.

◮ What’s that? ◮ What is a “program” outside of computing? ⋆ TV show. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 2 / 27

slide-7
SLIDE 7

What is programming?

CS 115 is titled “Introduction to Computer Programming”. What is that? Telling a computer what to do?

◮ But every time I click on a button, or press a key,

I am telling the computer what to do.

◮ That’s not quite what we mean by programming.

Writing computer programs.

◮ What’s that? ◮ What is a “program” outside of computing? ⋆ TV show. ⋆ Concert program Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 2 / 27

slide-8
SLIDE 8

What is programming?

CS 115 is titled “Introduction to Computer Programming”. What is that? Telling a computer what to do?

◮ But every time I click on a button, or press a key,

I am telling the computer what to do.

◮ That’s not quite what we mean by programming.

Writing computer programs.

◮ What’s that? ◮ What is a “program” outside of computing? ⋆ TV show. ⋆ Concert program: what is going to happen, in what order. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 2 / 27

slide-9
SLIDE 9

What is programming?

CS 115 is titled “Introduction to Computer Programming”. What is that? Telling a computer what to do?

◮ But every time I click on a button, or press a key,

I am telling the computer what to do.

◮ That’s not quite what we mean by programming.

Writing computer programs.

◮ What’s that? ◮ What is a “program” outside of computing? ⋆ TV show. ⋆ Concert program: what is going to happen, in what order. ◮ A sequence of instructions telling a computer how to do something. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 2 / 27

slide-10
SLIDE 10

What is programming?

CS 115 is titled “Introduction to Computer Programming”. What is that? Telling a computer what to do?

◮ But every time I click on a button, or press a key,

I am telling the computer what to do.

◮ That’s not quite what we mean by programming.

Writing computer programs.

◮ What’s that? ◮ What is a “program” outside of computing? ⋆ TV show. ⋆ Concert program: what is going to happen, in what order. ◮ A sequence of instructions telling a computer how to do something. ◮ Plan out in advance how to solve a kind of problem. ⋆ Then we have the computer execute the program Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 2 / 27

slide-11
SLIDE 11

What is programming?

CS 115 is titled “Introduction to Computer Programming”. What is that? Telling a computer what to do?

◮ But every time I click on a button, or press a key,

I am telling the computer what to do.

◮ That’s not quite what we mean by programming.

Writing computer programs.

◮ What’s that? ◮ What is a “program” outside of computing? ⋆ TV show. ⋆ Concert program: what is going to happen, in what order. ◮ A sequence of instructions telling a computer how to do something. ◮ Plan out in advance how to solve a kind of problem. ⋆ Then we have the computer execute the program Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 2 / 27

slide-12
SLIDE 12

What is computer science?

So what is computer science, and how does it differ from programming?

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 3 / 27

slide-13
SLIDE 13

What is computer science?

So what is computer science, and how does it differ from programming? “The study of computers”?

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 3 / 27

slide-14
SLIDE 14

What is computer science?

So what is computer science, and how does it differ from programming? “The study of computers”?

◮ “Computer science is no more about computers than astronomy is

about telescopes.” –attributed to Edsgar Dijkstra.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 3 / 27

slide-15
SLIDE 15

What is computer science?

So what is computer science, and how does it differ from programming? “The study of computers”?

◮ “Computer science is no more about computers than astronomy is

about telescopes.” –attributed to Edsgar Dijkstra.

Questions about computation came up long before computers.

◮ It used to be people following the step-by-step instructions. ⋆ Abacus, slide rule, pencil and paper, . . . ◮ What did we call those people? Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 3 / 27

slide-16
SLIDE 16

What is computer science?

So what is computer science, and how does it differ from programming? “The study of computers”?

◮ “Computer science is no more about computers than astronomy is

about telescopes.” –attributed to Edsgar Dijkstra.

Questions about computation came up long before computers.

◮ It used to be people following the step-by-step instructions. ⋆ Abacus, slide rule, pencil and paper, . . . ◮ What did we call those people? “Computers” Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 3 / 27

slide-17
SLIDE 17

What is computer science?

So what is computer science, and how does it differ from programming? “The study of computers”?

◮ “Computer science is no more about computers than astronomy is

about telescopes.” –attributed to Edsgar Dijkstra.

Questions about computation came up long before computers.

◮ It used to be people following the step-by-step instructions. ⋆ Abacus, slide rule, pencil and paper, . . . ◮ What did we call those people? “Computers” Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 3 / 27

An early computer network, around 1890.

E.C. Pickering’s astronomy lab at Harvard.

Image: Harvard University, Wikipedia article “Harvard Computers”

slide-18
SLIDE 18

What is computer science?

So what is computer science, and how does it differ from programming? “The study of computers”?

◮ “Computer science is no more about computers than astronomy is

about telescopes.” –attributed to Edsgar Dijkstra.

Questions about computation came up long before computers.

◮ It used to be people following the step-by-step instructions. ⋆ Abacus, slide rule, pencil and paper, . . . ◮ What did we call those people? “Computers” ◮ When you do long division or sort a list of names, you are computing. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 3 / 27

slide-19
SLIDE 19

What is computer science?

So what is computer science, and how does it differ from programming? “The study of computers”?

◮ “Computer science is no more about computers than astronomy is

about telescopes.” –attributed to Edsgar Dijkstra.

Questions about computation came up long before computers.

◮ It used to be people following the step-by-step instructions. ⋆ Abacus, slide rule, pencil and paper, . . . ◮ What did we call those people? “Computers” ◮ When you do long division or sort a list of names, you are computing.

Computer science is the study of:

◮ What can be computed using step-by-step procedures. ◮ How best to specify these procedures. ◮ How to tell if a procedure is correct, efficient, etc. ◮ How to design procedures to solve real-world problems. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 3 / 27

slide-20
SLIDE 20

Algorithms

“Step-by-step procedure” is a mouthful. We have a name for that: an algorithm.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 4 / 27

slide-21
SLIDE 21

Algorithms

“Step-by-step procedure” is a mouthful. We have a name for that: an algorithm. A “well-ordered collection of unambiguous and effectively computable

  • perations that when executed produces a result and halts in a finite

amount of time.” [Schneider and Gersting].

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 4 / 27

slide-22
SLIDE 22

Algorithms

“Step-by-step procedure” is a mouthful. We have a name for that: an algorithm. A “well-ordered collection of unambiguous and effectively computable

  • perations that when executed produces a result and halts in a finite

amount of time.” [Schneider and Gersting]. Named after the 9th-century Persian mathematician Muhammad ibn Musa al-Khwarizmi.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 4 / 27

slide-23
SLIDE 23

Algorithms

“Step-by-step procedure” is a mouthful. We have a name for that: an algorithm. A “well-ordered collection of unambiguous and effectively computable

  • perations that when executed produces a result and halts in a finite

amount of time.” [Schneider and Gersting]. Named after the 9th-century Persian mathematician Muhammad ibn Musa al-Khwarizmi.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 4 / 27

Muhammad Al-Khwarizmi, Persian computer scientist.

Sculpture: S. Ch. Babajan / Image: Michael Zaretski, Flickr.

slide-24
SLIDE 24

Algorithms

“Step-by-step procedure” is a mouthful. We have a name for that: an algorithm. A “well-ordered collection of unambiguous and effectively computable

  • perations that when executed produces a result and halts in a finite

amount of time.” [Schneider and Gersting]. Named after the 9th-century Persian mathematician Muhammad ibn Musa al-Khwarizmi.

◮ “The Compendious Book on Calculation by Restoring and Balancing” ◮ Described how to solve linear and quadratic equations. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 4 / 27

slide-25
SLIDE 25

Algorithms

“Step-by-step procedure” is a mouthful. We have a name for that: an algorithm. A “well-ordered collection of unambiguous and effectively computable

  • perations that when executed produces a result and halts in a finite

amount of time.” [Schneider and Gersting]. Named after the 9th-century Persian mathematician Muhammad ibn Musa al-Khwarizmi.

◮ “The Compendious Book on Calculation by Restoring and Balancing” ◮ Described how to solve linear and quadratic equations. ◮ Arabic: Al-kitab al-mukhtasar fi hisab al-jabr wa’l-muqabala Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 4 / 27

slide-26
SLIDE 26

Algorithms

“Step-by-step procedure” is a mouthful. We have a name for that: an algorithm. A “well-ordered collection of unambiguous and effectively computable

  • perations that when executed produces a result and halts in a finite

amount of time.” [Schneider and Gersting]. Named after the 9th-century Persian mathematician Muhammad ibn Musa al-Khwarizmi.

◮ “The Compendious Book on Calculation by Restoring and Balancing” ◮ Described how to solve linear and quadratic equations. ◮ Arabic: Al-kitab al-mukhtasar fi hisab al-jabr wa’l-muqabala ⋆ “Algebra” Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 4 / 27

slide-27
SLIDE 27

Algorithms

“Step-by-step procedure” is a mouthful. We have a name for that: an algorithm. A “well-ordered collection of unambiguous and effectively computable

  • perations that when executed produces a result and halts in a finite

amount of time.” [Schneider and Gersting]. Named after the 9th-century Persian mathematician Muhammad ibn Musa al-Khwarizmi.

◮ “The Compendious Book on Calculation by Restoring and Balancing” ◮ Described how to solve linear and quadratic equations. ◮ Arabic: Al-kitab al-mukhtasar fi hisab al-jabr wa’l-muqabala ⋆ “Algebra”

Let’s look at one algorithm that is even older than that:

◮ Euclid’s greatest common divisor algorithm. ◮ One of the oldest algorithms that is still in use. ⋆ In Euclid’s Elements, written around 300 BCE. ⋆ Older than long division! Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 4 / 27

slide-28
SLIDE 28

Algorithms

“Step-by-step procedure” is a mouthful. We have a name for that: an algorithm. A “well-ordered collection of unambiguous and effectively computable

  • perations that when executed produces a result and halts in a finite

amount of time.” [Schneider and Gersting]. Named after the 9th-century Persian mathematician Muhammad ibn Musa al-Khwarizmi.

◮ “The Compendious Book on Calculation by Restoring and Balancing” ◮ Described how to solve linear and quadratic equations. ◮ Arabic: Al-kitab al-mukhtasar fi hisab al-jabr wa’l-muqabala ⋆ “Algebra”

Let’s look at one algorithm that is even older than that:

◮ Euclid’s greatest common divisor algorithm. ◮ One of the oldest algorithms that is still in use. ⋆ In Euclid’s Elements, written around 300 BCE. ⋆ Older than long division! Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 4 / 27

slide-29
SLIDE 29

Euclid’s algorithm

Given two numbers a and b, their greatest common divisor (GCD) is the largest number that both are divisible by. The GCD of 10 and 25 is 5; of 13 and 3 is 1.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 5 / 27

slide-30
SLIDE 30

Euclid’s algorithm

Given two numbers a and b, their greatest common divisor (GCD) is the largest number that both are divisible by. The GCD of 10 and 25 is 5; of 13 and 3 is 1. Euclid designed an algorithm to compute the GCD: Inputs: two positive integers (whole numbers) a and b. Outputs: the GCD of a and b

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 5 / 27

slide-31
SLIDE 31

Euclid’s algorithm

Given two numbers a and b, their greatest common divisor (GCD) is the largest number that both are divisible by. The GCD of 10 and 25 is 5; of 13 and 3 is 1. Euclid designed an algorithm to compute the GCD: Inputs: two positive integers (whole numbers) a and b. Outputs: the GCD of a and b

1 Repeat as long as b is not zero: 1.1 If a > b, then set a ← (a − b). 1.2 Otherwise, set b ← (b − a). Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 5 / 27

slide-32
SLIDE 32

Euclid’s algorithm

Given two numbers a and b, their greatest common divisor (GCD) is the largest number that both are divisible by. The GCD of 10 and 25 is 5; of 13 and 3 is 1. Euclid designed an algorithm to compute the GCD: Inputs: two positive integers (whole numbers) a and b. Outputs: the GCD of a and b

1 Repeat as long as b is not zero: 1.1 If a > b, then set a ← (a − b). 1.2 Otherwise, set b ← (b − a). 2 Output a as the answer. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 5 / 27

slide-33
SLIDE 33

Euclid’s algorithm

Given two numbers a and b, their greatest common divisor (GCD) is the largest number that both are divisible by. The GCD of 10 and 25 is 5; of 13 and 3 is 1. Euclid designed an algorithm to compute the GCD: Inputs: two positive integers (whole numbers) a and b. Outputs: the GCD of a and b

1 Repeat as long as b is not zero: 1.1 If a > b, then set a ← (a − b). 1.2 Otherwise, set b ← (b − a). 2 Output a as the answer.

Euclid proved that this algorithm is correct (it gives the right answer) and effective (it always gives an answer).

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 5 / 27

slide-34
SLIDE 34

Euclid’s algorithm

Given two numbers a and b, their greatest common divisor (GCD) is the largest number that both are divisible by. The GCD of 10 and 25 is 5; of 13 and 3 is 1. Euclid designed an algorithm to compute the GCD: Inputs: two positive integers (whole numbers) a and b. Outputs: the GCD of a and b

1 Repeat as long as b is not zero: 1.1 If a > b, then set a ← (a − b). 1.2 Otherwise, set b ← (b − a). 2 Output a as the answer.

Euclid proved that this algorithm is correct (it gives the right answer) and effective (it always gives an answer).

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 5 / 27

Euclid, Greek computer scientist.

Sculpture: J. Durham / Image: Mark A. Wilson, Wikipedia, 2005.

slide-35
SLIDE 35

Euclid’s algorithm

Given two numbers a and b, their greatest common divisor (GCD) is the largest number that both are divisible by. The GCD of 10 and 25 is 5; of 13 and 3 is 1. Euclid designed an algorithm to compute the GCD: Inputs: two positive integers (whole numbers) a and b. Outputs: the GCD of a and b

1 Repeat as long as b is not zero: 1.1 If a > b, then set a ← (a − b). 1.2 Otherwise, set b ← (b − a). 2 Output a as the answer.

Euclid proved that this algorithm is correct (it gives the right answer) and effective (it always gives an answer). Let’s try a few examples.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 5 / 27

slide-36
SLIDE 36

Euclid’s algorithm

Given two numbers a and b, their greatest common divisor (GCD) is the largest number that both are divisible by. The GCD of 10 and 25 is 5; of 13 and 3 is 1. Euclid designed an algorithm to compute the GCD: Inputs: two positive integers (whole numbers) a and b. Outputs: the GCD of a and b

1 Repeat as long as b is not zero: 1.1 If a > b, then set a ← (a − b). 1.2 Otherwise, set b ← (b − a). 2 Output a as the answer.

Euclid proved that this algorithm is correct (it gives the right answer) and effective (it always gives an answer). Let’s try a few examples.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 5 / 27

slide-37
SLIDE 37

Designing an algorithm

In this class we will use the words “design”, “pseudocode”, and “algorithm” interchangeably.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 6 / 27

slide-38
SLIDE 38

Designing an algorithm

In this class we will use the words “design”, “pseudocode”, and “algorithm” interchangeably. These are the steps to solve a problem. A design is like an outline or rough draft for your program. Figure out what you’re going to do before you start doing it! We’ll start with a non-computer example.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 6 / 27

slide-39
SLIDE 39

Designing an algorithm

In this class we will use the words “design”, “pseudocode”, and “algorithm” interchangeably. These are the steps to solve a problem. A design is like an outline or rough draft for your program. Figure out what you’re going to do before you start doing it! We’ll start with a non-computer example.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 6 / 27

slide-40
SLIDE 40

Design: building a dog house

Let’s say we want to build a dog house.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 7 / 27

slide-41
SLIDE 41

Design: building a dog house

Let’s say we want to build a dog house. What steps do we need to take?

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 7 / 27

slide-42
SLIDE 42

Design: building a dog house

Let’s say we want to build a dog house. What steps do we need to take?

1 Decide on a location and size for the doghouse. 2 Get materials for the house. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 7 / 27

slide-43
SLIDE 43

Design: building a dog house

Let’s say we want to build a dog house. What steps do we need to take?

1 Decide on a location and size for the doghouse. 2 Get materials for the house. 3 Cut a piece of wood for the floor. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 7 / 27

slide-44
SLIDE 44

Design: building a dog house

Let’s say we want to build a dog house. What steps do we need to take?

1 Decide on a location and size for the doghouse. 2 Get materials for the house. 3 Cut a piece of wood for the floor. 4 Cut wood for the four walls. 5 Cut a door into one wall. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 7 / 27

slide-45
SLIDE 45

Design: building a dog house

Let’s say we want to build a dog house. What steps do we need to take?

1 Decide on a location and size for the doghouse. 2 Get materials for the house. 3 Cut a piece of wood for the floor. 4 Cut wood for the four walls. 5 Cut a door into one wall. 6 Assemble walls. 7 Attach walls to the floor. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 7 / 27

slide-46
SLIDE 46

Design: building a dog house

Let’s say we want to build a dog house. What steps do we need to take?

1 Decide on a location and size for the doghouse. 2 Get materials for the house. 3 Cut a piece of wood for the floor. 4 Cut wood for the four walls. 5 Cut a door into one wall. 6 Assemble walls. 7 Attach walls to the floor. 8 Make roof. 9 Attach roof to walls. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 7 / 27

slide-47
SLIDE 47

Design: building a dog house

Let’s say we want to build a dog house. What steps do we need to take?

1 Decide on a location and size for the doghouse. 2 Get materials for the house. 3 Cut a piece of wood for the floor. 4 Cut wood for the four walls. 5 Cut a door into one wall. 6 Assemble walls. 7 Attach walls to the floor. 8 Make roof. 9 Attach roof to walls. 10 Paint the outside. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 7 / 27

slide-48
SLIDE 48

Design: building a dog house

Let’s say we want to build a dog house. What steps do we need to take?

1 Decide on a location and size for the doghouse. 2 Get materials for the house. 3 Cut a piece of wood for the floor. 4 Cut wood for the four walls. 5 Cut a door into one wall. 6 Assemble walls. 7 Attach walls to the floor. 8 Make roof. 9 Attach roof to walls. 10 Paint the outside. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 7 / 27

slide-49
SLIDE 49

Notes on the design

Steps are numbered in the order they should be performed.

◮ If I try cutting the door after attaching the walls to the floor,

it will be harder.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 8 / 27

slide-50
SLIDE 50

Notes on the design

Steps are numbered in the order they should be performed.

◮ If I try cutting the door after attaching the walls to the floor,

it will be harder.

◮ You’ll number your steps for the first few designs in class. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 8 / 27

slide-51
SLIDE 51

Notes on the design

Steps are numbered in the order they should be performed.

◮ If I try cutting the door after attaching the walls to the floor,

it will be harder.

◮ You’ll number your steps for the first few designs in class.

Some steps could be further divided:

◮ “Get materials”: what materials? Where? Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 8 / 27

slide-52
SLIDE 52

Notes on the design

Steps are numbered in the order they should be performed.

◮ If I try cutting the door after attaching the walls to the floor,

it will be harder.

◮ You’ll number your steps for the first few designs in class.

Some steps could be further divided:

◮ “Get materials”: what materials? Where? ◮ “Make roof”: cut at an angle, nail together, . . . Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 8 / 27

slide-53
SLIDE 53

Notes on the design

Steps are numbered in the order they should be performed.

◮ If I try cutting the door after attaching the walls to the floor,

it will be harder.

◮ You’ll number your steps for the first few designs in class.

Some steps could be further divided:

◮ “Get materials”: what materials? Where? ◮ “Make roof”: cut at an angle, nail together, . . .

“Cut wood for the four walls”: a repeated step.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 8 / 27

slide-54
SLIDE 54

Notes on the design

Steps are numbered in the order they should be performed.

◮ If I try cutting the door after attaching the walls to the floor,

it will be harder.

◮ You’ll number your steps for the first few designs in class.

Some steps could be further divided:

◮ “Get materials”: what materials? Where? ◮ “Make roof”: cut at an angle, nail together, . . .

“Cut wood for the four walls”: a repeated step. Could go into more detail: how big is a wall, the floor, etc.?

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 8 / 27

slide-55
SLIDE 55

Notes on the design

Steps are numbered in the order they should be performed.

◮ If I try cutting the door after attaching the walls to the floor,

it will be harder.

◮ You’ll number your steps for the first few designs in class.

Some steps could be further divided:

◮ “Get materials”: what materials? Where? ◮ “Make roof”: cut at an angle, nail together, . . .

“Cut wood for the four walls”: a repeated step. Could go into more detail: how big is a wall, the floor, etc.? What’s the budget?

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 8 / 27

slide-56
SLIDE 56

Dog house, refined

1 Decide on a location and size for the doghouse. 2 Get materials for the house. 1

Get lumber.

2

Get paint.

3

Get nails.

3 Cut a piece of wood for the floor. 4 Repeat four times: 1

Cut a piece of wood for a wall.

5 Cut a door into one wall. 6 Attach walls to the floor. 7 Make roof. 1

Cut two pieces of wood.

2

Join the pieces at a 90 degree angle.

3

Nail the pieces together.

8 Attach roof to walls. 9 Paint the outside. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 9 / 27

slide-57
SLIDE 57

Dog house, refined

1 Decide on a location and size for the doghouse. 2 Get materials for the house. 1

Get lumber.

2

Get paint.

3

Get nails.

3 Cut a piece of wood for the floor. 4 Repeat four times: 1

Cut a piece of wood for a wall.

5 Cut a door into one wall. 6 Attach walls to the floor. 7 Make roof. 1

Cut two pieces of wood.

2

Join the pieces at a 90 degree angle.

3

Nail the pieces together.

8 Attach roof to walls. 9 Paint the outside. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 9 / 27

slide-58
SLIDE 58

The first computers

The first automatic computers were designed to solve one specific problem.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 10 / 27

slide-59
SLIDE 59

The first computers

The first automatic computers were designed to solve one specific problem. The Antikythera mechanism was built around 100 BCE for calendar and astronomical calculations.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 10 / 27

slide-60
SLIDE 60

The first computers

The first automatic computers were designed to solve one specific problem. The Antikythera mechanism was built around 100 BCE for calendar and astronomical calculations.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 10 / 27

The Antikythera mechanism

Image: user “Marsyas”, Wikimedia Commons, 20 December 2005.

slide-61
SLIDE 61

The first computers

The first automatic computers were designed to solve one specific problem. The Antikythera mechanism was built around 100 BCE for calendar and astronomical calculations. Charles Babbage designed the difference engine, 1823–1842, to compute values of polynomials.

◮ Never finished in his lifetime. ◮ Finally built in 1991. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 10 / 27

slide-62
SLIDE 62

The first computers

The first automatic computers were designed to solve one specific problem. The Antikythera mechanism was built around 100 BCE for calendar and astronomical calculations. Charles Babbage designed the difference engine, 1823–1842, to compute values of polynomials.

◮ Never finished in his lifetime. ◮ Finally built in 1991. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 10 / 27

Babbage’s difference engine, built 1991

Image: Allan J. Cronin, Wikipedia, March 2009.

slide-63
SLIDE 63

The first computers

The first automatic computers were designed to solve one specific problem. The Antikythera mechanism was built around 100 BCE for calendar and astronomical calculations. Charles Babbage designed the difference engine, 1823–1842, to compute values of polynomials.

◮ Never finished in his lifetime. ◮ Finally built in 1991. ◮ And it worked! Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 10 / 27

slide-64
SLIDE 64

The first computers

The first automatic computers were designed to solve one specific problem. The Antikythera mechanism was built around 100 BCE for calendar and astronomical calculations. Charles Babbage designed the difference engine, 1823–1842, to compute values of polynomials.

◮ Never finished in his lifetime. ◮ Finally built in 1991. ◮ And it worked! Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 10 / 27

slide-65
SLIDE 65

Programming early computers

Early computers were designed to solve one specific problem. Some could be reprogrammed by flipping switches or plugging in cables.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 11 / 27

slide-66
SLIDE 66

Programming early computers

Early computers were designed to solve one specific problem. Some could be reprogrammed by flipping switches or plugging in cables.

◮ Flip switches to enter a number into the “store”. ◮ Connect cables from the store to the adder, multiplier, etc. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 11 / 27

slide-67
SLIDE 67

Programming early computers

Early computers were designed to solve one specific problem. Some could be reprogrammed by flipping switches or plugging in cables.

◮ Flip switches to enter a number into the “store”. ◮ Connect cables from the store to the adder, multiplier, etc. ◮ Setting up the machine to solve a problem could take days. ⋆ Even if you already know which cables should go where. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 11 / 27

slide-68
SLIDE 68

Programming early computers

Early computers were designed to solve one specific problem. Some could be reprogrammed by flipping switches or plugging in cables.

◮ Flip switches to enter a number into the “store”. ◮ Connect cables from the store to the adder, multiplier, etc. ◮ Setting up the machine to solve a problem could take days. ⋆ Even if you already know which cables should go where.

But still, that was faster and more accurate than humans.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 11 / 27

slide-69
SLIDE 69

Programming early computers

Early computers were designed to solve one specific problem. Some could be reprogrammed by flipping switches or plugging in cables.

◮ Flip switches to enter a number into the “store”. ◮ Connect cables from the store to the adder, multiplier, etc. ◮ Setting up the machine to solve a problem could take days. ⋆ Even if you already know which cables should go where.

But still, that was faster and more accurate than humans.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 11 / 27

slide-70
SLIDE 70

Stored programs

British mathematician Alan Turing described in 1936 a mathematical model of how machines can compute.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 12 / 27

slide-71
SLIDE 71

Stored programs

British mathematician Alan Turing described in 1936 a mathematical model of how machines can compute.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 12 / 27

Alan Turing, British computer scientist.

Image: National Portrait Gallery, London, 1951.

slide-72
SLIDE 72

Stored programs

British mathematician Alan Turing described in 1936 a mathematical model of how machines can compute.

◮ A founder of modern computer science. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 12 / 27

slide-73
SLIDE 73

Stored programs

British mathematician Alan Turing described in 1936 a mathematical model of how machines can compute.

◮ A founder of modern computer science.

He realized that you could make a universal machine

◮ It would take as part of its input a description of the program to run. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 12 / 27

slide-74
SLIDE 74

Stored programs

British mathematician Alan Turing described in 1936 a mathematical model of how machines can compute.

◮ A founder of modern computer science.

He realized that you could make a universal machine

◮ It would take as part of its input a description of the program to run. ◮ Programs become just another kind of data! ◮ John von Neumann developed these ideas further in 1944. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 12 / 27

slide-75
SLIDE 75

Stored programs

British mathematician Alan Turing described in 1936 a mathematical model of how machines can compute.

◮ A founder of modern computer science.

He realized that you could make a universal machine

◮ It would take as part of its input a description of the program to run. ◮ Programs become just another kind of data! ◮ John von Neumann developed these ideas further in 1944. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 12 / 27

John von Neumann, Hungarian-American computer scientist.

Image: Los Alamos National Lab.

slide-76
SLIDE 76

Stored programs

British mathematician Alan Turing described in 1936 a mathematical model of how machines can compute.

◮ A founder of modern computer science.

He realized that you could make a universal machine

◮ It would take as part of its input a description of the program to run. ◮ Programs become just another kind of data! ◮ John von Neumann developed these ideas further in 1944.

Turing later went on to develop the bombe to break WWII encryption.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 12 / 27

slide-77
SLIDE 77

Stored programs

British mathematician Alan Turing described in 1936 a mathematical model of how machines can compute.

◮ A founder of modern computer science.

He realized that you could make a universal machine

◮ It would take as part of its input a description of the program to run. ◮ Programs become just another kind of data! ◮ John von Neumann developed these ideas further in 1944.

Turing later went on to develop the bombe to break WWII encryption.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 12 / 27

Somebody set up us the bombe (reproduction).

Image: Antoine Taveneaux, Wikipedia, 18 June 2012.

slide-78
SLIDE 78

Stored programs

British mathematician Alan Turing described in 1936 a mathematical model of how machines can compute.

◮ A founder of modern computer science.

He realized that you could make a universal machine

◮ It would take as part of its input a description of the program to run. ◮ Programs become just another kind of data! ◮ John von Neumann developed these ideas further in 1944.

Turing later went on to develop the bombe to break WWII encryption.

◮ Germany used the Enigma machine to encrypt wartime messages. ◮ The bombe figured out which settings the Enigma used each day. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 12 / 27

slide-79
SLIDE 79

Stored programs

British mathematician Alan Turing described in 1936 a mathematical model of how machines can compute.

◮ A founder of modern computer science.

He realized that you could make a universal machine

◮ It would take as part of its input a description of the program to run. ◮ Programs become just another kind of data! ◮ John von Neumann developed these ideas further in 1944.

Turing later went on to develop the bombe to break WWII encryption.

◮ Germany used the Enigma machine to encrypt wartime messages. ◮ The bombe figured out which settings the Enigma used each day. ◮ 2014 film: The Imitation Game ◮ “The Imitation Game” was his name for what we now call the “Turing

test”: how can we tell whether a computer is intelligent?

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 12 / 27

slide-80
SLIDE 80

Stored programs

British mathematician Alan Turing described in 1936 a mathematical model of how machines can compute.

◮ A founder of modern computer science.

He realized that you could make a universal machine

◮ It would take as part of its input a description of the program to run. ◮ Programs become just another kind of data! ◮ John von Neumann developed these ideas further in 1944.

Turing later went on to develop the bombe to break WWII encryption.

◮ Germany used the Enigma machine to encrypt wartime messages. ◮ The bombe figured out which settings the Enigma used each day. ◮ 2014 film: The Imitation Game ◮ “The Imitation Game” was his name for what we now call the “Turing

test”: how can we tell whether a computer is intelligent?

A sad end.

◮ In 1952, it came out that Turing was gay: illegal at the time. ◮ He was convicted and sentenced to chemical castration (hormones). ◮ Committed suicide in 1954. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 12 / 27

slide-81
SLIDE 81

Stored programs

British mathematician Alan Turing described in 1936 a mathematical model of how machines can compute.

◮ A founder of modern computer science.

He realized that you could make a universal machine

◮ It would take as part of its input a description of the program to run. ◮ Programs become just another kind of data! ◮ John von Neumann developed these ideas further in 1944.

Turing later went on to develop the bombe to break WWII encryption.

◮ Germany used the Enigma machine to encrypt wartime messages. ◮ The bombe figured out which settings the Enigma used each day. ◮ 2014 film: The Imitation Game ◮ “The Imitation Game” was his name for what we now call the “Turing

test”: how can we tell whether a computer is intelligent?

A sad end.

◮ In 1952, it came out that Turing was gay: illegal at the time. ◮ He was convicted and sentenced to chemical castration (hormones). ◮ Committed suicide in 1954. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 12 / 27

slide-82
SLIDE 82

Parts of a modern computer

RAM: the computer’s “working memory”.

◮ “Random Access Memory” Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 13 / 27

slide-83
SLIDE 83

Parts of a modern computer

RAM: the computer’s “working memory”.

◮ “Random Access Memory” ◮ Made up of cells (words), each holding a number. ⋆ Represented in binary. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 13 / 27

slide-84
SLIDE 84

Parts of a modern computer

RAM: the computer’s “working memory”.

◮ “Random Access Memory” ◮ Made up of cells (words), each holding a number. ⋆ Represented in binary. ◮ Volatile: information is lost when the power goes out. ◮ Fast (nanoseconds) ◮ Relatively expensive. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 13 / 27

slide-85
SLIDE 85

Parts of a modern computer

RAM: the computer’s “working memory”.

◮ “Random Access Memory” ◮ Made up of cells (words), each holding a number. ⋆ Represented in binary. ◮ Volatile: information is lost when the power goes out. ◮ Fast (nanoseconds) ◮ Relatively expensive. ◮ Von Neumann architecture: CPU reads instructions from RAM. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 13 / 27

slide-86
SLIDE 86

Parts of a modern computer

RAM: the computer’s “working memory”.

◮ “Random Access Memory” ◮ Made up of cells (words), each holding a number. ⋆ Represented in binary. ◮ Volatile: information is lost when the power goes out. ◮ Fast (nanoseconds) ◮ Relatively expensive. ◮ Von Neumann architecture: CPU reads instructions from RAM.

Secondary storage: hard drives, flash, DVD, . . .

◮ Persistent: data can be stored for years or decades. ◮ Slow (microseconds to milliseconds: < 1/1000 the speed of RAM) ◮ Relatively cheap. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 13 / 27

slide-87
SLIDE 87

Parts of a modern computer

RAM: the computer’s “working memory”.

◮ “Random Access Memory” ◮ Made up of cells (words), each holding a number. ⋆ Represented in binary. ◮ Volatile: information is lost when the power goes out. ◮ Fast (nanoseconds) ◮ Relatively expensive. ◮ Von Neumann architecture: CPU reads instructions from RAM.

Secondary storage: hard drives, flash, DVD, . . .

◮ Persistent: data can be stored for years or decades. ◮ Slow (microseconds to milliseconds: < 1/1000 the speed of RAM) ◮ Relatively cheap. ◮ Data must be transferred to RAM before the CPU can use it. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 13 / 27

slide-88
SLIDE 88

Parts of a modern computer

RAM: the computer’s “working memory”.

◮ “Random Access Memory” ◮ Made up of cells (words), each holding a number. ⋆ Represented in binary. ◮ Volatile: information is lost when the power goes out. ◮ Fast (nanoseconds) ◮ Relatively expensive. ◮ Von Neumann architecture: CPU reads instructions from RAM.

Secondary storage: hard drives, flash, DVD, . . .

◮ Persistent: data can be stored for years or decades. ◮ Slow (microseconds to milliseconds: < 1/1000 the speed of RAM) ◮ Relatively cheap. ◮ Data must be transferred to RAM before the CPU can use it.

CPU: Central Processing Unit.

◮ Reads instructions from RAM. ◮ Executes (carries them out) in order. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 13 / 27

slide-89
SLIDE 89

Parts of a modern computer

RAM: the computer’s “working memory”.

◮ “Random Access Memory” ◮ Made up of cells (words), each holding a number. ⋆ Represented in binary. ◮ Volatile: information is lost when the power goes out. ◮ Fast (nanoseconds) ◮ Relatively expensive. ◮ Von Neumann architecture: CPU reads instructions from RAM.

Secondary storage: hard drives, flash, DVD, . . .

◮ Persistent: data can be stored for years or decades. ◮ Slow (microseconds to milliseconds: < 1/1000 the speed of RAM) ◮ Relatively cheap. ◮ Data must be transferred to RAM before the CPU can use it.

CPU: Central Processing Unit.

◮ Reads instructions from RAM. ◮ Executes (carries them out) in order. ◮ Simple instructions: add numbers, is-equal, skip to another instruction. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 13 / 27

slide-90
SLIDE 90

Parts of a modern computer

RAM: the computer’s “working memory”.

◮ “Random Access Memory” ◮ Made up of cells (words), each holding a number. ⋆ Represented in binary. ◮ Volatile: information is lost when the power goes out. ◮ Fast (nanoseconds) ◮ Relatively expensive. ◮ Von Neumann architecture: CPU reads instructions from RAM.

Secondary storage: hard drives, flash, DVD, . . .

◮ Persistent: data can be stored for years or decades. ◮ Slow (microseconds to milliseconds: < 1/1000 the speed of RAM) ◮ Relatively cheap. ◮ Data must be transferred to RAM before the CPU can use it.

CPU: Central Processing Unit.

◮ Reads instructions from RAM. ◮ Executes (carries them out) in order. ◮ Simple instructions: add numbers, is-equal, skip to another instruction. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 13 / 27

slide-91
SLIDE 91

Computer units

RAM consists of bits: a circuit that stores a 1 or a 0. Bits are combined into bytes, usually 8 bits.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 14 / 27

slide-92
SLIDE 92

Computer units

RAM consists of bits: a circuit that stores a 1 or a 0. Bits are combined into bytes, usually 8 bits.

◮ Binary numbers: places are powers of two ⋆ 1, 2, 4, 8, 16, 32, 64, 128 Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 14 / 27

slide-93
SLIDE 93

Computer units

RAM consists of bits: a circuit that stores a 1 or a 0. Bits are combined into bytes, usually 8 bits.

◮ Binary numbers: places are powers of two ⋆ 1, 2, 4, 8, 16, 32, 64, 128 ◮ So 01001011 Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 14 / 27

slide-94
SLIDE 94

Computer units

RAM consists of bits: a circuit that stores a 1 or a 0. Bits are combined into bytes, usually 8 bits.

◮ Binary numbers: places are powers of two ⋆ 1, 2, 4, 8, 16, 32, 64, 128 ◮ So 01001011 = 1 Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 14 / 27

slide-95
SLIDE 95

Computer units

RAM consists of bits: a circuit that stores a 1 or a 0. Bits are combined into bytes, usually 8 bits.

◮ Binary numbers: places are powers of two ⋆ 1, 2, 4, 8, 16, 32, 64, 128 ◮ So 01001011 = 1 + 2 Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 14 / 27

slide-96
SLIDE 96

Computer units

RAM consists of bits: a circuit that stores a 1 or a 0. Bits are combined into bytes, usually 8 bits.

◮ Binary numbers: places are powers of two ⋆ 1, 2, 4, 8, 16, 32, 64, 128 ◮ So 01001011 = 1 + 2 + 8 Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 14 / 27

slide-97
SLIDE 97

Computer units

RAM consists of bits: a circuit that stores a 1 or a 0. Bits are combined into bytes, usually 8 bits.

◮ Binary numbers: places are powers of two ⋆ 1, 2, 4, 8, 16, 32, 64, 128 ◮ So 01001011 = 1 + 2 + 8 + 64 Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 14 / 27

slide-98
SLIDE 98

Computer units

RAM consists of bits: a circuit that stores a 1 or a 0. Bits are combined into bytes, usually 8 bits.

◮ Binary numbers: places are powers of two ⋆ 1, 2, 4, 8, 16, 32, 64, 128 ◮ So 01001011 = 1 + 2 + 8 + 64 = 75 Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 14 / 27

slide-99
SLIDE 99

Computer units

RAM consists of bits: a circuit that stores a 1 or a 0. Bits are combined into bytes, usually 8 bits.

◮ Binary numbers: places are powers of two ⋆ 1, 2, 4, 8, 16, 32, 64, 128 ◮ So 01001011 = 1 + 2 + 8 + 64 = 75 ◮ (More about this in chapter 3). Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 14 / 27

slide-100
SLIDE 100

Computer units

RAM consists of bits: a circuit that stores a 1 or a 0. Bits are combined into bytes, usually 8 bits.

◮ Binary numbers: places are powers of two ⋆ 1, 2, 4, 8, 16, 32, 64, 128 ◮ So 01001011 = 1 + 2 + 8 + 64 = 75 ◮ (More about this in chapter 3). ◮ One byte can represent a number from 0 to 255. ⋆ Or a single character in ASCII code. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 14 / 27

slide-101
SLIDE 101

Computer units

RAM consists of bits: a circuit that stores a 1 or a 0. Bits are combined into bytes, usually 8 bits.

◮ Binary numbers: places are powers of two ⋆ 1, 2, 4, 8, 16, 32, 64, 128 ◮ So 01001011 = 1 + 2 + 8 + 64 = 75 ◮ (More about this in chapter 3). ◮ One byte can represent a number from 0 to 255. ⋆ Or a single character in ASCII code.

Kilobyte (kB): 210 = 1024 bytes (about a page of text)

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 14 / 27

slide-102
SLIDE 102

Computer units

RAM consists of bits: a circuit that stores a 1 or a 0. Bits are combined into bytes, usually 8 bits.

◮ Binary numbers: places are powers of two ⋆ 1, 2, 4, 8, 16, 32, 64, 128 ◮ So 01001011 = 1 + 2 + 8 + 64 = 75 ◮ (More about this in chapter 3). ◮ One byte can represent a number from 0 to 255. ⋆ Or a single character in ASCII code.

Kilobyte (kB): 210 = 1024 bytes (about a page of text) Megabyte (MB): 220 ≈ 1 million bytes (1024 kB, a large book)

◮ A song in MP3 format might take 3 or 4 MB. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 14 / 27

slide-103
SLIDE 103

Computer units

RAM consists of bits: a circuit that stores a 1 or a 0. Bits are combined into bytes, usually 8 bits.

◮ Binary numbers: places are powers of two ⋆ 1, 2, 4, 8, 16, 32, 64, 128 ◮ So 01001011 = 1 + 2 + 8 + 64 = 75 ◮ (More about this in chapter 3). ◮ One byte can represent a number from 0 to 255. ⋆ Or a single character in ASCII code.

Kilobyte (kB): 210 = 1024 bytes (about a page of text) Megabyte (MB): 220 ≈ 1 million bytes (1024 kB, a large book)

◮ A song in MP3 format might take 3 or 4 MB.

Gigabyte (GB): 230 ≈ 1 billion bytes (1024 MB, a small library)

◮ A DVD is about 4.7 GB. ◮ A modern computer might have 16 GB of RAM. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 14 / 27

slide-104
SLIDE 104

Computer units

RAM consists of bits: a circuit that stores a 1 or a 0. Bits are combined into bytes, usually 8 bits.

◮ Binary numbers: places are powers of two ⋆ 1, 2, 4, 8, 16, 32, 64, 128 ◮ So 01001011 = 1 + 2 + 8 + 64 = 75 ◮ (More about this in chapter 3). ◮ One byte can represent a number from 0 to 255. ⋆ Or a single character in ASCII code.

Kilobyte (kB): 210 = 1024 bytes (about a page of text) Megabyte (MB): 220 ≈ 1 million bytes (1024 kB, a large book)

◮ A song in MP3 format might take 3 or 4 MB.

Gigabyte (GB): 230 ≈ 1 billion bytes (1024 MB, a small library)

◮ A DVD is about 4.7 GB. ◮ A modern computer might have 16 GB of RAM.

Terabyte (TB): 240 ≈ 1 trillion bytes (1024 GB, a large library)

◮ A modern hard drive might be 1 or 2 TB. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 14 / 27

slide-105
SLIDE 105

Calculating with computer units

Let’s say you have a 16 GB USB stick.

◮ And a bunch of videos, 256 MB each. ◮ How many videos can it hold? Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 15 / 27

slide-106
SLIDE 106

Calculating with computer units

Let’s say you have a 16 GB USB stick.

◮ And a bunch of videos, 256 MB each. ◮ How many videos can it hold? ◮ 1024 = 256 × 4 Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 15 / 27

slide-107
SLIDE 107

Calculating with computer units

Let’s say you have a 16 GB USB stick.

◮ And a bunch of videos, 256 MB each. ◮ How many videos can it hold? ◮ 1024 = 256 × 4, so you can fit four videos in one GB. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 15 / 27

slide-108
SLIDE 108

Calculating with computer units

Let’s say you have a 16 GB USB stick.

◮ And a bunch of videos, 256 MB each. ◮ How many videos can it hold? ◮ 1024 = 256 × 4, so you can fit four videos in one GB. ◮ 4 × 16 = 64: 64 videos on the USB stick. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 15 / 27

slide-109
SLIDE 109

Calculating with computer units

Let’s say you have a 16 GB USB stick.

◮ And a bunch of videos, 256 MB each. ◮ How many videos can it hold? ◮ 1024 = 256 × 4, so you can fit four videos in one GB. ◮ 4 × 16 = 64: 64 videos on the USB stick.

Beware!

◮ Hard drive manufacturers use a different definition of kB, MB, etc! ◮ They say that 1 kB is exactly 1000 bytes (not 1024). Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 15 / 27

slide-110
SLIDE 110

Calculating with computer units

Let’s say you have a 16 GB USB stick.

◮ And a bunch of videos, 256 MB each. ◮ How many videos can it hold? ◮ 1024 = 256 × 4, so you can fit four videos in one GB. ◮ 4 × 16 = 64: 64 videos on the USB stick.

Beware!

◮ Hard drive manufacturers use a different definition of kB, MB, etc! ◮ They say that 1 kB is exactly 1000 bytes (not 1024). ⋆ And that 1 MB is exactly 1 million bytes, 1 GB exactly 1 billion. . . Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 15 / 27

slide-111
SLIDE 111

Calculating with computer units

Let’s say you have a 16 GB USB stick.

◮ And a bunch of videos, 256 MB each. ◮ How many videos can it hold? ◮ 1024 = 256 × 4, so you can fit four videos in one GB. ◮ 4 × 16 = 64: 64 videos on the USB stick.

Beware!

◮ Hard drive manufacturers use a different definition of kB, MB, etc! ◮ They say that 1 kB is exactly 1000 bytes (not 1024). ⋆ And that 1 MB is exactly 1 million bytes, 1 GB exactly 1 billion. . . ◮ When it gets to terabytes, that’s a difference of 10%! Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 15 / 27

slide-112
SLIDE 112

Calculating with computer units

Let’s say you have a 16 GB USB stick.

◮ And a bunch of videos, 256 MB each. ◮ How many videos can it hold? ◮ 1024 = 256 × 4, so you can fit four videos in one GB. ◮ 4 × 16 = 64: 64 videos on the USB stick.

Beware!

◮ Hard drive manufacturers use a different definition of kB, MB, etc! ◮ They say that 1 kB is exactly 1000 bytes (not 1024). ⋆ And that 1 MB is exactly 1 million bytes, 1 GB exactly 1 billion. . . ◮ When it gets to terabytes, that’s a difference of 10%! ◮ Sometimes you will see “KiB”, “MiB”, “GiB”, “TiB”: ⋆ “Kibibytes”, “Mebibytes”, “Gibibytes”, “Tebibytes” ⋆ Unambiguously refer to the 1024 definition, not 1000. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 15 / 27

slide-113
SLIDE 113

Calculating with computer units

Let’s say you have a 16 GB USB stick.

◮ And a bunch of videos, 256 MB each. ◮ How many videos can it hold? ◮ 1024 = 256 × 4, so you can fit four videos in one GB. ◮ 4 × 16 = 64: 64 videos on the USB stick.

Beware!

◮ Hard drive manufacturers use a different definition of kB, MB, etc! ◮ They say that 1 kB is exactly 1000 bytes (not 1024). ⋆ And that 1 MB is exactly 1 million bytes, 1 GB exactly 1 billion. . . ◮ When it gets to terabytes, that’s a difference of 10%! ◮ Sometimes you will see “KiB”, “MiB”, “GiB”, “TiB”: ⋆ “Kibibytes”, “Mebibytes”, “Gibibytes”, “Tebibytes” ⋆ Unambiguously refer to the 1024 definition, not 1000. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 15 / 27

slide-114
SLIDE 114

Programming languages

Computer programming is the process of translating an algorithm into step-by-step instructions a computer can understand.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 16 / 27

slide-115
SLIDE 115

Programming languages

Computer programming is the process of translating an algorithm into step-by-step instructions a computer can understand. So what do these instructions look like? That depends. . .

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 16 / 27

slide-116
SLIDE 116

Programming languages

Computer programming is the process of translating an algorithm into step-by-step instructions a computer can understand. So what do these instructions look like? That depends. . . A programming language is a particular way of writing instructions to a computer.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 16 / 27

slide-117
SLIDE 117

Programming languages

Computer programming is the process of translating an algorithm into step-by-step instructions a computer can understand. So what do these instructions look like? That depends. . . A programming language is a particular way of writing instructions to a computer. There are thousands of programming languages out there, dozens or hundreds of which are still in regular use.

◮ A professional programmer usually knows several. ◮ Then they can choose the right tool (language) for each job.

In CS 115, we’ll learn to write programs in Python, a high-level, interpreted programming language.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 16 / 27

slide-118
SLIDE 118

Syntax and semantics

In a given programming language: Syntax are the rules that say what programs look like

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 17 / 27

slide-119
SLIDE 119

Syntax and semantics

In a given programming language: Syntax are the rules that say what programs look like:

◮ Spelling. ◮ Punctuation. ◮ Order and combination of words (grammar). Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 17 / 27

slide-120
SLIDE 120

Syntax and semantics

In a given programming language: Syntax are the rules that say what programs look like:

◮ Spelling. ◮ Punctuation. ◮ Order and combination of words (grammar).

Semantics are the rules that say what programs mean

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 17 / 27

slide-121
SLIDE 121

Syntax and semantics

In a given programming language: Syntax are the rules that say what programs look like:

◮ Spelling. ◮ Punctuation. ◮ Order and combination of words (grammar).

Semantics are the rules that say what programs mean:

◮ What does the computer do when it executes this statement? ◮ When you combine these statements, what happens? Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 17 / 27

slide-122
SLIDE 122

Syntax and semantics

In a given programming language: Syntax are the rules that say what programs look like:

◮ Spelling. ◮ Punctuation. ◮ Order and combination of words (grammar).

Semantics are the rules that say what programs mean:

◮ What does the computer do when it executes this statement? ◮ When you combine these statements, what happens? Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 17 / 27

slide-123
SLIDE 123

Low-level languages

Low-level languages: Machine code: numbers treated as instructions by the CPU.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 18 / 27

slide-124
SLIDE 124

Low-level languages

Low-level languages: Machine code: numbers treated as instructions by the CPU. 05 01

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 18 / 27

slide-125
SLIDE 125

Low-level languages

Low-level languages: Machine code: numbers treated as instructions by the CPU. 05 01 Assembly code: human-readable way of writing machine code.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 18 / 27

slide-126
SLIDE 126

Low-level languages

Low-level languages: Machine code: numbers treated as instructions by the CPU. 05 01 Assembly code: human-readable way of writing machine code. add EAX, 1 mov [ESP+4], EAX

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 18 / 27

slide-127
SLIDE 127

Low-level languages

Low-level languages: Machine code: numbers treated as instructions by the CPU. 05 01 Assembly code: human-readable way of writing machine code. add EAX, 1 mov [ESP+4], EAX A single instruction does very little. Different languages for Intel (32 and 64 bit), ARM, PowerPC, . . .

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 18 / 27

slide-128
SLIDE 128

Low-level languages

Low-level languages: Machine code: numbers treated as instructions by the CPU. 05 01 Assembly code: human-readable way of writing machine code. add EAX, 1 mov [ESP+4], EAX A single instruction does very little. Different languages for Intel (32 and 64 bit), ARM, PowerPC, . . . For many years, these were the only ways to write programs.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 18 / 27

slide-129
SLIDE 129

Low-level languages

Low-level languages: Machine code: numbers treated as instructions by the CPU. 05 01 Assembly code: human-readable way of writing machine code. add EAX, 1 mov [ESP+4], EAX A single instruction does very little. Different languages for Intel (32 and 64 bit), ARM, PowerPC, . . . For many years, these were the only ways to write programs.

◮ Difficult, verbose, error-prone, and machine-specific. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 18 / 27

slide-130
SLIDE 130

Low-level languages

Low-level languages: Machine code: numbers treated as instructions by the CPU. 05 01 Assembly code: human-readable way of writing machine code. add EAX, 1 mov [ESP+4], EAX A single instruction does very little. Different languages for Intel (32 and 64 bit), ARM, PowerPC, . . . For many years, these were the only ways to write programs.

◮ Difficult, verbose, error-prone, and machine-specific. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 18 / 27

slide-131
SLIDE 131

High-level languages

Low-level languages have very simple instructions—you need lots of instructions to do anything useful.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 19 / 27

slide-132
SLIDE 132

High-level languages

Low-level languages have very simple instructions—you need lots of instructions to do anything useful. High-level languages like Python and C++ make things simpler: allow one statement to stand for many machine code instructions: Assembly language:

mov EAX, EBP[-2] mov EBX, EBP[-4] add EBX, 100 mul EAX, EBX div EAX, 100 mov EBP[2], EAX

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 19 / 27

slide-133
SLIDE 133

High-level languages

Low-level languages have very simple instructions—you need lots of instructions to do anything useful. High-level languages like Python and C++ make things simpler: allow one statement to stand for many machine code instructions: Assembly language:

mov EAX, EBP[-2] mov EBX, EBP[-4] add EBX, 100 mul EAX, EBX div EAX, 100 mov EBP[2], EAX

High-level language:

total = price * (tax + 100) / 100

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 19 / 27

slide-134
SLIDE 134

High-level languages

Low-level languages have very simple instructions—you need lots of instructions to do anything useful. High-level languages like Python and C++ make things simpler: allow one statement to stand for many machine code instructions: Assembly language:

load r1, -2[sp] mov r2, -4[sp] load r3, 100 add r2, r3, r2 mul r1, r2, r4 div r4, r3, r5 store sp[2], r1

High-level language:

total = price * (tax + 100) / 100 And you can translate it into different machine code instructions for another processor.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 19 / 27

slide-135
SLIDE 135

High-level languages

Low-level languages have very simple instructions—you need lots of instructions to do anything useful. High-level languages like Python and C++ make things simpler: allow one statement to stand for many machine code instructions: Assembly language:

load r1, -2[sp] mov r2, -4[sp] load r3, 100 add r2, r3, r2 mul r1, r2, r4 div r4, r3, r5 store sp[2], r1

High-level language:

total = price * (tax + 100) / 100 And you can translate it into different machine code instructions for another processor.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 19 / 27

slide-136
SLIDE 136

Interpreters and compilers

Underneath, the computer still understands only machine code. So if we write in a high-level language, we have to have a way to translate that language into machine code.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 20 / 27

slide-137
SLIDE 137

Interpreters and compilers

Underneath, the computer still understands only machine code. So if we write in a high-level language, we have to have a way to translate that language into machine code. There are two general ways to do this: interpreters and compilers.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 20 / 27

slide-138
SLIDE 138

Interpreters and compilers

Underneath, the computer still understands only machine code. So if we write in a high-level language, we have to have a way to translate that language into machine code. There are two general ways to do this: interpreters and compilers. Interpreter: deciphers a language and executes instructions in order.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 20 / 27

slide-139
SLIDE 139

Interpreters and compilers

Underneath, the computer still understands only machine code. So if we write in a high-level language, we have to have a way to translate that language into machine code. There are two general ways to do this: interpreters and compilers. Interpreter: deciphers a language and executes instructions in order.

+ Easy to change your program: edit source, run again. − Must decode the program each time: slow. − Users need a copy of the interpreter.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 20 / 27

slide-140
SLIDE 140

Interpreters and compilers

Underneath, the computer still understands only machine code. So if we write in a high-level language, we have to have a way to translate that language into machine code. There are two general ways to do this: interpreters and compilers. Interpreter: deciphers a language and executes instructions in order.

+ Easy to change your program: edit source, run again. − Must decode the program each time: slow. − Users need a copy of the interpreter.

◮ Examples: Python, JavaScript, Perl. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 20 / 27

slide-141
SLIDE 141

Interpreters and compilers

Underneath, the computer still understands only machine code. So if we write in a high-level language, we have to have a way to translate that language into machine code. There are two general ways to do this: interpreters and compilers. Interpreter: deciphers a language and executes instructions in order.

+ Easy to change your program: edit source, run again. − Must decode the program each time: slow. − Users need a copy of the interpreter.

◮ Examples: Python, JavaScript, Perl.

Compiler: deciphers a language and translates it to machine code.

◮ (without executing it!) Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 20 / 27

slide-142
SLIDE 142

Interpreters and compilers

Underneath, the computer still understands only machine code. So if we write in a high-level language, we have to have a way to translate that language into machine code. There are two general ways to do this: interpreters and compilers. Interpreter: deciphers a language and executes instructions in order.

+ Easy to change your program: edit source, run again. − Must decode the program each time: slow. − Users need a copy of the interpreter.

◮ Examples: Python, JavaScript, Perl.

Compiler: deciphers a language and translates it to machine code.

◮ (without executing it!)

− Changing a program requires an additional step (compiling). + Compile once, execute many times: runs faster. + Run directly by the operating system—no translator needed.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 20 / 27

slide-143
SLIDE 143

Interpreters and compilers

Underneath, the computer still understands only machine code. So if we write in a high-level language, we have to have a way to translate that language into machine code. There are two general ways to do this: interpreters and compilers. Interpreter: deciphers a language and executes instructions in order.

+ Easy to change your program: edit source, run again. − Must decode the program each time: slow. − Users need a copy of the interpreter.

◮ Examples: Python, JavaScript, Perl.

Compiler: deciphers a language and translates it to machine code.

◮ (without executing it!)

− Changing a program requires an additional step (compiling). + Compile once, execute many times: runs faster. + Run directly by the operating system—no translator needed.

◮ Examples: C++, FORTRAN, Haskell. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 20 / 27

slide-144
SLIDE 144

Interpreters and compilers

Underneath, the computer still understands only machine code. So if we write in a high-level language, we have to have a way to translate that language into machine code. There are two general ways to do this: interpreters and compilers. Interpreter: deciphers a language and executes instructions in order.

+ Easy to change your program: edit source, run again. − Must decode the program each time: slow. − Users need a copy of the interpreter.

◮ Examples: Python, JavaScript, Perl.

Compiler: deciphers a language and translates it to machine code.

◮ (without executing it!)

− Changing a program requires an additional step (compiling). + Compile once, execute many times: runs faster. + Run directly by the operating system—no translator needed.

◮ Examples: C++, FORTRAN, Haskell.

Some languages combine features of both: Java is compiled into an intermediate byte code

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 20 / 27

slide-145
SLIDE 145

Interpreters and compilers

Underneath, the computer still understands only machine code. So if we write in a high-level language, we have to have a way to translate that language into machine code. There are two general ways to do this: interpreters and compilers. Interpreter: deciphers a language and executes instructions in order.

+ Easy to change your program: edit source, run again. − Must decode the program each time: slow. − Users need a copy of the interpreter.

◮ Examples: Python, JavaScript, Perl.

Compiler: deciphers a language and translates it to machine code.

◮ (without executing it!)

− Changing a program requires an additional step (compiling). + Compile once, execute many times: runs faster. + Run directly by the operating system—no translator needed.

◮ Examples: C++, FORTRAN, Haskell.

Some languages combine features of both: Java is compiled into an intermediate byte code, which is then interpreted.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 20 / 27

slide-146
SLIDE 146

Interpreters and compilers

Underneath, the computer still understands only machine code. So if we write in a high-level language, we have to have a way to translate that language into machine code. There are two general ways to do this: interpreters and compilers. Interpreter: deciphers a language and executes instructions in order.

+ Easy to change your program: edit source, run again. − Must decode the program each time: slow. − Users need a copy of the interpreter.

◮ Examples: Python, JavaScript, Perl.

Compiler: deciphers a language and translates it to machine code.

◮ (without executing it!)

− Changing a program requires an additional step (compiling). + Compile once, execute many times: runs faster. + Run directly by the operating system—no translator needed.

◮ Examples: C++, FORTRAN, Haskell.

Some languages combine features of both: Java is compiled into an intermediate byte code, which is then interpreted.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 20 / 27

slide-147
SLIDE 147

An analogy

Suppose you want to make baklava (a kind of dessert pastry).

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 21 / 27 Image: Robert Kindermann, Wikipedia, 29 July 2006.

slide-148
SLIDE 148

An analogy

Suppose you want to make baklava (a kind of dessert pastry). You have a recipe

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 21 / 27 Image: Robert Kindermann, Wikipedia, 29 July 2006.

slide-149
SLIDE 149

An analogy

Suppose you want to make baklava (a kind of dessert pastry). You have a recipe, but it’s in Greek, which you don’t speak.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 21 / 27

Μπακλαβάς

slide-150
SLIDE 150

An analogy

Suppose you want to make baklava (a kind of dessert pastry). You have a recipe, but it’s in Greek, which you don’t speak. You have a friend who speaks Greek and English, but doesn’t know how to bake.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 21 / 27

Μπακλαβάς

slide-151
SLIDE 151

An analogy

Suppose you want to make baklava (a kind of dessert pastry). You have a recipe, but it’s in Greek, which you don’t speak. You have a friend who speaks Greek and English, but doesn’t know how to bake. What to do?

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 21 / 27

Μπακλαβάς

slide-152
SLIDE 152

An analogy

Suppose you want to make baklava (a kind of dessert pastry). You have a recipe, but it’s in Greek, which you don’t speak. You have a friend who speaks Greek and English, but doesn’t know how to bake. What to do? Two options:

1 Have your friend stand with you in the kitchen, telling you each

instruction in order

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 21 / 27

slide-153
SLIDE 153

An analogy

Suppose you want to make baklava (a kind of dessert pastry). You have a recipe, but it’s in Greek, which you don’t speak. You have a friend who speaks Greek and English, but doesn’t know how to bake. What to do? Two options:

1 Have your friend stand with you in the kitchen, telling you each

instruction in order—an interpreter.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 21 / 27

slide-154
SLIDE 154

An analogy

Suppose you want to make baklava (a kind of dessert pastry). You have a recipe, but it’s in Greek, which you don’t speak. You have a friend who speaks Greek and English, but doesn’t know how to bake. What to do? Two options:

1 Have your friend stand with you in the kitchen, telling you each

instruction in order—an interpreter.

2 Give your friend the recipe and have them translate it into an English

recipe and write it down

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 21 / 27

slide-155
SLIDE 155

An analogy

Suppose you want to make baklava (a kind of dessert pastry). You have a recipe, but it’s in Greek, which you don’t speak. You have a friend who speaks Greek and English, but doesn’t know how to bake. What to do? Two options:

1 Have your friend stand with you in the kitchen, telling you each

instruction in order—an interpreter.

2 Give your friend the recipe and have them translate it into an English

recipe and write it down—a compiler.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 21 / 27

slide-156
SLIDE 156

An analogy

Suppose you want to make baklava (a kind of dessert pastry). You have a recipe, but it’s in Greek, which you don’t speak. You have a friend who speaks Greek and English, but doesn’t know how to bake. What to do? Two options:

1 Have your friend stand with you in the kitchen, telling you each

instruction in order—an interpreter.

2 Give your friend the recipe and have them translate it into an English

recipe and write it down—a compiler. You can get started more quickly with the interpretation method, but you need your friend in the kitchen every single time.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 21 / 27

slide-157
SLIDE 157

An analogy

Suppose you want to make baklava (a kind of dessert pastry). You have a recipe, but it’s in Greek, which you don’t speak. You have a friend who speaks Greek and English, but doesn’t know how to bake. What to do? Two options:

1 Have your friend stand with you in the kitchen, telling you each

instruction in order—an interpreter.

2 Give your friend the recipe and have them translate it into an English

recipe and write it down—a compiler. You can get started more quickly with the interpretation method, but you need your friend in the kitchen every single time.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 21 / 27

slide-158
SLIDE 158

Programming environment and tools

What do you need to write programs in Python? An interpreter to translate and execute your program.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 22 / 27

slide-159
SLIDE 159

Programming environment and tools

What do you need to write programs in Python? An interpreter to translate and execute your program. A text editor for writing and changing source code.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 22 / 27

slide-160
SLIDE 160

Programming environment and tools

What do you need to write programs in Python? An interpreter to translate and execute your program. A text editor for writing and changing source code.

◮ Notepad is common, but not really suited for programming. ◮ More advanced editors can: ⋆ Automatically indent code. ⋆ Color code to clarify its meaning. ⋆ Jump from variable name to definition. ⋆ Much more. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 22 / 27

slide-161
SLIDE 161

Programming environment and tools

What do you need to write programs in Python? An interpreter to translate and execute your program. A text editor for writing and changing source code.

◮ Notepad is common, but not really suited for programming. ◮ More advanced editors can: ⋆ Automatically indent code. ⋆ Color code to clarify its meaning. ⋆ Jump from variable name to definition. ⋆ Much more.

A debugger to help find and repair bugs.

◮ Pause execution at a certain line. ◮ Step through code line-by-line. ◮ Inspect and change variables and memory. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 22 / 27

slide-162
SLIDE 162

Programming environment and tools

What do you need to write programs in Python? An interpreter to translate and execute your program. A text editor for writing and changing source code.

◮ Notepad is common, but not really suited for programming. ◮ More advanced editors can: ⋆ Automatically indent code. ⋆ Color code to clarify its meaning. ⋆ Jump from variable name to definition. ⋆ Much more.

A debugger to help find and repair bugs.

◮ Pause execution at a certain line. ◮ Step through code line-by-line. ◮ Inspect and change variables and memory.

These are just some of the tools used by professional programmers.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 22 / 27

slide-163
SLIDE 163

Programming environment and tools

What do you need to write programs in Python? An interpreter to translate and execute your program. A text editor for writing and changing source code.

◮ Notepad is common, but not really suited for programming. ◮ More advanced editors can: ⋆ Automatically indent code. ⋆ Color code to clarify its meaning. ⋆ Jump from variable name to definition. ⋆ Much more.

A debugger to help find and repair bugs.

◮ Pause execution at a certain line. ◮ Step through code line-by-line. ◮ Inspect and change variables and memory.

These are just some of the tools used by professional programmers.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 22 / 27

slide-164
SLIDE 164

Integrated development environments

Many programmers build their toolkits by selecting their favorite tool for each job

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 23 / 27

slide-165
SLIDE 165

Integrated development environments

Many programmers build their toolkits by selecting their favorite tool for each job: interpreter, editor, debugger, etc.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 23 / 27

slide-166
SLIDE 166

Integrated development environments

Many programmers build their toolkits by selecting their favorite tool for each job: interpreter, editor, debugger, etc. An integrated development environment (IDE): combines several programming tools into one cohesive program.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 23 / 27

slide-167
SLIDE 167

Integrated development environments

Many programmers build their toolkits by selecting their favorite tool for each job: interpreter, editor, debugger, etc. An integrated development environment (IDE): combines several programming tools into one cohesive program. Some IDEs for Python:

◮ IDLE: comes with Python. ◮ WingIDE: recommended for this class.

Lab 1 will introduce WingIDE.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 23 / 27

slide-168
SLIDE 168

Integrated development environments

Many programmers build their toolkits by selecting their favorite tool for each job: interpreter, editor, debugger, etc. An integrated development environment (IDE): combines several programming tools into one cohesive program. Some IDEs for Python:

◮ IDLE: comes with Python. ◮ WingIDE: recommended for this class.

Lab 1 will introduce WingIDE. Debugging and other topics in a few weeks.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 23 / 27

slide-169
SLIDE 169

Integrated development environments

Many programmers build their toolkits by selecting their favorite tool for each job: interpreter, editor, debugger, etc. An integrated development environment (IDE): combines several programming tools into one cohesive program. Some IDEs for Python:

◮ IDLE: comes with Python. ◮ WingIDE: recommended for this class.

Lab 1 will introduce WingIDE. Debugging and other topics in a few weeks.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 23 / 27

slide-170
SLIDE 170

The End

Don’t hesitate to email or visit office hours. Next lecture:

◮ Installing and using Python and WingIDE. ◮ A first Python program. ◮ Documentation and comments. ◮ Programming errors and debugging. ◮ Variables, identifiers, and assignment. ◮ Arithmetic.

What questions do you have?

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 24 / 27

slide-171
SLIDE 171

The End

Don’t hesitate to email or visit office hours. Next lecture:

◮ Installing and using Python and WingIDE. ◮ A first Python program. ◮ Documentation and comments. ◮ Programming errors and debugging. ◮ Variables, identifiers, and assignment. ◮ Arithmetic.

What questions do you have?

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 24 / 27

slide-172
SLIDE 172

How to do a design in CS 115

Use a plain text editor, not a word processor.

◮ The editor in IDLE or WingIDE works. ◮ Notepad works. ◮ Mac TextEdit: Format → Make Plain Text. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 25 / 27

slide-173
SLIDE 173

How to do a design in CS 115

Use a plain text editor, not a word processor.

◮ The editor in IDLE or WingIDE works. ◮ Notepad works. ◮ Mac TextEdit: Format → Make Plain Text.

State the purpose of the program up top.

◮ Followed by your name, section, email, assignment number. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 25 / 27

slide-174
SLIDE 174

How to do a design in CS 115

Use a plain text editor, not a word processor.

◮ The editor in IDLE or WingIDE works. ◮ Notepad works. ◮ Mac TextEdit: Format → Make Plain Text.

State the purpose of the program up top.

◮ Followed by your name, section, email, assignment number.

One step per line.

◮ Start the line with a “#” symbol (we’ll see why next time). ◮ Indent and number substeps and repeated steps. ◮ Can number them 7.1, 7.2; or a, b, c: just make it clear. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 25 / 27

slide-175
SLIDE 175

How to do a design in CS 115

Use a plain text editor, not a word processor.

◮ The editor in IDLE or WingIDE works. ◮ Notepad works. ◮ Mac TextEdit: Format → Make Plain Text.

State the purpose of the program up top.

◮ Followed by your name, section, email, assignment number.

One step per line.

◮ Start the line with a “#” symbol (we’ll see why next time). ◮ Indent and number substeps and repeated steps. ◮ Can number them 7.1, 7.2; or a, b, c: just make it clear.

Hint: wait until the very end to number the steps.

◮ That way there is less to change if you have to rearrange your design. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 25 / 27

slide-176
SLIDE 176

How to do a design in CS 115

Use a plain text editor, not a word processor.

◮ The editor in IDLE or WingIDE works. ◮ Notepad works. ◮ Mac TextEdit: Format → Make Plain Text.

State the purpose of the program up top.

◮ Followed by your name, section, email, assignment number.

One step per line.

◮ Start the line with a “#” symbol (we’ll see why next time). ◮ Indent and number substeps and repeated steps. ◮ Can number them 7.1, 7.2; or a, b, c: just make it clear.

Hint: wait until the very end to number the steps.

◮ That way there is less to change if you have to rearrange your design.

Give your file a name ending in .py (Python code)

◮ Why? The design will be the basis for your implementation. ◮ You’ll write code for each step of the design. ⋆ Before long, you’ll have a working program. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 25 / 27

slide-177
SLIDE 177

How to do a design in CS 115

Use a plain text editor, not a word processor.

◮ The editor in IDLE or WingIDE works. ◮ Notepad works. ◮ Mac TextEdit: Format → Make Plain Text.

State the purpose of the program up top.

◮ Followed by your name, section, email, assignment number.

One step per line.

◮ Start the line with a “#” symbol (we’ll see why next time). ◮ Indent and number substeps and repeated steps. ◮ Can number them 7.1, 7.2; or a, b, c: just make it clear.

Hint: wait until the very end to number the steps.

◮ That way there is less to change if you have to rearrange your design.

Give your file a name ending in .py (Python code)

◮ Why? The design will be the basis for your implementation. ◮ You’ll write code for each step of the design. ⋆ Before long, you’ll have a working program. Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 25 / 27

slide-178
SLIDE 178

Example program design

# Purpose: Ask for the user’s name and greet them. # Author:

  • J. Random Hacker, section 1,

# random.hacker@uky.edu # Assignment: Lab 42 # Main program: # 1. Input the user’s name from the keyboard # 2. Output the word hello, followed by the user’s name.

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 26 / 27

slide-179
SLIDE 179

Turned into code

We’ll see more about how this code works next time. # Purpose: Ask for the user’s name and greet them. # Author:

  • J. Random Hacker, section 1,

# random.hacker@uky.edu # Assignment: Lab 42 # Main program: def main(): # 1. Input the user’s name from the keyboard name = input("What is your name? ") # 2. Output the word hello, followed by the user’s name. print("Hello ", name) main()

Neil Moore (UK CS) CS 115 Lecture 2 Fall 2015 27 / 27