JavaScript:SpiderMonkey:C Coding Style: Difference between revisions

Line 47: Line 47:
  }
  }


== Program Flow ==
== Control Flow ==
* Keep indentation at a minimum.  
* Minimize indentation using return, break, and continue where appropriate.
** Prefer return statements to cast out abnormal cases, instead of nesting "if/else" statements and indenting the common cases.
 
** Prefer return (break, continue) statements to cast out abnormal cases, instead of nesting "if/else" statements and indenting the common cases.
  void
  void
  MyFunction(int n)
  MyFunction(int n)
Line 64: Line 65:
     ...
     ...
  }
  }
** If an "if" statement contains a return statement, do not use "else".
** If an "if" statement contains a return statement, do not use "else".
  if (condition) {          // bad
  if (condition) {          // bad
Line 76: Line 78:
  }
  }
  DoThat();
  DoThat();
** Avoid similar arbitrary patterns and non-sequiturs:
** Avoid similar arbitrary patterns and non-sequiturs:
  if (condition) {          // bad
  if (condition) {          // bad
Confirmed users, Bureaucrats and Sysops emeriti
419

edits