| 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 |
| | 11 | 1. source code goes in the directory `src` |
| | 12 | 1. 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. |
| | 16 | 1. never use wildcards (*) in import statements |
| | 17 | 1. 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 |
| | 20 | 1. break up a method into smaller pieces if it gets too long |
| | 21 | 1. place one blank line between elements in a file (an element is a field, method, or class) |
| | 22 | 1. one blank line before and after each block of local variables declarations |
| | 23 | 1. apply the Eclipse formatter (Source->Format) to all source files |
| 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) |
| | 27 | 1. do not reveal more than absolutely necessary |
| | 28 | 1. example: typically constructors can be package-private |
| | 29 | * a public factory method is called by outside world |
| | 30 | 1. best to start at most restrictive (private) and only increase visibility if there is no choice |
| | 31 | 1. generally, fields should be private |
| | 32 | * write access methods for those that need to be revealed |
| | 33 | 1. methods declared in (Java) interfaces must be public so don't declare them to be (i.e., leave out the public) |
| 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` |
| | 38 | 1. class and interface names start with uppercase letters and are written in `CamelCase` |
| | 39 | 1. 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};` |
| | 44 | 1. avoid abbreviations in identifiers |
| | 45 | * for example use `expression`, not `expr` |
| | 46 | * use meaningful names for identifiers that explain their purpose |
| 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 |
| | 50 | 1. See [http://www.oracle.com/technetwork/java/javase/documentation/index-137868.html] |
| | 51 | 1. every element (method, field, class, interface, ...) has a javadoc |
| | 52 | 1. 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?'' |
| | 54 | 1. tags |