Is your IDE *too* helpful?

Summary:One side-effect of IDE competition is that each team tries to outdo each other at every revision. Usually this is good, but sometimes... I'm not so sure. Consider this example.

One side-effect of IDE competition is that each team tries to outdo each other at every revision. Usually this is good, but sometimes... I'm not so sure. Consider this example.

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". With a few exceptions like Python, most languages do not treat whitespace as significant. But our eyes do, and we can get confused.

Now this could happen due to a space vs. tab problem, or maybe a cut-n-paste error. But whatever the reason, the meaning is clearer with the proper indentation, i.e.,

    if (condition)
        doSomething();
    doSomethingElse();

However you can make it even clearer by adding braces, like this:

    if (condition) {
        doSomething();
    }
    doSomethingElse();

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.

Here's a screenshot of the cleanup wizard that comes with JDT in Eclipse 3.2M5. Note the option for "No block for single statements".

 

cleanupwizard.png

Do not under any circumstances turn on that option.

The new Eclipse also provides a helpful "quick fix" option to get rid of your extra braces for you:

 

quickfix3.png

There's such a thing as giving developers a little too much rope with which to hang themselves, and I think this is a good example. IDEs should encourage best practices, not provide an option for every possible thing under the sun.

What do you think, have you ever had your IDE be a little too "helpful"?

Update 2/22: Here's a real world example of how omitting braces can cause bugs. It just came up on a open source development list I read.


Topics: Software Development

About

Ed Burnette has been hooked on computers ever since he laid eyes on a TRS-80 in the local Radio Shack. Since graduating from NC State University he has programmed everything from serial device drivers and debuggers to web servers. After a delightful break working on commercial video games, Ed reluctantly returned to business software. He... Full Bio

zdnet_core.socialButton.googleLabel Contact Disclosure

Kick off your day with ZDNet's daily email newsletter. It's the freshest tech news and opinion, served hot. Get it.

Related Stories

The best of ZDNet, delivered

You have been successfully signed up. To sign up for more newsletters or to manage your account, visit the Newsletter Subscription Center.
Subscription failed.