georgia institute of technology workshop for programming and systems management teachers chapter 1...

57
Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Upload: tamsyn-douglas

Post on 14-Dec-2015

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Workshop for Programming And Systems Management Teachers

Chapter 1

Introduction to Computers and Programming

Page 2: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Learning Goals

• Understand at a conceptual level– What is a computer?– What are the parts of a computer?– What can computers do?– What is a program?– Why learn to program?– What is hard about learning to program?– What is hard about teaching programming?– Strategies for teaching programming

Page 3: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

What is a Computer?

• One who computes• A device that performs

high-speed mathematical and/or logical operations or that assembles, stores, correlates, or otherwise processes information.

• The first computers were people – who did computations

Page 4: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Parts of a Computer

• User Interface – monitor (screen),

mouse, keyboard, printer

• Brain - Central Processing Unit – can do math and logic

operations

• Memory - Storage– main - RAM– secondary – Disks,

CD-ROMs, DVDs

Page 5: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

CPU – Brain of the Computer

• Arithmetic/Logic Unit (ALU)– Does math and logic

calculations on numbers in registers

• Control Unit– Reads instructions

from memory and decodes and executes them using the ALU

345

263Add register A to register B

608 Store the value in register C into memory location320843202

Page 6: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Fetch, Decode, Execute Cycle

• The control unit reads (fetches) an instruction from memory

• The control unit decodes the instruction and sets up the hardware to do the instruction – like add the values in the A and B registers

and put the result in the C register

• The instruction is executed • The program counter is incremented to

read the next instruction

Page 7: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Processor Speed

• Processors (CPUs) have a clock

• Clock speed is measured in megahertz (MHz) or gigahertz (GHz)

• Some instructions take just 2-3 clock cycles, some take more

• When the clock speed increases the computer can execute instructions faster

Page 8: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Memory• Computer memory is

used to store data • The smallest unit of

memory is a bit (Binary digIT)

• A bit can be off (no voltage) or on (has voltage) which we interpret to be 0 or 1

• Memory is organized into 8 bit contiguous groups called bytes. A megabyte is 1,048,576 bytes (over 1 million bytes). A gigabyte is over 1 billion bytes.

Page 9: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

How does Memory Represent Values?

• The different patterns of the on and off bits in a byte determine the value stored

• Numbers are stored using binary numbers– 101 is 1 * 20 + 0 * 21 + 1 * 22 = 5

• Characters are internally represented as numbers– Different numbers represent different characters– There are several systems for assigning numbers to

characters: • ASCII, EBCDIC, and Unicode

Page 10: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Encodings Make Computer Powerful

• Voltages are interpreted as numbers

• Numbers can be interpreted as characters

• Characters can be interpreted to be part of a link to Sun’s Java Site

0100 0001

off on off off off off off on

a

<a href=http://java.sun.com>Sun’s Java Site </a>

Page 11: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Notepad Exercise

• Open notepad and type a sentence in it

• Save the file• Check the size in

bytes by leaving the cursor over the file name

• Now count the number of letters and spaces

Page 12: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Binary Numbers

• We usually work with decimal numbers with digits from 0 to 9 and powers of 10

7313 = (7 * 1000 + 3 * 100 + 1 * 10 + 3 * 1)

Or (7 * 103 + 3 * 102 + 1 * 101 + 3 * 100)

• The binary number system uses digits 0 and 1 and powers of 2

0101 = (0 * 23 + 1 * 22 + 0 * 21 + 1 *20)

(0 * 8 + 1 * 4 + 0 * 2 + 1 * 1) = 5

Page 13: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Binary Addition

• To add two decimal numbers you add the digits and if the total is greater than ten you carry the one into the next column

• To add two binary numbers – 0 + 0 = 0– 0 + 1 and 1 + 0 = 1– 1 + 1 = 0 with a carry of 1

into the next column to the left

00 10 111

01 01 001

