Comp 110 – Introduction to Programming

University of North Carolina at Chapel Hill

Ten Commandments of Computer Programming

1. Grow programs little by little The alternative, giving birth to programs, is painful.

2. Test as you grow. If you don't find the bug now, it will take you ten times as long to find it later.

3. List the boundary conditions. Bugs hide in the corners. Until you have found all the corners, you have no hope of the code being correct.

4. Clearly state the contract with the client. If you don't know exactly what it must do, you have no hope of the code being correct.

5. Draw your data structures. If you can't clearly visualize how it works, you have no hope of the code being correct.

6. Create Lego blocks. They are small and simple with an intuitive interface.

7. Minimize accessibility. Make all data members private. If a member function or constant is only used within the class, make it private. Do not use protected unless you have a good reason to do so.

8. Program to interfaces not implementations. Your program will be more flexible.

9. Buy don't build. Know your libraries. The Java Collection Framework is the foundation.

10. Refactor, rewrite, polish. Just because your code gets the correct results doesn't mean that you are done. Coding consists of four steps: Ready, Aim, Fire, Finish. Don't shortchange the last step.