Changes between Version 2 and Version 3 of Coding Standards


Ignore:
Timestamp:
01/10/17 17:04:50 (9 years ago)
Author:
siegel
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Coding Standards

    v2 v3  
    22== Coding Standards ==
    33
    4 - General
     4=== General ===
    55
    661. All code should compile without errors or warnings;
    7 2. Eclipse should indicate no warnings.
     71. Eclipse should indicate no warnings.
    88
    9 - Code Structure
     9=== Code Structure and Formatting ===
    1010
    11 1. source code goes in src (under trunk)
    12 2. test code goes in test (under trunk)
    13 3. never use wildcards (*) in import statements
    14 4. a class should do one thing and do that one thing well
    15     - keep them small
    16     - break up into smaller classes if class becomes unwieldy
    17 5. break up a method into smaller pieces if it gets too long
    18 6. place one blank line between elements in a file (an element is a field, method, or class)
    19 7. one blank line before and after each block of  local variables declarations
     111. source code goes in the directory `src`
     121. test code goes in one of the `test` directories:
     13 * `test/regress` : regression tests.  These are short tests that are expected to always pass.   When a developer changes something, she should be able to quickly run the regression tests to determine if the change "broke" anything.  In general, merges into the trunk will be rejected if they break any regression test.
     14 * `test/dev` : development tests.   These are tests for newly discovered defects or for new features under development.   At any time, they will not necessarily all pass.  However, the goal should be to get them to pass.   Once a development test is passing, it should be moved to `test/regress` and becomes a regression test, or to `test/big`.
     15 * `test/big` : these are tests that should pass, but take too long or consume too much memory to be useful as regression tests.
     161. never use wildcards (*) in import statements
     171. a class should do one thing and do that one thing well
     18 * keep them small
     19 * break up into smaller classes if class becomes unwieldy
     201. break up a method into smaller pieces if it gets too long
     211. place one blank line between elements in a file (an element is a field, method, or class)
     221. one blank line before and after each block of  local variables declarations
     231. apply the Eclipse formatter (Source->Format) to all source files
    2024
    21 - Visibility
     25=== Visibility ===
    22261. think carefully about the visibility level for each element, i.e., whether to make the element public (visible to all), protected (visible to package and sub-classes), package-private (visible to package, the default in Java), or private (visible to same class only)
    23 2. do not reveal more than absolutely necessary
    24 3. example: typically constructors can be package-private
    25     - a public factory method is called by outside world
    26 4. best to start at most restrictive (private) and only increase visibility if there is no choice
    27 5. generally, fields should be private
    28     - write access methods for those that need to be revealed
    29 6. methods declared in (Java) interfaces must be public so don't declare them to be (i.e., leave out the public)
     271. do not reveal more than absolutely necessary
     281. example: typically constructors can be package-private
     29 * a public factory method is called by outside world
     301. best to start at most restrictive (private) and only increase visibility if there is no choice
     311. generally, fields should be private
     32  * write access methods for those that need to be revealed
     331. methods declared in (Java) interfaces must be public so don't declare them to be (i.e., leave out the public)
    3034
    31 - Names
     35=== Names ===
    32361. generally, package names are all lower case letters
    33     - exception: IF
    34 2. class and interface names start with uppercase letters and are written in {{{CamelCase}}}
    35 3. method and variable names generally start with lower case letters and are written using {{{camelCase}}}
    36     - exception: "constants" generally all caps:
    37          - {{{public final static int MEM_BOUND = 2060;}}}
    38     - exception: names of enum elements:
    39          - {{{public enum Result {YES, NO, MAYBE};}}}
    40 4. avoid abbreviations in identifiers
    41     - For example "expression", not "expr"
    42     - use meaningful names for identifiers that explain their purpose
     37 * exception: `IF`
     381. class and interface names start with uppercase letters and are written in `CamelCase`
     391. method and variable names generally start with lower case letters and are written using `camelCase`
     40 * exception: "constants" are generally all caps:
     41   - `public final static int MEM_BOUND = 2060;`
     42   - exception: names of enum elements:
     43      - `public enum Result {YES, NO, MAYBE};`
     441. avoid abbreviations in identifiers
     45  * for example  use `expression`, not `expr`
     46  * use meaningful names for identifiers that explain their purpose
    4347
    44 - Documentation
    45 
     48=== Documentation ===
    46491. See [http://docs.oracle.com/javase/7/docs/api/] for good examples of javadocs
    47 2. See [http://www.oracle.com/technetwork/java/javase/documentation/index-137868.html]
    48 3. every element (method, field, class, interface, ...) has a javadoc
    49 4. javadocs should ''explain''
    50     - ask yourself ''would someone who has never seen this code before be able to read this and understand what it does?''
    51 5. tags
     501. See [http://www.oracle.com/technetwork/java/javase/documentation/index-137868.html]
     511. every element (method, field, class, interface, ...) has a javadoc
     521. javadocs should ''explain''
     53 * ask yourself ''would someone who has never seen this code before be able to read this and understand what it does?''
     541. tags
    5255    - which tags occur in javadocs is not nearly as important as the clarity and completeness of the explanation
    5356    - do not include a tag with no information associated to it
    5457    - do include an {{{@author}}} tag for each file
    5558    - do include an {{{@exception}}} tag for each exception (including runtime exceptions) that could be thrown
    56 6. javadocs for interface methods should not reveal implementation details
    57 7. javadocs for methods in a class that implement a method declared in an interface can simply refer to the interface javadoc and add any additional information specific to that implementation; do not copy and paste the interface javadoc
    58 8. method javadocs should list the pre-conditions and post-conditions for the method
     591. javadocs for interface methods should not reveal implementation details
     601. javadocs for methods in a class that implement a method declared in an interface can simply refer to the interface javadoc and add any additional information specific to that implementation; do not copy and paste the interface javadoc
     611. method javadocs should list the pre-conditions and post-conditions for the method
    5962    - a pre-condition is a condition the program state should satisfy when the method is called.  This is typically a condition on the parameters to the method, e.g., {{{N>0}}}.
    6063    - a post-condition is a guarantee: it states a condition the program state must satisfy when the method returns (assuming the method was called in a way that satisfied the pre-condition)
    61 9. packages should have a javadoc in a file {{{package-info.java}}}
     641. packages should have a javadoc in a file {{{package-info.java}}}