Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Jmeter Wiki" for change 
notification.

The "CodeStyleGuidelines" page has been changed by ham1:
https://wiki.apache.org/jmeter/CodeStyleGuidelines?action=diff&rev1=2&rev2=3

Comment:
Added more detail and example code

  
  == Java ==
  
+ === Indentation/White space ===
+ 
   * 4 spaces for indentation
-     * No tabs <!>
+   * No tabs <!>
-  * "Soft" line length of ~80
-     * "Hard" line length of 120
+  * "Soft" maximum line length of ~80 characters
+   * Editors and monitors used by most programmers with good eyes can easily 
handle 120 characters. However:
+    * lines longer than this can be harder to read and frustrating work with
+    * not all programmers have good eyes and/or wide high resolution monitors
+    * in typography line length is recommended to be 
[[http://mikeyanderson.com/optimal_characters_per_line|45-75]] with the optimum 
being 66 or [[http://practicaltypography.com/line-length.html| 45-90]]
+   * Here is an example from `CLUtil.java`
+    * which do you find easier to read?
+ {{{
+             boolean argumentOptional = (flags & 
CLOptionDescriptor.ARGUMENT_OPTIONAL) == CLOptionDescriptor.ARGUMENT_OPTIONAL;
+             boolean argumentRequired = (flags & 
CLOptionDescriptor.ARGUMENT_REQUIRED) == CLOptionDescriptor.ARGUMENT_REQUIRED;
+             boolean twoArgumentsRequired = (flags & 
CLOptionDescriptor.ARGUMENTS_REQUIRED_2) == 
CLOptionDescriptor.ARGUMENTS_REQUIRED_2;
+ }}}
+ or
+ {{{
+             boolean argumentOptional = isFlagSet(flags, ARGUMENT_OPTIONAL);
+             boolean argumentRequired = isFlagSet(flags, ARGUMENT_REQUIRED);
+             boolean twoArgumentsRequired = isFlagSet(flags, 
ARGUMENTS_REQUIRED_2);
+ 
+             private static boolean isFlagSet(int flags, int flag) {
+                 return (flags & flag) == flag;
+             }
+ }}}
+   * "Hard" maximum line length of 120 characters
-       * Except for imports or other places where breaking the line wouldn't 
aid readability
+    * Except for imports or other places where breaking the line wouldn't aid 
readability
+   
+ 
+ === Spacing ===
+ 
   * Spacing between elements on a line e.g.
-    * `if (...`
-    * `while (...`
+    * `if (x || y) {`
+    * `while (true) {`
-    * `methodCall(arg1, arg2)`
+    * `methodCall(arg1, arg2) {`
-    * `"con" + "cat"`
+    * `String s = "con" + "cat";`
-  * Braces are always used with `if`, `else`, `for`, `do` and `while` 
statements, even when the body is empty or only a single statement
+  * Braces are always used with `if`, `else`, `for`, `do` and `while` 
statements, even if the body is empty or only a single statement
+ 
+ === Other ===
   * Import order
+   * TBC
-  * Import spacing 
+  * Import spacing
+   * TBC
-  * No `.*` imports
+  * No wildcard (`.*`) imports
-  * Line length of methods (soft limit of 50?)
+  * Method line length (soft limit of 50)
-  * Line length of classes (soft limit of 500?)
+  * Class line length (soft limit of 500)
  
  === Java 8 Specific ===
  
   * Use of Optional
+   * Return types where null is possible (which aren't performance critical)
   * Default/static methods on Interfaces
-  * Lambdas where possible (max ~5 lines)
+  * Utilise lambdas where possible (max ~5 lines)
+   * If the lambda is >4-5 lines then consider making this a separate method
  
  == See Also ==
  

Reply via email to