JavaScript:SpiderMonkey:C Coding Style: Difference between revisions

Jump to navigation Jump to search
Line 12: Line 12:


== Tabs and Spaces ==
== Tabs and Spaces ==
* Do not add tabs to source files (expand them at 8-space stops if they creep back in).
* Observe the 80-column limit per line, and break down lines that are too long.
* Four spaces of indentation per statement nesting level.
* Four spaces of indentation per statement nesting level.
* Tabs are taken to be eight spaces, and an Emacs magic comment at the top of each file tries to help. If you're using MSVC or similar, you'll want to set tab width to 8, and help convert these files to be space-filled. Do not add hard tabs to source files; do remove them whenever possible.
* "case L:" labels in "switch" statements count as half of a nesting level, so indent two spaces, with the labeled statements indenting two more for a standard four spaces indentation from "switch" to a case-controlled statement.
* Observe the 80-column limit per line, and break down lines that are too long.
switch (discriminant) {
  case L1:
    DoSomething();
  . . .
}
* Exception: for switches with every case labeling a trivially-short statement it's ok to put the case, the statement, and the break; all on one line.
* Comment /* FALL THROUGH */ in place of missing break when intentionally falling through from one case-controlled statement sequence into another, or into the default statements.
* Do not use spaces between a function name and its arguments list,                                                or between an array name and the square bracket. Also, do no use spaces after a bracket. Use a space after a comma to separate arguments.
* Do not use spaces between a function name and its arguments list,                                                or between an array name and the square bracket. Also, do no use spaces after a bracket. Use a space after a comma to separate arguments.
  JS_SetContext ( rt, cx ); // bad
  JS_SetContext ( rt, cx ); // bad
Confirmed users, Bureaucrats and Sysops emeriti
419

edits

Navigation menu