Monday, March 5, 2012

Principles of Programming

Principles of Programming

1. Model everything in the user domain and the programming domain as an object. It provides a useful paradigm for program organization, remembering what each part does, and conceptual chunking.
2. Always use constants and enumerations.
3. Create unit tests to guide development.
4. Create print method for each class.
5. Create standard exception handling method.
a. Easy at highest level to capture all exceptions.
b. Exceptions themselves should contain information on how to handle themselves.
c. Handlers can decide how to handle exception, i.e. output to stdout, logfile, abort, or html error message.
6. Document (almost) every class and method – except for functions whose description can be determined by convention, i.e. getter/setter.
7. Document even functions that seem redundant with their name, just to show that they actually do what their name implies.
8. Learn how to use the source level debugger and the IDE and other programming tools.
9. Keep a log of what you are doing – hardcopy, in a notebook.
10. Make system with minimal features for each stage of development.
11. Make system extendible for future stages of development.
12. Write install document as you do development, so that you remember to write down what is needed to get going in the environment. Later when you are expert you may make too many assumptions.
13. No global variables for the program. Some may be used for testing or runtime environment, to save typing.
14. If you need global variables, you really need an “application” class. Imagine that you have 2 instances of the application running in another module – will it work?
15. Let the app class know about everything (i.e. root of a tree of information that encompasses the program) and let everything know about the app tree (directly or indirectly, through it’s parents/ancestors).
16. (to be continued)