- From an old assignment (a child's arithmetic quiz)
[back]
- Good documentation habits include always explaining
the purpose of variables, and using sensible names that are not too
similar. I like to see pre- and post-conditions in code that I grade.
These exact form of these documentation habits are a matter of style
but you should always provide the same information. (Kernighan &
Pike's The Practice of Programming (Addison-Wesley, 1999)
has another good style.)
[back]
- It is sometimes useful to show the parameters
passed to a function. When you do, also show the names so you
can't accidentally pass them in the wrong order. D'oh!
[back]
- Note the continuation here
[back]
- I prefer to use
{}
s for all
if
statements. That way I can easily insert more
code without forgetting the {
. (This is
especially easy mistake to make if you use macros.)
[back]
- There's no
{
here. That's a
problem waiting to happen.
[back]
- Notice that I always use a
default
case with a switch
. It takes
very little time to code but can save a great deal of time later.
[back]
- Along with a good indentation style (which I
will not discuss here) I find labelling closing braces
that are far away from their corresponding opening braces.
If you type the start and end of functions at the same time
(like you type closing parentheses when you type the opening
ones) then this is easy to do.
[back]
Last updated by J. Blustein on 28 April 2002.
This document is copyright by its author, J. Blustein <jamie@csd.uwo.ca>.