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:30] – [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 38: Line 38:
 </code> </code>
  
-Braces must **always** be used, even if the enclosed block contains a single line.+Braces must **always** be used for multi-line conditionals, even if the enclosed block contains a single line.
  
 Bad: Bad:
Line 52: 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 98: 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 123: Line 155:
     return total;     return total;
 } }
-</code> 
-  * Functions should be commented using JSDoc syntax: 
-<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> </code>
   * Semicolons should be used at the end of lines, including after anonymous functions:   * Semicolons should be used at the end of lines, including after anonymous functions:
dev/client_coding/coding_guidelines.1397716237.txt.gz · Last modified: 2014/04/17 02:30 by dstillman