|
Why we need make code clarity?
The primary reason developers should write clean code is so that it can be read and understood easily. If the code is readable, the next person working on the code, including the original author at a later date will be more efficient.
Good style itself doesn't actually affect application performance directly. You can strip code of extra whitespace, and it will recompile fine and run at the same speed as before. In fact, it will compile faster (but not run faster). However, while having a standard filing system makes dealing with paperwork more efficient, using a standard style makes it easier to work with your code. Therefore, you should strive to use a standard style for your application code.
What should we do?
The following short checklist helps ensure that your project submission looks clean and professional:
- Use one statement per line.
- Align related program parts.
- Be consistent with indenting and braces.
- Use enough vertical and horizontal whitespace.
- Don't use the tab character; use spaces instead.
- Comment empty body sections to avoid confusion.
- Use braces even when an if, for, or while loop has just one statement.
- Comments should have the same indenting as code.
- Comments should be spell checked.
- Eliminate obvious comments.
- Use one class per file (inner classes are okay).
- Use one exit from loops and methods.
- Don't repeat code; use a method instead.
- Avoid OS-dependent code, such as path delimiters and absolute paths (use relative paths).
- Don't use identifiers longer than 20 characters.
- Spell out the words in names; do not use abbreviations.
- Use names different enough from one another to avoid confusion.
- Don't differ names by letter case alone.
- Use meaningful names, except for loop increments, for which single-letter names such as i or j are acceptable.
- The names of all instance methods and fields start with a lowercase letter, and subsequent words within the method or field name are capitalized.
- Capitalize class names.
- Package names must be all lowercase letters.
- Boolean method names should begin with is.
- Use nouns when naming classes and variables.
- Use verb phrases for methods.
- Restrict the visibility of variables and other identifiers.
- Use constants (final) instead of variables whenever possible.
- Use meaningful default values.
- Use getXXX() and setXXX() methods for getting/setting field values
Java Tutorial by javaresources.biz
|