What constitutes good programming?
For those students writing programs for me for classes or for research
projects, I expect high-quality programming. To me, that means writing a
program that is:
- Correct. It must correctly perform the task it is designed to do.
- Robust. It gracefully handles unexpected data or conditions.
For example, you should check the return value of every function call to see if it had an error, and handle it appropriately.
- Efficient. It endeavors to minimize its use of resources
(e.g., disk space, memory, and CPU time).
- Readable. Non-authors of your program should be able to read
the source and understand what has been written. This implies plenty of
comments and whitespace (including indentation). In fact, a reader
should be able to read just the function names and comments to understand
this -- not just the code itself. Functions should be small.
- Modular. Parts of your program should be re-usable by others
-- this means writing generic functions that can apply in many contexts.
It also means avoiding the use of constants since they limit the applicability of code, and decrease its readability and maintainability. If you have to use constants, and we all do, define them as macros in the beginning of your program so that you only have to change the value in one place rather than many.
This list is in no particular order, and likely does not contain all
desirable characteristics -- I'd be interested to hear of others that I
have missed.
This page is part of my advice to Lehigh students.
Last modified: 6 June 2002