---- --- ------

01 11 1000

00111001010

01010101101

-------------------

10001110111

Page 14: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

2’s Compliment Notation

• Computers actually only know how to add– So, how do they handle subtraction?

• Computers subtract by adding a negative number

• How do you represent a negative number in memory?– Positive numbers in 2’s compliment are just

the same as a binary number– For negative numbers reverse 0s and 1s and

then add 1

Page 15: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

2’s Compliment Example

• To subtract 3 from 7

• First represent both as a binary number– 7 is 0000 0111– 3 is 0000 0011

• Reverse the 0s and 1s and then add 1 to get -3– 0000 0011 reversed is 1111 1100– add 1 0000 0001– The result is 1111 1101

Page 16: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Add the Negative Number

• To subtract 3 from 7

• Add -3 to 7 – 7 is 0000 0111– -3 is 1111 1101– The result is 1 0000 0100

• Through away the leftmost 1

• The answer is 0000 0100 which is 4

Page 17: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Patterns Exercise

• How many different patterns of on and off bits are there in 3 bits? How many in 4 bits? How many in 8 bits?

• 000 is one pattern

• 001 is another pattern

• 010 is another pattern

Page 18: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Does the number of patterns matter?

• Some garage door openers in the 70s used 8 bits to set the code to use to open the door– Giving 256 different

patterns– Which is enough that

you won’t open your neighbors door

– But small enough that someone could try each one

Page 19: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Remote Entry Systems• With 8 bits for a code you

have a 1/256 chance of a random code working– You don’t want someone

opening your car in a place with lots of cars (like a mall)

• There are also radio scanners that can capture your code– So you want the code to

change each time • Modern remote entry

systems use a 40 bit rolling code

Page 20: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Types of Memory• Registers

– Very high speed temporary storage areas for use in the CPU

• Cache– High speed temporary storage for use with the CPU

• Main Memory – Random-access Memory (RAM)– High speed temporary storage – Contains programs and data currently being used– Often described in Megabytes (MB)

• Secondary Memory - Disks– Contains programs and data not currently being used– Often described in Gigabytes (GB)

Page 21: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Why are there so many types of memory?

• The faster memory is the more it costs– So we reduce the cost by using small

amounts of expensive memory (registers, cache, and RAM) and large amounts of cheaper memory (disks)

• Why do we need cache?– Processors are very fast and need quick

access to lots of data– Cache provides quick access to data from

RAM

Page 22: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

What can Computers Do?

• Add, subtract, multiply, and divide numbers in registers

• Logic operations on numbers in registers– Less than, greater than, equal to– When true jump to a new instruction

• Move data between types of memory and to other input and output devices

Page 23: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Vocabulary Exercise• Look at two computer

advertisements• See if you can figure out what all

the words mean• Use the internet to look up

unfamiliar words – http://computer.howstuffworks.com/– http://en.wikipedia.org/– http://webopedia.com

• Which one is a better for computer games?

• Which one is better for your homework?

Page 24: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

What is a Computer Program?

• Instructions to a computer that allow it to process some data

• You can think of it like a recipe– It contains instructions – Processes ingredients

to produce a result– You can use the same

recipe over and over

Page 25: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Computer Languages

• Each processor has its own language– Machine language – 0001 may be the instruction for adding two registers

• Assembly language is a low-level language– Has the same instructions as machine language but

allows people to use names for the instructions instead of numeric codes (like ADD)

– An assembler translates the names into the numeric machine language

– Executes very fast– Slow for programming

Page 26: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Programming is About Naming

• Computers can associate names with anything– A byte– A group of bytes– A group of letters– A file – A picture– A program, recipe, or function (method) – A type (class)

Page 27: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

File Names

• Operating systems associate file names with locations on your hard disk– A hard disk stores values

even after the power is turned off

• When you double click on a file– The operating system

reads the data starting at that location into RAM

Page 28: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Names for Values

