This website is preserved for historical and scholarly reference and is no longer actively maintained.
Style Standards for Programming Assignments
The purpose of style standards is to make programs more readable by humans.
- Your name must be printed as a comment at the beginning of every file turned in
- Use either 3 or 4 spaces for each indentation. Be consistent. Pick a number and stay with it. Do not use tabs to indent because the printer does not have the same tab spacing as the computer. Use the space bar to indent.
- Every method (function) you write must have a clearly stated postcondition.
- If there is any condition required to execute the method (function), it must be clearly stated as a precondition.
- Every method (function) must begin with a section of comments giving a clear English statement of the algorithm. The algorithm may be omitted only if the method (function) contains fewer than 10 lines of code and the code is self-documenting.
- Every Java statement must begin on a separate line.
- If the condition for execution, such as in a while or if statement can be written in the form "( constant == var )" it may not be written in the form "( var == constant )".
- Any "else" must be followed by a comment giving the condition when the else is executed.
- A comment must immediately follow every while statement, giving the conditiions that are true when the while statement terminates.
- Comments must be included when they will aid the reader in understanding the program. Do not comment the obvious. Do comment the "what" you are doing, but rarely the "how".
- Use meaningful variable names. Do not use the single letter 'o' or the single letter 'l' for variable names.
- Use white space to set off logical ideas.
- If you use code, text, ideas, etc. that are not your own (from text, web, etc.) cite the source.