Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007
Programming Guidlines and Example M1 Solution
General programming guidlines:
Check out this example solution that follows the above principles: Tony-M1.st
- 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.
- Each method should calculate or do only one thing. Methods should be small, a few lines.
- Each class should do or represent only one thing.
- 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).
- You should strive to make your code small and simple (elegant), not just work. Take pride in how your code looks.
- It takes several iterations of changing and refactoring before your code becomes elegant. It is an art.
- 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.
- Why do all this? It makes your code layered and flexible, which will make development easier, more pleasant, with fewer bugs.
- 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).
- 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)
Link to this Page