Next: Layout and indentation Up: Some advice on style Previous: A general principle

On arbitrariness and consistency

In many ways the styles that one adopts in programming are arbitrary - there must be many acceptable schemes. However, two points need to be taken into consideration:

We should conclude that we ought to adopt conventional approaches wherever possible. Most organizations producing software have "house rules" concerning program presentation styles. Some organizations have more rigid house rules, and some have more flexible rules, but some conventions are near-universal, and programming text books usually adopt styles that are typical of professional practice..

In all circumstances, whether we are following conventions or are exercising our individual freedom, consistency is very important. For example, if you decide that identifiers consisting of multiple words should have underscores between the words (eg: no_of_cars), or that loop bodies should be indented by 3 spaces, then you should be scrupulous in the matter.

This applies in program design itself as well; for example, if you program a certain kind of task in one part of a program using a particular algorithm, then you should use the same algorithm at each place that that kind of task has to be performed. If things look similar when they are similar then the reader can transfer understanding from one place to another much more easily.

Email: Dr Simon B Jones