welcome to cs120 fall 2012 1 john magee ([email protected])

48
Welcome to CS120 Welcome to CS120 Fall 2012 Fall 2012 1 John Magee John Magee ([email protected]) ([email protected])

Upload: milo-stone

Post on 29-Dec-2015

216 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

Welcome to CS120Welcome to CS120

Fall 2012Fall 2012

11

John MageeJohn Magee([email protected])([email protected])

Page 2: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

Welcome to CS120Welcome to CS120

Computing is ubiquitousComputing is ubiquitous– Daily life, news, eCommerce…Daily life, news, eCommerce…– Sciences and engineering fieldsSciences and engineering fields– Social sciences, humanity,Social sciences, humanity,– Arts, music, sportsArts, music, sports– Education Education – ……

Page 3: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

ComputingComputing One core objective of computing is efficient problem One core objective of computing is efficient problem

solving solving Computing shares common methodologies with Computing shares common methodologies with

other fieldsother fields

Given a problem, how toGiven a problem, how to– Understand it, formulate it, make hypotheses…Understand it, formulate it, make hypotheses…

Many computing problems come from other fieldsMany computing problems come from other fields

– Design a solutionDesign a solution strategies for big problems, such as divide and conquerstrategies for big problems, such as divide and conquer

– Implement a solutionImplement a solution Should be done in a systematic, disciplined fashionShould be done in a systematic, disciplined fashion

– Test a solutionTest a solution– Revise, improve…Revise, improve…

Page 4: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

CS120CS120 Object-oriented programmingObject-oriented programming Graphics/animation-based problemsGraphics/animation-based problems Alice: A 3D animation languageAlice: A 3D animation language Java: an Eventful ApproachJava: an Eventful Approach Main topicsMain topics

– MethodsMethods– Variables and functionsVariables and functions– Control structuresControl structures– Lists and ArraysLists and Arrays– EventsEvents– ClassesClasses

Page 5: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

Why Learn Programming?Why Learn Programming?

– Programming is a challenging and intellectually engaging experience.

– Programming is a part of computer science, and is therefore important to anyone interested in becoming a computer professional.

55

Page 6: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

Why Learn Programming?Why Learn Programming?

– Computers have become commonplace in our society, and understanding their strengths and limitations requires an understanding of programming.

– Programming can be a lot of fun.– Programming is a skill that can pay

the bills. Very well.

66

Page 7: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

About Learning to ProgramAbout Learning to Program

Pre-requisitesThis is a first course in computer science. There are no formal pre-requisites. Some informal pre-req’s:

– using email, browsing the web– copying and pasting text– some high-school level algebra

TimeAnyone can be successful at learning programming.Decent results, however, take a lot of time.

77

Page 8: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

How do we get there?How do we get there?

88 9

LecturesTeaching LabsWeekly HomeworksProjectsMidtermWritten Exam and Practical Exam

Page 9: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

ExpectationsExpectations

99 9

AttendanceThis is not a correspondence course.

ParticipationQuestions and discussion are what makes the class interesting.

Page 10: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

Administrative Questions?Administrative Questions?

1010 9

Page 11: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

What You’ll Learn TodayWhat You’ll Learn Today

– What is computer science?What is computer science?– What is a computer?What is a computer?– What are hardware and software?What are hardware and software?– How can computers learn new tricks?How can computers learn new tricks?– What is Programming? What is Programming?

1111

Page 12: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

What is Computer Science?What is Computer Science?

1212

Page 13: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

What is CS?What is CS?

The fundamental ideas of CS are:The fundamental ideas of CS are:– AlgorithmsAlgorithms– ProtocolsProtocols– Encoding InformationEncoding Information– AbstractionAbstraction

1313

Page 14: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

Flashlight MessagingFlashlight Messaging

Imagine you are 10 years old, in Imagine you are 10 years old, in 1980...1980...

Your best friend lives next door. Your best friend lives next door. You want to send messages at night.You want to send messages at night.

You each have a flashlight. You each have a flashlight. What do you do?What do you do?

1414

Page 15: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

ABC means 123ABC means 123

13 5 5 20 13 5 5 20

13 5 13 5

1 20 1 20

19 20 1 18 2 21 3 11 1919 20 1 18 2 21 3 11 19

(Meet me at Starbucks)(Meet me at Starbucks)

1515

Page 16: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

Numbered CodeNumbered CodeReplace each character with a number…Replace each character with a number…

Coded Message Example:Coded Message Example:13 5 5 20 13 5 1 20 19 20 1 18 2 21 3 11 1913 5 5 20 13 5 1 20 19 20 1 18 2 21 3 11 19

EncodingEncoding is about converting data into a coded is about converting data into a coded form.form.

DecodingDecoding is about converting from coded to normal is about converting from coded to normal form.form.

1616

Page 17: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

AlgorithmAlgorithm

An An algorithmalgorithm is a is a sequence of clear and sequence of clear and precise step-by-step precise step-by-step instructions for solving instructions for solving a problem in a finite a problem in a finite amount of time.amount of time.

1717

Page 18: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

