JavaScript Concern from a recent review

Dave Williss dwilliss at microimages.com
Mon Apr 9 13:55:36 UTC 2007



Gervase Markham wrote:
> Colin Ogilvie wrote:
>> I'm concerned by a recent review Myk did on a JavaScript file (quoted 
>> above) where he says that for one-line conditionals and loop blocks 
>> you should omit braces (as a Nit).
>>
>> I'd like to suggest that this is a bad practice, and possibly going 
>> to cause confusion in the future, particularly in the example above. 
>> For clarity, it would be better written including braces.
>
> I would agree with you, and respectfully disagree with Myk. I don't 
> believe that omitting braces adds to readability. The most it does, 
> given Bugzilla's current coding style, is save a line. And I don't 
> think that advantage outweighs the potential mistakes that can be made 
> in maintenance, and the mental switch required to notice the different 
> syntax in this special case.
Where I work, our code style guidelines actually *require* braces in 
this case.  The only time we don't require them is if the whole thing is 
on one line.  This is for C/C++ code, but it applies to just about any 
language which uses braces.  In fact, if I'm not mistaken, in Perl it's 
actually invalid syntax to omit them. I vote for braces.  Much more 
readable.




More information about the developers mailing list