MooTools code style (which is by no means any sort of standard other than
with the moo-devs) says that any if/else block that can be expressed in
single lines should be, that any if or else that requires more than one
line (including a line wrap) means both use curly braces, that there is no
space between ){
Examples:
if (foo) foo();
else bar();
if (foo){
foo();
} else {
this.statement();
takes.twoLines();
}
this would not be considered valid mootools style:
if (foo) foo();
else {
this.statement();
takes.twoLines();
}
It's also not frowned upon to use braces for one line statements where it
would help make the intent more clear.
I'll also note that in recent releases this kind of block started showing
up:
if (enumerables) for (var i = enumerables.length; i--;){
k = enumerables[i];
if (a.hasOwnProperty(k)) self.call(this, k, a[k]);
}
I.e. the if/for are on the same line.
On Thu, Mar 29, 2012 at 4:39 PM, Sanford Whiteman <[email protected]>wrote:
> One Style To Rule Them All (tm)... age-old problem, n'eh?
>
> I'm hardly the one to dictate, because I use the ternary operator more
> often than sane people do. I find it easy to read, but YMMV.
>
> The general (don't quote me) consensus as to using curly braces is to
> use them all the time, because that makes your code more maintainable
> as you insert new lines. Then again, some very "pro" code leaves them
> off for single-line statements -- but whether that code went through I
> preprocessor I couldn't tell you.
>
> -- S.
>
>