Whereas correct operation of a program is the critical element of
success,
there are other less apparent (but no less important) features that a
program
should include to be considered proper. The following should assist you
when writing programs to determine what to emphasize in your code.
These
guidelines essentially list all points which I feel are crucial to good
programming skills and that all of your forthcoming programs will
include
most, if not all, of these items.
You should consider code that is submitted for assignments as
production code.
Your programs should include the following:
Good comments including the author and date at the top of the
source file. Inline comments
should
include
a heading describing what the program does and a heading for
every
method describing what the method does.
Spaces, tabs, and blank lines. This GREATLY aids readability.
Meaningful variable names and parameter passing.
Properly declaring classes, methods and variables.
Breaking up large programming tasks into separate, logical
classes and
methods.
The following example demonstrates good coding conventions, commets,
and readability (Click on the image to see a larger-sized image appear
in a separate window.)
What NOT to include? Be sure to remove all old, commented-out lines of
code. Consider the following code: (Click on the image to see a
larger-sized image appear
in a separate window.)
The old, commented-out lines of code do not add any functionality to
the code and should be removed from all submitted code assignments.
Many companies and organizations frequently have guidelines for coding
conventions. In particular, Google has posted a style guide
for several languages including Java
and Python
.