CS 40 - Lecture 2

David S. Taylor
Alice

- Learn basic lingo
- Carry out a simple task
- Gain confidence
Dealing with Complexity

- Computers are complex
- more complex than algebra
- less complex than a single-celled organism
- Need to dive in before you understand everything
- Not everyone's favorite learning style
- Set yourself simple task
- Be happy when you succeed
Rules of Engagement
- Work with your buddy
- Pair programming
- List both names in the comment field when working with somebody
- Save file as ObjectHop.a2w (where Object is replaced by
whatever object it is that is hopping, ToasterHop.a2w in my
case). The a2w should automatically be appended by Alice, you don't
need to type it.
- Submit your answers to the Google
Group
- Even if it is no good—no penalty
- Note: others will be able to see your file
- Use ActiveLecture.org to give
feedback
- Too boring? See penultimate slide
Anonymous Poll (No Wrong Answer)
Log in to http://ActiveLecture.org
How Do You Rate Your Computer Skills? (Email, word processing, etc.)
- Excellent (know file system, keyboard shortcuts)
- Good (get everything done without getting frustrated)
- Fair (get stuff done but struggle a lot)
- Poor (often challenged by simple tasks, can't complete tasks)
- Other (please explain)
Your Mission

- Make an object hop around a circle
Learning Step 1: Invoke Methods
- Pick an object and add it to the world
- ...but not the same as your neighbors
- Make it hop once: Right click, select commands to
- move up,
- move sideways,
- move down
What's the Point?
- Learn the system: Where to find stuff, where to click
- Learn the lingo: Objects, methods
- Are we done yet?
- No—doesn't hop around a circle
- Missing: Turns, repetitions
- Missing: Replay
Programming

- Programming = Making replay possible
- Programmer = Movie director
- Program user = Movie watcher
- Most programs can react to user input
Learning Step 2: world.my first method
- Program = sequence of canned steps
- Put step into world.my first method
- Usually start with a Do in order; drag it
- Drag in three toaster moves (but don't use
a toaster)
- Click Play, watch it hop
- Repeat.
- You are a programmer!
Learning Step 3: Responsibilities
- Object-oriented programming: match objects and their
responsibilities
- Should the world make the toaster hop?
- Should the toaster hop itself?
- Create new "hop" method for toaster (use
your object)
- Drag code from world.my first method to
toaster.hop
- What do you put into world.my first method? ←
ActiveLecture.org
Learning Step 4: Loops
- Remember original goal: hop around a circle
- Turn a bit after each hop (try 0.05 revolutions; custom number)
- Hop, turn, hop, turn
- Add these calls to hip to world.my first method
- How many more calls do we need to add to go around the circle?
← ActiveLecture.org
Loops
- Drag Loop into world.my first method
- Drag a hop and turn into the loop; ditch the other
- Play and enjoy
- Did you solve our task?
- What did you learn? ← ActiveLecture.org
Too Boring?

- Make hopping smoother
- Make your object say something
- Vary radius of circle (Hint: Create new variable)
Reminder

- List both names in the comment field when working with somebody
- Save file as ObjectHop.a2w (where Object is replaced by
whatever object it is that is hopping, ToasterHop.a2w in my
case). The a2w should automatically be appended by Alice, you don't
need to type it.
- Submit your answers to the Google
Group
- Get those photos into the Google Group!