Introduction to programming - class 1
-
Upload
paul-brebner -
Category
Education
-
view
172 -
download
1
Transcript of Introduction to programming - class 1
Notes
• Slides, exercises, example programs, etc for an Introductory High School Programming Elective (Years 9 and 10)
• No prior experience assumed• Ran for 2 school terms• Required 1 computer per 2 students, a computer and
projector for the presenter• Based on the language Processing, www.processing.org• Each class was about 1.5 hours long, included talk and
supervised exercises, there was also another 45 minute class per week which was just for practical exercises
• Assumes that there is reasonable IT support, that students can download and run things from the internet, and that they can save, share, and load programs
Who am I?
• Computer Scientist
– Study of computers and computing
– The theory of computing
• What is a
– Programmer? Software Architect? Software Engineer? IT person?
• History of computers (mine)
Colossus – 70 years old, 1st programmable electronic (valve) computer
“My” computers
• 1978, Burroughs B6700, > $1M
• Mainframe Bank computer with “punch cards”
2 = Card reader
First home made
• Mini-scamp microcomputer – 1979, $200
• Microprocessor (Computer on a single chip)
• 256 Bytes RAM, 1MHz CPU, Input = switches, output = LEDs
VAX 11/780 (1980)
VAX specs
• 1MByte RAM (Core memory)
• 1MHz CPU, $250,000, lots of circuit boards
Home designed & made
• 1984
• $1,000, 64KBytes RAM
• 6809 CPU (2 MHz)
• 8” floppy disc
• Programmed for
– music synthesiser
Amiga 500
• Game machine!
– 1987, $1,000
– 0.5MByte RAM
– 7MHz CPU
– Colour graphics and sound
– Mouse
– 3.5 inch floppy disk
Intel 486
• 1993, homebuilt, 50MHz CPU, $3,000
Basic computer architecture
Address 0
Address 1
Address 2
Address 3
MEMORYCPU
BUS
Address 100
Address 101
DISPLAY
1 FETCH
PC
IR 2 DECODE
3 EXECUTELOADR1LOADR2STOREADDER
END
Registers
R1
R2
Simulation game
• Everyone has a role:– Fetch
– Decode
– Execute• LOADR1, LOADR2, STORE, ADDER, END
– BUS
– MEMORY
– DISPLAY
• Explain Registers and roles
Simulation
• Here’s the program in “binary”– 0101– 1000– 0110– 100– 1010– 0101– 1001– 1101– 1010– 1111
Simulation: What will it do? Displays two characters...
• Here’s the program in “English” (some hidden)– LOADR1– ?– LOADR2– 100– STORE– LOADR1– ?– INCR2– STORE– END
Problem!
• Machine code programs– In binary – too hard to read/write
– Hard to write large (> 1000 lines?) programs
– Only processes binary numbers – what about decimals? text? Images?
– Error prone
– Not portable – every CPU type has a different instruction set, have to rewrite the program for every CPU type.
– Solution• High level programming languages
– E.g. Fortran, COBOL, LISP, Prolog, Pascal, C, C++, C#, Java, Javascript, Processing
High level languages
• High level programming language– e.g. Print(“hi”)
– Translated (Compiled) into machine code
– Or run on a “Virtual machine”
– Java “write once, run everywhere”• Runs on a JVM (Java Virtual Machine).
• Can run on anything from a mobile phone to a super-computer
– “Processing” – a high level graphics language running on top of Java!
Processing layers
• Processing
– Runs on
• Java
– Runs on
• JVM
– Runs on
• Actual CPU
Lines of Code
• How big are programs? 1 LOC – 100M LOC• How many lines of code a day is normal?
– 10 LOC a day per programmer (famous figure)– As programs get bigger it gets harder to get them to work correctly
• Programming includes other critical tasks– Management (planning for what needs doing when by who)– Specification (what should the program do?)– Design (how should the program do it?)– Programming (writing the program)– Reviewing (reading the program – often someone else’s program – to check it)– Integration (getting your part of the program working with other parts)– Testing (does the program do what is should do? Does it have bugs?)– Debugging (getting rid of the bugs – no program is ever bug free)– Deployment (putting the program where it needs to be to run)– Maintenance (keeping it running, upgrading it)– Retirement (removing the program once it is no longer needed)– Documentation (describing how the program works so someone else can understand it)
Processing Example: Patterns// Move the mouse around. The faster you go the bigger the ellipse// This is a COMMENT
// Primitive processing function: setup() is called once to create screen size and colourvoid setup() {
size(640, 360);background(102);
}
// Primitive processing function: draw() repeats forevervoid draw() {
variableEllipse(mouseX, mouseY, pmouseX, pmouseY);}
// a new function! draws a LARGER ellipse the fasterrrrrrrrrrrrrrrr the mouse speed// speed is computed as the distance between current and previous positionsvoid variableEllipse(int x, int y, int px, int py) {
float speed = abs(x-px) + abs(y-py);stroke(speed); // primitive – sets the drawing colour (float type = white to black)ellipse(x, y, speed, speed); // primitive – draws an oval at position x, y, and height and width
}