• When work with data in main memory we will usually assign a name to it. – Rather than remember the address in memory

• The computer associates the name with the address for us

• Programs are like algebra– Where you use names to make the equations

make sense• PV=nRT or e=Mc2

Page 29: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Programs are for People

• The computer doesn’t care what names we use

• The names are important so that our programs are understandable– To us– To others

• Names should be appropriate– Not too long or confusing

Page 30: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

High Level Languages

• Are translated (compiled) into machine language or assembly language

• Contains more instructions than in the original machine language– Which translate into several machine

language instructions

• May have slower execution speed than an assembly language program

• Easier and faster for writing programs

Page 31: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Programming Languages

• A set of names that have encodings– Some names allow us to define new

encodings

• You can assign a name to represent a value (we call this a variable)

• You can assign a name to represent a function or procedure

• You can assign a name to a collection of related variables and functions/procedures

Page 32: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

FORTRAN

• Acronym for formula translator

• The first high-level language

• Developed in the 1950s at IBM by John Backus

• Mostly used for scientific applications that require extensive mathematical computations.

• There have been several versions• The most recent is FORTRAN-90

Page 33: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

COBOL

• Acronym for common business oriented language.

• Developed in the late 1950s and early 1960s by the Conference on Data Systems and Languages (CODASYL).

• Popular for business applications that run on large computers

• Meant to be easy to read– Very wordy to program

Page 34: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

BASIC

• Acronym for Beginner's All-purpose Symbolic Instruction Code.

• Developed in the mid 1960s at Dartmouth College by John G. Kemeny and Thomas E. Kurtz

• Mostly used in business and education

• VisualBasic is a form of BASIC created by MicroSoft that uses visual programming– Good for graphical user interfaces

Page 35: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

RPG

• Originally meant Report Program Generator – but as of 1998 with RPG IV (RPG/LE) it is no longer

an acronym

• Originally developed in 1965 to generate reports from data files and databases– Not as verbose as COBOL– More functionality than BASIC

• Has evolved into a procedural programming language

• Used on IBM and DEC minicomputers

Page 36: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

C

• Developed by Dennis Ritchie at Bell Labs in the mid 1970s

• Originally a systems programming language– Closer to machine language than other high-

level languages– Used to develop the UNIX operating system

• Popular in business and science in the 80s • Used on personal computers because took less

memory than other computer languages

Page 37: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

C++

• Developed by Bjarne Stroustrup at Bell Labs in 1986

• Added object-oriented features to its predecessor, C.

• Very popular in the late 80s to 90s

• Popular for 3-d graphics

Page 38: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Java

• Developed at Sun in the early 1990s– Invented by James Gosling

• Similar to C++ in syntax but easier to use– Java is C++ --

• Cross-platform, object-oriented language

• Used in business, science, and education

• One of the fastest adopted technologies of all time

Page 39: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

C#

• Microsoft developed object-oriented language for the .NET platform

• Created by Anders Hejlsberg (author of Turbo Pascal and architect of Delphi), Scot Wiltamuth, and Peter Golde

• Similar to Java– Garbage collection– No explicit pointers– Doesn’t compile to machine language

• Common language runtime (CLR)

Page 40: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Which Language?

• All high-level languages are eventually translated into machine language

• You can write the same program in any language– The computer doesn’t care what high-level

language you use

• The language matters to the programmer– How long does it take to write the program?– How hard is it to change the program?– How long does it take to execute?

Page 41: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Why Don’t We Just Use English?

• English is good for communication between two intelligent humans– Even then we sometimes don’t

understand

• Computers are very stupid– They basically know how to

add, compare, store, and load– Programs are very detailed

instructions• Everything must be precise and

unambiguous

Page 42: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Programming Exercise

• Write down instructions for how to play checkers

• Have another group read the directions and do the actions – stop anytime anything

isn’t clear and ask for clarification

