Java Reference
In-Depth Information
9.8
Summary of coding standards
Instead of listing a template of antipatterns, we'll provide a summary of the
coding standards described in this chapter. The best way to use this informa-
tion is to cross out those guidelines that are not important or compatible with
the goals of your team, and then add any you like from one of the references
in the bibliography or from the style guide in the previous section.
Guidelines for names
For fields and attributes, use descriptive nouns with restrictive adjectives
where appropriate.
Use a descriptive test prefix for Booleans, like is , contains , or has .
Make collection names plural for clarification.
For methods, use descriptive verbs with restrictive nouns indicating tar-
gets where appropriate.
Name accessors with get and set , followed by the field names.
Name Boolean accessors with a descriptive test, like is , has , or contains .
Exception: Single letters are acceptable for loop counters, for the econ-
omy of space, where readability remains clear.
Use camel case to distinguish between words. Capitalize the first letter
of acronyms.
Capitalize the first letters of classes and interfaces, but not methods,
variables, or attributes.
Guidelines for attribute name/automatic variable name collisions
Use a leading or trailing _ for all attributes, or
Precede all attribute references with this, or
Access attributes solely through accessors, or
Disallow the same attribute names in the method body.
Guidelines for braces
Enclose such statements as if , while , or for within open and closed
curly braces even if the body is a single line.
Choose a style and be consistent.
Search WWH ::




Custom Search