Code Specifications

Good code is like a finely-crafted part of a machine. It is no more complex than it needs to be, it is interchangeable with other parts, and it is easy to maintain. The following standards come out of several years of teaching and grading. Following them religiously helps me to manage and test 20 different versions of the same program, and makes it much less likely that I will lose your file. (It also makes it easier for me to get your programs back to you sooner.) Any deviation from these standards can result in a lower grade.

General

Java-Specific

For Java, please follow these specific points:

Style

Of course, style will vary from language to language. However, some principles are constant:

  • Comment your code. Every function/method should have its own comment (though a group of related one-line functions may share a comment). In addition, there should be regular comments in the body of your code.
  • Use proper documentation comments. In Java, this means using Javadoc comments for every public method and class. In Python, this means defining the proper """ doc string within every public method and class. Other languages will have equivalents.
  • Name functions and variables properly. Function names should be verbs. Variable names should be nouns. Don’t use single-letter names unless the variable is an index, or there is a specific, special reason.
  • Skip lines. This will help your eyes pick out related blocks of code. Rule of thumb: comment line, 5 lines of code, skipped line. And skip a line between functions, excepting related one-line functions.
  • Maintain correct tabbing. Being careful about your program’s tabbing will help you find many bugs before they become problems.