Introduction to programming - class 1
-
Upload
paul-brebner -
Category
Education
-
view
172 -
download
1
Transcript of Introduction to programming - class 1
![Page 2: Introduction to programming - class 1](https://reader033.fdocuments.us/reader033/viewer/2022052313/58edd7501a28abc32e8b460f/html5/thumbnails/2.jpg)
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
![Page 3: Introduction to programming - class 1](https://reader033.fdocuments.us/reader033/viewer/2022052313/58edd7501a28abc32e8b460f/html5/thumbnails/3.jpg)
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)
![Page 4: Introduction to programming - class 1](https://reader033.fdocuments.us/reader033/viewer/2022052313/58edd7501a28abc32e8b460f/html5/thumbnails/4.jpg)
Colossus – 70 years old, 1st programmable electronic (valve) computer
![Page 5: Introduction to programming - class 1](https://reader033.fdocuments.us/reader033/viewer/2022052313/58edd7501a28abc32e8b460f/html5/thumbnails/5.jpg)
“My” computers
• 1978, Burroughs B6700, > $1M
• Mainframe Bank computer with “punch cards”
![Page 6: Introduction to programming - class 1](https://reader033.fdocuments.us/reader033/viewer/2022052313/58edd7501a28abc32e8b460f/html5/thumbnails/6.jpg)
2 = Card reader
![Page 7: Introduction to programming - class 1](https://reader033.fdocuments.us/reader033/viewer/2022052313/58edd7501a28abc32e8b460f/html5/thumbnails/7.jpg)
First home made
• Mini-scamp microcomputer – 1979, $200
• Microprocessor (Computer on a single chip)
• 256 Bytes RAM, 1MHz CPU, Input = switches, output = LEDs
![Page 8: Introduction to programming - class 1](https://reader033.fdocuments.us/reader033/viewer/2022052313/58edd7501a28abc32e8b460f/html5/thumbnails/8.jpg)
VAX 11/780 (1980)
![Page 9: Introduction to programming - class 1](https://reader033.fdocuments.us/reader033/viewer/2022052313/58edd7501a28abc32e8b460f/html5/thumbnails/9.jpg)
VAX specs
• 1MByte RAM (Core memory)
• 1MHz CPU, $250,000, lots of circuit boards
![Page 10: Introduction to programming - class 1](https://reader033.fdocuments.us/reader033/viewer/2022052313/58edd7501a28abc32e8b460f/html5/thumbnails/10.jpg)
Home designed & made
• 1984
• $1,000, 64KBytes RAM
• 6809 CPU (2 MHz)
• 8” floppy disc
• Programmed for
– music synthesiser
![Page 11: Introduction to programming - class 1](https://reader033.fdocuments.us/reader033/viewer/2022052313/58edd7501a28abc32e8b460f/html5/thumbnails/11.jpg)
Amiga 500
• Game machine!
– 1987, $1,000
– 0.5MByte RAM
– 7MHz CPU
– Colour graphics and sound
– Mouse
– 3.5 inch floppy disk
![Page 12: Introduction to programming - class 1](https://reader033.fdocuments.us/reader033/viewer/2022052313/58edd7501a28abc32e8b460f/html5/thumbnails/12.jpg)
![Page 13: Introduction to programming - class 1](https://reader033.fdocuments.us/reader033/viewer/2022052313/58edd7501a28abc32e8b460f/html5/thumbnails/13.jpg)
Intel 486
• 1993, homebuilt, 50MHz CPU, $3,000
![Page 14: Introduction to programming - class 1](https://reader033.fdocuments.us/reader033/viewer/2022052313/58edd7501a28abc32e8b460f/html5/thumbnails/14.jpg)
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
![Page 15: Introduction to programming - class 1](https://reader033.fdocuments.us/reader033/viewer/2022052313/58edd7501a28abc32e8b460f/html5/thumbnails/15.jpg)
Simulation game
• Everyone has a role:– Fetch
– Decode
– Execute• LOADR1, LOADR2, STORE, ADDER, END
– BUS
– MEMORY
– DISPLAY
• Explain Registers and roles
![Page 16: Introduction to programming - class 1](https://reader033.fdocuments.us/reader033/viewer/2022052313/58edd7501a28abc32e8b460f/html5/thumbnails/16.jpg)
Simulation
• Here’s the program in “binary”– 0101– 1000– 0110– 100– 1010– 0101– 1001– 1101– 1010– 1111
![Page 17: Introduction to programming - class 1](https://reader033.fdocuments.us/reader033/viewer/2022052313/58edd7501a28abc32e8b460f/html5/thumbnails/17.jpg)
Simulation: What will it do? Displays two characters...
• Here’s the program in “English” (some hidden)– LOADR1– ?– LOADR2– 100– STORE– LOADR1– ?– INCR2– STORE– END
![Page 18: Introduction to programming - class 1](https://reader033.fdocuments.us/reader033/viewer/2022052313/58edd7501a28abc32e8b460f/html5/thumbnails/18.jpg)
![Page 19: Introduction to programming - class 1](https://reader033.fdocuments.us/reader033/viewer/2022052313/58edd7501a28abc32e8b460f/html5/thumbnails/19.jpg)
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
![Page 20: Introduction to programming - class 1](https://reader033.fdocuments.us/reader033/viewer/2022052313/58edd7501a28abc32e8b460f/html5/thumbnails/20.jpg)
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!
![Page 21: Introduction to programming - class 1](https://reader033.fdocuments.us/reader033/viewer/2022052313/58edd7501a28abc32e8b460f/html5/thumbnails/21.jpg)
Processing layers
• Processing
– Runs on
• Java
– Runs on
• JVM
– Runs on
• Actual CPU
![Page 22: Introduction to programming - class 1](https://reader033.fdocuments.us/reader033/viewer/2022052313/58edd7501a28abc32e8b460f/html5/thumbnails/22.jpg)
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)
![Page 23: Introduction to programming - class 1](https://reader033.fdocuments.us/reader033/viewer/2022052313/58edd7501a28abc32e8b460f/html5/thumbnails/23.jpg)
![Page 24: Introduction to programming - class 1](https://reader033.fdocuments.us/reader033/viewer/2022052313/58edd7501a28abc32e8b460f/html5/thumbnails/24.jpg)
![Page 25: Introduction to programming - class 1](https://reader033.fdocuments.us/reader033/viewer/2022052313/58edd7501a28abc32e8b460f/html5/thumbnails/25.jpg)
![Page 26: Introduction to programming - class 1](https://reader033.fdocuments.us/reader033/viewer/2022052313/58edd7501a28abc32e8b460f/html5/thumbnails/26.jpg)
![Page 27: Introduction to programming - class 1](https://reader033.fdocuments.us/reader033/viewer/2022052313/58edd7501a28abc32e8b460f/html5/thumbnails/27.jpg)
![Page 28: Introduction to programming - class 1](https://reader033.fdocuments.us/reader033/viewer/2022052313/58edd7501a28abc32e8b460f/html5/thumbnails/28.jpg)
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
}