Don’t touch my braces!
No, it’s not that my pants will fall down if you do, but my Java code might get a bit less intelligible.
Ed Burnette blogs on a nasty little “feature” of Eclipse. First, a little background
Java, C, and C++ share a little syntactic quirk that has bitten all developers on the rear from time to time. Take a look at this code:
if (condition)
doSomething();
doSomethingElse();The “doSomethingElse();” code will always be executed regardless of the value of the condition because only the “doSomething();” statement is considered part of the “if”.
This has bitten me on more than one occasion on source code that has been checked into our repository and edited by multiple people, causing the indentation to get screwed up (eg tabs and spaces). Especially when you’re scanning code you’re not familiar with, indentation is a key indication of code blocks and nesting.
My preference is to always use braces for code blocks, i feel it’s far more consistent. Ed says:
Some programmers find this overly verbose. It wastes a line on your screen, or two lines if you like putting the opening brace on its own line. However I would argue that maintainability and idiot-proofing the code is much more important.
The reason I mention all this is that some IDEs will helpfully offer to remove these “extraneous” braces for you.
This is evil.
Too right it’s evil. Since when has verbosity been a bad thing when it improves maintainability and understanding “at a glance” ?
Much as a dislike the line breaking feature in Eclipse when you use it to format code… I don’t care if my lines are excessively long, I’d rather have a long line that makes sense, than to break the lines in a non-intuitive manner, which Eclipse is wont to do.
So rest assured Ed, when I download my copy of Eclipse 3.2, this feature is well and truly staying off.
February 26th, 2006 at 9:23 am
Man – I don’t remember that “feature” from Eclipse back when I was using it heavily (actually, it was WSAD back then). But that would drive me nuts!
February 27th, 2006 at 11:54 am
apparently that’s because it’s a new “feature” in the eclipse 3.2 stream. Personally, i’d prefer it if they did some more work to improve the performance of the IDE on OS X instead of getting into an arms race with Visual Studio for who can have the most useless bells and whistles
April 4th, 2007 at 5:58 pm
that my pants will fall down if you do
March 4th, 2010 at 1:46 pm
Thanks for this post. It’s very informative and well explained. I’m sure web enthusiasts will be very interested in reading this and will even find it helpful.