ProtocolsProtocols

A A protocolprotocol is a set is a set of rules governing of rules governing the exchange or the exchange or transmission of transmission of data between data between devices.devices.

1818

Page 19: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

The Braille Encoding The Braille Encoding SchemeScheme

Each character Each character is up to 6 dots. is up to 6 dots.

Each dot is Each dot is either on or off.either on or off.

Invented by Louis Braille (1809-1852).Invented by Louis Braille (1809-1852).

1919

Page 20: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

What are we looking at?What are we looking at?

2020

Page 21: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

No, No, thisthis is the matrix! is the matrix!

2121

Page 22: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

What is this?What is this?

2222

Page 23: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

2323

Your web browser interprets Your web browser interprets the coded data (1s and 0s) the coded data (1s and 0s) and renders the Facebook and renders the Facebook webpage.webpage.

Page 24: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

AbstractionAbstraction

AbstractionAbstraction is about hiding unnecessary is about hiding unnecessary details and retaining only the relevant details and retaining only the relevant information.information.

Eg. Eg.

““Tie your shoe”Tie your shoe”

““Drive a car”Drive a car”

2424

Page 25: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

Encoding/DecodingEncoding/Decoding

The binary coded data (1s and 0s) is The binary coded data (1s and 0s) is what your web browser interprets as what your web browser interprets as the Facebook webpage. the Facebook webpage.

How?How?

The digital computer is a machine The digital computer is a machine which encodes, processes, and which encodes, processes, and decodes data.decodes data.

2525

Page 26: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

Data and InformationData and Information

Data is a fact pattern:Data is a fact pattern:

Information is how we interpret that Information is how we interpret that pattern:pattern:

2626

Page 27: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

What is a Computer?What is a Computer?

2727 2

What is a computer, anyway?

Give some examples:

A computer takes an input, applies a process, and produces an output.

Page 28: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

What is a Computer?What is a Computer?

2828

Page 29: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

HardwareHardware

2929 3

Page 30: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

SoftwareSoftware

3030 3

Page 31: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

Early History of ComputingEarly History of Computing

3131

Joseph Jacquard (1801) Jacquard’s Loom, the punched card

Page 32: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

Harvard Mark IHarvard Mark I

3232IBM Archives

Page 33: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

First Computer BugFirst Computer Bug

3333

Log of first computer bug, discovered by Grace Hopper, 1945A Computer Science Pioneer, she later wrote the first Compiler.

Page 34: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

ProgrammabilityProgrammability

3434 3

What tricks does your computer do? – Web browsing, email, instant messenger– Play games– Watch movies, organize photos – Word processing, spreadsheets, database

Programmability is the ability to give a general-purpose computer instructions so that it can perform new tasks.

Page 35: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

Programming LanguagesProgramming Languages

A program is a sequence of A program is a sequence of instructions.instructions.Spock: Spock: Computer. This is a Class-A compulsory directive. Computer. This is a Class-A compulsory directive. Compute, to the last digit, the value of pi.Compute, to the last digit, the value of pi.

Computers are not very good at Computers are not very good at understanding natural languagesunderstanding natural languages– Ambiguity and imprecisionAmbiguity and imprecision– Dialects, accents, etcDialects, accents, etc

3535

Page 36: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

Programming LanguagesProgramming Languages

Computer languages are exact and Computer languages are exact and unambiguous.unambiguous.

Programming is the process of encoding our Programming is the process of encoding our ideas for the computer: ideas for the computer: – SyntaxSyntax (form) (form) – SemanticsSemantics (meaning) (meaning)

Popular programming languages:Popular programming languages:– BASIC, C++, Java, Perl, PythonBASIC, C++, Java, Perl, Python

3636

Page 37: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

Machine LanguageMachine Language

Computing hardware performs only a small set of Computing hardware performs only a small set of concrete operations, which are created in circuitry:concrete operations, which are created in circuitry:

load the number from memory location 2001 into the CPUload the number from memory location 2001 into the CPUload the number from memory location 2002 into the CPUload the number from memory location 2002 into the CPUadd the two numbers in the CPUadd the two numbers in the CPUstore the result into location 2003store the result into location 2003

These instructions must be provided to the CPU as These instructions must be provided to the CPU as binary notation (1s and 0s), called machine binary notation (1s and 0s), called machine languagelanguage

3737

Page 38: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

High Level LanguagesHigh Level Languages

Java is a high-level languageJava is a high-level language

c = a + bc = a + b

High level languages are more High level languages are more natural for us to understand, but natural for us to understand, but need to be translated into the need to be translated into the machine language for execution.machine language for execution.

3838

Page 39: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

AliceAlice A modern programming toolA modern programming tool

– 3-D graphics3-D graphics– 3-D models of objects3-D models of objects

AnimationAnimation– Objects can be made to move around the Objects can be made to move around the

virtual world virtual world (a video game or simulation (a video game or simulation implemented in 3-D)implemented in 3-D)

Two kinds of animations:Two kinds of animations:– Movie: Movie: passive user watches the animationpassive user watches the animation

