Introduction to programming - class 1

28
Introduction to Programming Class 1 Paul Brebner [email protected] CTO Performance Assurance Pty Ltd

Transcript of Introduction to programming - class 1

Page 1: Introduction to programming - class 1

Introduction to ProgrammingClass 1

Paul Brebner

[email protected]

CTO Performance Assurance Pty Ltd

Page 2: 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

Page 3: Introduction to programming - class 1

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

Colossus – 70 years old, 1st programmable electronic (valve) computer

Page 5: Introduction to programming - class 1

“My” computers

• 1978, Burroughs B6700, > $1M

• Mainframe Bank computer with “punch cards”

Page 6: Introduction to programming - class 1

2 = Card reader

Page 7: Introduction to programming - class 1

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

VAX 11/780 (1980)

Page 9: Introduction to programming - class 1

VAX specs

• 1MByte RAM (Core memory)

• 1MHz CPU, $250,000, lots of circuit boards

Page 10: Introduction to programming - class 1

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

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
Page 13: Introduction to programming - class 1

Intel 486

• 1993, homebuilt, 50MHz CPU, $3,000

Page 14: Introduction to programming - class 1

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

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

Simulation

• Here’s the program in “binary”– 0101– 1000– 0110– 100– 1010– 0101– 1001– 1101– 1010– 1111

Page 17: Introduction to programming - class 1

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
Page 19: Introduction to programming - class 1

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

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

Processing layers

• Processing

– Runs on

• Java

– Runs on

• JVM

– Runs on

• Actual CPU

Page 22: Introduction to programming - class 1

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
Page 24: Introduction to programming - class 1
Page 25: Introduction to programming - class 1
Page 26: Introduction to programming - class 1
Page 27: Introduction to programming - class 1
Page 28: Introduction to programming - class 1

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

}