235
edits
Changes
Created page with '<div style="color:red">This is just a draft and may change!</div> Basically, the [https://developer.mozilla.org/En/Developer_Guide/Coding_Style Mozilla C++ coding style guide r…'
<div style="color:red">This is just a draft and may change!</div>
Basically, the [https://developer.mozilla.org/En/Developer_Guide/Coding_Style Mozilla C++ coding style guide rules] apply. But our MailNews code has <strike>grown</strike> evolved over the years and can be rather <strike>twisted</strike> 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 <tt>if</tt> 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 <tt>if</tt> 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 <tt>let</tt> 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 <tt>if</tt>
for (let i = 0; i < ax; ++i) // i is local to the for loop
CallSomethingElse(i);
}
}
<div style="text-align: right">''This page is maintained by [mailto:mnyromyr@tprac.de Karsten "Mnyromyr" Düsterloh].''</div>
Basically, the [https://developer.mozilla.org/En/Developer_Guide/Coding_Style Mozilla C++ coding style guide rules] apply. But our MailNews code has <strike>grown</strike> evolved over the years and can be rather <strike>twisted</strike> 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 <tt>if</tt> 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 <tt>if</tt> 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 <tt>let</tt> 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 <tt>if</tt>
for (let i = 0; i < ax; ++i) // i is local to the for loop
CallSomethingElse(i);
}
}
<div style="text-align: right">''This page is maintained by [mailto:mnyromyr@tprac.de Karsten "Mnyromyr" Düsterloh].''</div>