Style Notes
CSE 143
Table of contents
Formatting
- Include a header comment with your name, section, TA, and brief description of program functionality.
- Use pre/post format.
Pre:
represents parameter specifications and requirements with exceptions noted;Post:
represents method return or output functionality. - No more than 80 characters per line.
Commenting Language
- Say what the method does directly (“calculates a sum” instead of “this method calculates…”).
- Write in a client-oriented manner. Avoid mentioning local variable names, private field names, loops, recursion, etc. - these concern how the program works.
- Explicitly write the inputs (parameters) and outputs (output or return) for a method.
Naming
Variable Type | Formatting | Example |
---|---|---|
Class | Capitalized | ClassName |
Method/Variable | camelCase | className |
Class Constant | UPPER_CASE | CLASS_CONSTANT |
Variable and Field Guidelines
- Fields should always be
private
unless stated otherwise. - Class constants can be
public
. - Avoid static global variables.
- Always declare fields above their constructor, but do not initialize outside of constructor. Instead, initialize fields inside the constructor.
Miscellaneous
- Adhere by Boolean zen.
- Make helper methods private.
References
- Official CSE 143 Java Style Guide
- Unofficial CSE 143 Java Style Guide
- Unofficial CSE 143 Guide to Commenting