JavaScript:SpiderMonkey:C++ Coding Style: Difference between revisions

Jump to navigation Jump to search
Add info about conditionals.
m (→‎Classical OOP: Four space softtab consistency in examples.)
(Add info about conditionals.)
Line 6: Line 6:


C++ is powerful, with many degrees of freedom and some attractive nuisances. We should aspire to use it in a lean, close-to-the-metal fashion, and avoid style-over-substance [http://www.bikeshed.com/ bikeshedding].
C++ is powerful, with many degrees of freedom and some attractive nuisances. We should aspire to use it in a lean, close-to-the-metal fashion, and avoid style-over-substance [http://www.bikeshed.com/ bikeshedding].
== Conditionals ==
The following style is used for bracing conditionals:
If the consequent (and, if present, the alternate) is a single statement, no braces are used.
if (today == "Tuesday")
    puts("I don't have my wallet on me.");
else
    puts("I would gladly pay you on Tuesday for a hamburger today.");
However, if ''either'' the consequent or alternate is a block of multiple statements, braces are used on both.
if (canSwingFromWeb) {
    p->swingFromWeb();
} else {
    JS_ASSERT(p->isSpiderPig());
    p->doWhateverSpiderPigDoes();
}


== Namespaces ==
== Namespaces ==
29

edits

Navigation menu