– Interactive: Interactive: active user clicks on mouse, types active user clicks on mouse, types a key on keyboard …a key on keyboard … Actions of user are called Actions of user are called eventsevents

Page 40: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

Getting and Running AliceGetting and Running Alice Alice software is freely distributedAlice software is freely distributed Downloading AliceDownloading Alice

– Go to the website: Go to the website: http://www.alice.org – Click the link Get Alice 2.2Click the link Get Alice 2.2– Click download link specific to your operating Click download link specific to your operating

systemsystem– Save Save Alice.zipAlice.zip (or (or Alice.dmgAlice.dmg) to your PC) to your PC

Installing and running AliceInstalling and running Alice– Extract Alice from Extract Alice from Alice.zipAlice.zip (or (or Alice.dmgAlice.dmg) file) file– Create desktop shortcut (alias) to Alice.exeCreate desktop shortcut (alias) to Alice.exe– Double-click Alice icon to launch Alice applicationDouble-click Alice icon to launch Alice application

4141

Page 41: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

Go through the Go through the tutorials to learn the tutorials to learn the basics of Alicebasics of Alice

4242

The Alice Tutorials (continued)

Page 42: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

AliceAlice

Drag-and-drop based programmingDrag-and-drop based programming– Major advantage: preventing syntax errorsMajor advantage: preventing syntax errors– LimitationsLimitations

Restricted editingRestricted editing Restricted reusingRestricted reusing

– Statement resusable within a method (but not Statement resusable within a method (but not statements)statements)

– Clipboards available for copying and pasting statements Clipboards available for copying and pasting statements between methods of a class (but not all statements)between methods of a class (but not all statements)

– Saving a object (with newly defined methods) as a class Saving a object (with newly defined methods) as a class for using in other worlds for using in other worlds

Objects need to be pre-created (inconv. for Objects need to be pre-created (inconv. for arrays)arrays)

Page 43: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

User StoriesUser Stories ContainContain

– Basic description of what happens when program runsBasic description of what happens when program runs– Nouns in story (Alice, the White Rabbit) correspond to Nouns in story (Alice, the White Rabbit) correspond to

objectsobjects– Verbs correspond to Verbs correspond to actions, responses to messagesactions, responses to messages– Chronological flow describes the sequence of the Chronological flow describes the sequence of the

actionsactions When the program begins, Alice and the White Rabbit are facing When the program begins, Alice and the White Rabbit are facing

each other, Alice on the left and the White Rabbit on the right. each other, Alice on the left and the White Rabbit on the right. Alice turns her head and then greets us. The White Rabbit also Alice turns her head and then greets us. The White Rabbit also turns and then greets us. Alice and the White Rabbit introduce turns and then greets us. Alice and the White Rabbit introduce themselves. Simultaneously, Alice and the White Rabbit say themselves. Simultaneously, Alice and the White Rabbit say “Welcome to our world.”“Welcome to our world.”

Alice in Action with JavaAlice in Action with Java 4444

Page 44: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

User Story and Story BoardUser Story and Story BoardA numbered sequence of objects and actionsA numbered sequence of objects and actions1. Alice turns her head toward the user1. Alice turns her head toward the user

2. Alice greets the user2. Alice greets the user

3. The white rabbit turns toward the user3. The white rabbit turns toward the user

4. The white rabbit greets the user4. The white rabbit greets the user

5. Alice introduces herself5. Alice introduces herself

6. The white rabbit introduces himself6. The white rabbit introduces himself

7. Simultaneously, Alice and the white rabbit say7. Simultaneously, Alice and the white rabbit say

““Welcome to our world.”Welcome to our world.”

Alice in Action with JavaAlice in Action with Java 4545

Page 45: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

Program DesignProgram Design For a given user story For a given user story

– plan scents and shotsplan scents and shots Scene: a piece of the story usually set in one Scene: a piece of the story usually set in one

locationlocation Shot: part of scene told with camera in one Shot: part of scene told with camera in one

positionposition

– Create storyboardsCreate storyboards

Alice in Action with JavaAlice in Action with Java 4646

Page 46: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

Topics in CS120Topics in CS120

Eventful Java (tentative)Eventful Java (tentative)– EventsEvents– Primitive typesPrimitive types– Control StructuresControl Structures– Classes Classes – ArraysArrays– (Animation ?)(Animation ?)

Page 47: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

What You Learned TodayWhat You Learned Today

– Computer Science is…Computer Science is…– A Computer is… A Computer is…

Hardware vs. SoftwareHardware vs. Software ProgrammabilityProgrammability

– Programming LanguagesProgramming Languages Machine language vs. high levelMachine language vs. high level

– Introducing Alice and JavaIntroducing Alice and Java

4848

Page 48: Welcome to CS120 Fall 2012 1 John Magee (jmagee@clarku.edu)

Announcements and To Do Announcements and To Do ListList

– Visit the course web pageVisit the course web page– Download Alice 2.2Download Alice 2.2

Do the tutorialsDo the tutorials

– Readings:Readings: Alice in Action, Chapter 1Alice in Action, Chapter 1

4949