Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
dev:client_coding:coding_guidelines [2014/04/17 02:20] – [Additional notes] dstillmandev:client_coding:coding_guidelines [2017/11/27 05:18] (current) – Remove Zotero 5 warning bwiernik
Line 3: Line 3:
 **Note:** Not all current code in Zotero conforms to these guidelines. While existing code generally should not be modified for the sole purpose of conforming, new code or modifications to existing code should follow these guidelines. **Note:** Not all current code in Zotero conforms to these guidelines. While existing code generally should not be modified for the sole purpose of conforming, new code or modifications to existing code should follow these guidelines.
  
-====== Basic style =====+===== Basic style ====
  
   * Indent using tabs (width 4), not spaces   * Indent using tabs (width 4), not spaces
Line 12: Line 12:
  
  
-====== Braces ======+===== Braces =====
  
 Braces should conform to [[http://en.wikipedia.org/wiki/Indent_style#Variant:_1TBS|1TBS variant of the K&R style]]: Braces should conform to [[http://en.wikipedia.org/wiki/Indent_style#Variant:_1TBS|1TBS variant of the K&R style]]:
Line 26: Line 26:
 </code> </code>
  
-Braces must **always** be used, even if the enclosed block contains a single line.+Add a space after keywords to distinguish them from function calls: 
 + 
 +Bad: 
 +<code javascript> 
 +if(foo) { 
 +</code> 
 + 
 +Good: 
 +<code javascript> 
 +if (foo) { 
 +</code> 
 + 
 +Braces must **always** be used for multi-line conditionals, even if the enclosed block contains a single line.
  
 Bad: Bad:
Line 40: Line 52:
 } }
 </code> </code>
- +===== Public/privileged/private/static methods and members =====
- +
-====== Public/privileged/private/static methods and members ======+
  
 //For an explanation of the difference between public, privileged and private methods and members, please see Douglas Crockford's [[http://javascript.crockford.com/private.html|Private Members in JavaScript]].// //For an explanation of the difference between public, privileged and private methods and members, please see Douglas Crockford's [[http://javascript.crockford.com/private.html|Private Members in JavaScript]].//
Line 88: Line 98:
  
  
 +===== Comments =====
  
 +Functions should be commented using JSDoc syntax:
  
-====== Additional notes ======+<code javascript> 
 +/** 
 + * Does something or other 
 + * 
 + * @param {string} value - This is a value 
 + * @param {boolean} [optionalValue] - This is an optional value 
 + * @return {number[]} - Array of itemIDs 
 + */ 
 +function myFunction(value, optionalValue) { 
 +   ... 
 +
 +</code> 
 + 
 + 
 +For readability and neatness, add a space after the slashes in line comments, and capitalize the first word: 
 + 
 +Bad: 
 +<code javascript> 
 +//this is a comment 
 +var foo 'bar'; 
 +</code> 
 + 
 +Good: 
 +<code javascript> 
 +// This is a comment 
 +var foo = 'bar'; 
 +</code> 
 + 
 + 
 + 
 +===== Additional notes =====
  
   * Variables should be defined in the smallest scope possible:   * Variables should be defined in the smallest scope possible:
Line 112: Line 154:
     }     }
     return total;     return total;
-} 
-</code> 
-  * Functions should be commented using JSDoc syntax: 
-<code javascript> 
-/** 
- * Does something or other 
- * 
- * @param {String} value 
- * @param {Boolean} [optionalValue] 
- * @return {Number[]} Array of itemIDs 
- */ 
-function myFunction(value, optionalValue) { 
-   ... 
 } }
 </code> </code>
Line 130: Line 159:
  
 <code javascript> <code javascript>
-var func = function () { +var func = function (bar) { 
-    ...+    var foo = bar;
 }; };
 </code> </code>
dev/client_coding/coding_guidelines.1397715643.txt.gz · Last modified: 2014/04/17 02:20 by dstillman