Page 43: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Why Learn to Program?• Alan Perlis, first head of Carnegie Mellon's

Computer Science Department, made the claim in 1961 that computer science, and programming explicitly, should be part of a liberal education

• Seymour Papert claimed in the 70’s and 80’s that learning to program is “learning to think, and debug one’s own thoughts.”– If you learned to program, you learned to plan, to

debug, to handle complexity, etc.• Twenty years of research found that that is

simply not true.• Most people don’t learn to program

Page 44: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

What CS Education Research Tells Us• Most people don’t learn to program in one

semester– Alan Perlis, “Most people find the concept of

programming obvious, but the doing impossible.” • Many people find CS classes boring and

irrelevant• Most people can’t transfer what they learn in

programming• Students have a hard time putting statements

together to accomplish a task• Students learn much less than teachers think

they will

Page 45: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

So, Why Learn to Program?

• The computer is the most amazingly creative device that humans have ever conceived of. If you can imagine it, you can make it “real” on a computer.

• Computers will continue to have a major impact on modern life– Movies, games, business,

healthcare, science, education, etc

Page 46: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Computers Are Commonplace

• Computers, or at least processors, are in many common devices

Page 47: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Programming is Communicating

• Alan Perlis, “You think you know when you can learn, are more sure when you can write, even more when you can teach, but certain when you can program.”

Page 48: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

What is Hard About Programming?

• It is easier to write an incorrect program than understand a correct one – Alan Perlis

• Beginners have a hard time understanding some of the core concepts– Boolean expressions with more than two items

• if (a < b) is okay• if (a < b && c > d) is hard

– Iteration (loops)

• Beginners have a hard time putting statements together to accomplish a task

Page 49: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Strategies for Teaching Programming

• Do Live Programming

• Choose Depth over Breadth

• Assign Interesting Programs

• Use Pair Programming

• Start by Modifying Programs

• Have Lots of Small Projects

• Go from Concrete to Abstract

Page 50: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Do Live Programming

• Program in front of the students and talk about what you are doing and why you are doing it– Programming is a new and

strange activity for most people

– Talk through the algorithms and how to translate them to code

– Let them see you make mistakes and fix them

– Learn by example

Page 51: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Choose Depth over Breadth

• Cover difficult topics in depth

• Cover topics in more than one way

• Try to get people to connect the concept to something they already know to reduce “brittle knowledge”

Page 52: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Assign Interesting Programs

• A basic problem is that students find programming projects irrelevant

• Use motivating, relevant examples and projects– Games, digital video

special effects, animation, graphics, pictures, sound, web pages, simulations

Page 53: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Use Pair Programming

• Have two students work together on programs

• They can explain what they are thinking to each other– Learn from each other

• One may be better at typing– Reducing frustration

Page 54: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Start by Modifying Programs

• Students won’t have to remember everything at once– Just focus on the part they are trying to understand– Less daunting than starting with nothing– Just getting the syntax right is time consuming– Reading code is a valuable skill

• The given code provides a sample of good coding practice– Teach by example– Gives advanced students something to learn from

Page 55: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Lots of Small Projects

• Programming is a skill– It takes practice

• Getting the program to work– Is frustrating while you are working on it– Rewarding when it works

• Students take much longer to program than teachers estimate– Expert programmers are much, much faster

than beginners

Page 56: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Go from Concrete to Abstract

• Use props, live demonstrations, role playing– People learn better when you start with

concrete things and later introduce abstract ideas

• Try to link concepts to students lives– To make it relevant– Reduce brittle knowledge

Page 57: Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 1 Introduction to Computers and Programming

Summary• Computers are fairly simple machines

– Fancy calculators with lots of storage– But incredibly fast

• Computers have changed modern life• Programs are instructions to a computer to

accomplish a task• Programs written in high-level languages are

translated to machine or assembly language by a compiler

• Programming is hard to learn– But there are some ways to make it easier