| January 2009 |
| Sun |
Mon |
Tue |
Wed |
Thu |
Fri |
Sat |
| |
|
|
|
1 |
2 |
3 |
| 4 |
5 |
6 |
7 |
8 |
9 |
10 |
| 11 |
12 |
13 |
14 |
15 |
16 |
17 |
| 18 |
19 |
20 |
21 |
22 |
23 |
24 |
| 25 |
26 |
27 |
28 |
29 |
30 |
31 |
Sun, 29 Aug 2004
Simple coding tips for junior to intermediate programmers new to objects.
- It's not a big deal to create a new class or method -- especially not a new method.
- Control structures don't appear as often in good OO code as in good procedural good.
- A method can be thought of as a function that retains state across invocations and can be called over and over again without having to re-initialize and pass in every parameter.
- Whenever a chunk of code becomes a good candidate for moving into a function in procedural terms, consider creating a class instead. This is especially true if it appears that the function would take many parameters and be called from many places.
- Whenever it appears that code might benefit from adding a comment, add a new method instead, and move the code that the comment would have applied to into the new method. Name the method something that summarizes the intent of the comment.
- If code is calling a method on another class and then calling a method on the returned value, consider creating a method on the other class that does the work.
Consider this exercise -- take a substantial piece of good procedural
code and turn every function into a class. Not necessarily with the goal
to produce an ideal implementation, but to explore the nature of objects.
permanent link