Programming Style
Programming style refers to the characteristics your program has
as a text document that can be read by humans.
Your overall goal
is to produce a program that is reads well and conveys to another
programmer your structure, strategies, and algorithms clearly.
What constitutes good style?
Here are a few things to do:
- Make sure the code is nicely indented to
give good visual definition to the various blocks of code
(loop bodies, if-then-else blocks, etc.).
-
Declare your variables at the top, and give // comments stating their use.
-
Create named constants (variables with initial values that you never
change) rather than burying numbers in your code for things like loop
limits, conversion factors, etc.
-
Put a large comment (a block comment) at the top of the script
explaining its general purpose. For this class, also make sure
the first items in that block comment are your name, your ONYEN,
and the class identification (COMP 110).
-
Comments should appear
before major loops and code divisions telling what activities are
being done or what quantity is being computed.
-
Variable names should be well chosen so they are informative...
for example "averageDistance" is informative... "ad" or "x" is not.
Loops indices can be single character variables.