View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Programming Guidlines and Example M1 Solution

General programming guidlines:
  1. Write high-level English-like code. Feel free to use verbs and nouns/attributes that don't exist yet (in the form of messages sent to self or other objects), then define those methods afterwards.
  2. Each method should calculate or do only one thing. Methods should be small, a few lines.
  3. Each class should do or represent only one thing.
  4. Never copy and paste code. Instead cut out the common code into a helper method (parameterize as necessary), then call that method from the original place and all new places where you were tempted to copy code to. This not only reduces the total amount of code but creates a higher-level vocabulary (the method name of the helper method is now in your vocabulary).
  5. You should strive to make your code small and simple (elegant), not just work. Take pride in how your code looks.
  6. It takes several iterations of changing and refactoring before your code becomes elegant. It is an art.
  7. Clean up your code (change and refactor) while trying to make it work, not afterwards. This activity will automatically get things working or at least make it easier to get things working.
  8. Why do all this? It makes your code layered and flexible, which will make development easier, more pleasant, with fewer bugs.
  9. Comment classes. Follow the Squeak class comment template (which is revealed when clicking ? on a new/uncommented class). Many methods should be straight forward enough that it is "self-commenting" (understandable from the method name and the code and thus not needing a comment).
  10. Reuse existing classes and methods in the system (Simply doing a "find class..." from the system category menu in Squeak and typing in a word your thinking of (like "Face" for the smiley morph) may find candidate classes. Also, you can find candidate selectors (method names) by typing a word anywhere, highlighting it, an hitting Alt-Shift-W)
Check out this example solution that follows the above principles:

Link to this Page