You are on page 1of 2

PROGRAMMING STYLE

NAMING CONVENTIONS

Classes
o Name should be descriptive
o Capitalize the first and second words (ie TempConverter)
Variables
o Do NOT use generic names (your names should almost represent selfdocumentation) (ie firstName)
o Lowercase the first letter and Capitalize subsequent words
o Do NOT use more than 15 characters
Constants
o Use meaningful names that help with self documentation
o Use ALL_UPPER_CASE for your named constants, separating words with
the underscore character. (ie TAX_RATE rather than taxRate or TAXRATE).
Methods
o Name should describe the meaning of the method
o Use mixed case first letter lowercase and subsequent words Capitalized
(ie calculateIncome)
o Are your methods getting or setting something you may want to prefix
the name with this (ie setIncome)
Parameters
o Use the same naming conventions as you did the above
o These are values that you will be passing into methods; therefore, you
may want to prefix the name with a or an (ie aDeposit)

COMMENTING

Heading comments
o //name of the assignment
o //what the program is to do
o //your name
o //date completed
Segments of code
o Include comments that describe what segments of code are performing
Methods
o //description of what the method does
o //pre-conditions
o //segments of code (as above)
o //post-conditions
Add comments as you goit will make it easier to debug
Always place the comment before the statement

FORMATTING

Using formatting increases the readability of you code


Indentation
o Indent under methods
o Indent under control structures such an if statement and for statement
o Make sure that the lines of code that are indented the same amounts go with
lines at the same indent level
Blank lines and white spaces
o Use blank lines to separate segments of code into chunks
o Use spaces around arithmetic operators, commas, and after semicolons in for
statements
Avoid long lines of code (do not use more than 80 characters)
o Break after a comma.
o Break before an operator.
o Align the new line with the beginning of the expression at the same level on the
previous line.

MISCELLANEOUS

Your input statements must be descriptive (you may use print or println)
Use println to print blank lines to separate input and output on the console (always
check your output with the samples)
You must format your output and have a statement
All programs should include error trapping

You might also like