|
Set: Monday 5th October 2009
Due: Monday 12th October 2009 at or before 16:30
|
|
This assignment involves adding some functionality to a class that I'm providing for you: an implementation of "Joe the Box".
Your task is to create a "dance" with two boxes, Alice and Bob. This means that the two boxes should respond to each other's motions. For example, if Alice moves right, Bob might move left; if Alice moves towards Bob, Bob should move towards Alice. I'm deliberately leaving the details of this up to you. The movements of one of the partners could be controlled by workspace commands, or by mouse movements, or by pseudo-random numbers.
Start the dance by sending a message like:
alice danceWith: bob
When you are done, file out your work (using the change sorter, or Monticello, to make sure that you capture all of your work), and send it to me by email.
Pair Programming
As mentioned in class, this work can be very rewarding (and certainly easier) if done in pairs. That said, this is not strictly required. Pairs can be arranged using the mailing list (cs520@cs). If you pair, make sure that both partners get to "drive" (write code), and both partners get to "navigate" (think about where you are going at a higher level).
Submitting
Submit your code by creating a changeset or Monticello package (better) and attaching it to an email sent to cs520-hw. In the mail subject include [CS 520 Assignment 1] and the names of all members of your group. For example:
- Subject: [CS520 Assignment 1] Joe Smith, Karen Chan
Finally, be sure to include instructions for starting and controlling your dance in the class comment of the Box class.
Hints
- To get familiar with using the Smalltalk Environment, I strongly suggest that you work through the first two chapters of Pharo by Example. This works best if you do it with a partner provided that you talk to your partner!
- Some slides that demonstrate the Box class are available here. They also show how to use step and atRandom.
- You may find these Squeak Language and Squeak Classes references useful.
- Other parts of the book that will be useful are chapters 14 and chapter 8. Section 6.3 describes Monticello in more detail than does Section 2.9.
- Use Monticello to write out your code; a side effect will be to create a .mcz file in your package cache. This is the file that you should turn in for your homework assignment.
- Keep a notebook. As you figure stuff out, write it down, so that you don't have to figure it out more than once.
- Code from the class will be placed on SqueakSource. The Box class that I demonstrated can be found by using Monticello to access the http repository at
MCHttpRepository
location: 'http://www.squeaksource.com/PSUCS520'
user: '<your SqueakSource name>'
password: ''
- Here is what we learned the first time I gave this assignment:
1. Don't send email from yahoo.com!
2. Size of Methods <= 7 lines
3. If you have a non-trivial algorithm, explain it. Use Explaining variable names (Beck p. 108) Use Intention-revealing selectors for method names (Beck p. 49) If all else fails, use a comment ! But read Method Comment (Beck p. 40) first. 4. Accessors should not have side effects! 5. Methods should (usually) either DO something or ANSWER a value (other than self), but not both.
This is not a firm rule, but a useful guideline. 6. Follow the directions! 7. Hand in on time. 8. Start the selectors of boolean methods with "is" or "has", e.g., cake isReady, model hasDependents 9. Use class methods when appropriate.
What to Do
-
- Look at the grading rubric so that you know what criteria we will be grading on.
- Start by loading the Box code that I wrote from SqueakSource, using Monticello, or by dropping this file onto your running Pharo image.
- Implement a method dance (which should make the receiver do a solo dance). Try it out.
- Implement danceWith: anotherBox (which makes the receiver dance with anotherBox). danceWith: will require that you add an instance variable to Box, so that a Box can remember its partner.
- Once you have some workspace code that demonstrates Alice and Bob dancing, paste it into the class comment for Box so that someone else can select it and execute it to demonstrate the dance capability.
Don't Panic
I'm aware that I'm throwing you in to the "deep end of the pool" with this assignment. This is because the only way to "get" Squeak is to struggle with it. But you are in a safe environment. There are plenty of life preservers available, in the form of books and web resources, and there are people to help: your classmates and your instructor. I expect that you will get stuck. There will be time in the next class session (Wednesday 7th) for getting you "unstuck". So, come armed with questions.
Also, be aware that there is nothing "golden" about the code that I wrote. It's probably not very good, and it's certainly buggy. I put some hacks in it (overriding the changed method) to redraw the display more frequently than ought to be necessary; if they prove problemetic, you should remove them.
|