SeaMonkey:MailNews:CodingStyle
Basically, the Mozilla C++ coding style guide rules apply. But our MailNews code has grown evolved over the years and can be rather twisted complex, thus we favour readability over brevity.
JavaScript
In general, use the C++ rules above, but take care of these exceptions:
Default bracing style is "curly braces go on their own line"
To enhance readability, curly braces should be aligned vertically:
if (condition) { let x = 23; CallSomething(x); } else { CallSomethingElse(); }
There are quite some (old) files in our codebase which entirely adhere to the "opening curly braces go at the end of a line" style. If you do changes there, please keep the file's coding style consistent. Mixed coding styles only makes things worse.
If one if branch needs braces, the other should have braces as well
// Fine! if (condition) CallSomething(23); else CallSomethingElse(); // Bad! Don't do this! if (condition) { let x = 23; CallSomething(x); } else CallSomethingElse();
No one-line if contructs
Almost all contemporary debuggers are line debuggers and can't break amidst a line of code:
// Fine! if (condition) return 42; // Bad! Don't do this! if (condition) return 42;
Use let for sub-scope variables
The scope of variables should as small as possible. Using the let keyword, the visibility can be restricted to the current block:
function CallSomething(ax) { var x = 23; // global to CallSomething! if (x < ax) { var y = 42; // global to CallSomething! let z = 666; // local to this if for (let i = 0; i < ax; ++i) // i is local to the for loop CallSomethingElse(i); } }