The best code reads like a human language. It’s tough to make the entire source code read that way, but for small snippets, having appropriate variable and function names is a boon to writing clear code.
For example, the following expression is a favorite:
while(!done)
You can read this statement as “while not done.” It makes sense. Until the value of the done
variable is TRUE, the loop spins. But somewhere inside the loop, when the exit condition is met, the value of done
is set equal to TRUE and the loop stops. It’s lucid.
It also helps to offer descriptive names to your C functions. A name such as setringervolume() is great, but the name set_ringer_volume() is better. It also helps to consider the function in context. For example:
ch=read_next_character();
In the preceding line, the function read_next_character() needs no explanation — unless it doesn’t actually return the next character.