Is your IDE *too* helpful?

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)

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)

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

    if (condition) {

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".


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:


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.

Topic: Software Development

Ed Burnette

About Ed Burnette

Ed Burnette is a software industry veteran with more than 25 years of experience as a programmer, author, and speaker. He has written numerous technical articles and books, most recently "Hello, Android: Introducing Google's Mobile Development Platform" from the Pragmatic Programmers.

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


Log in or register to join the discussion
  • Me.FarFetched= True

    in my opinion 8~O
  • Overstating the problem

    I think you're overstating the scope of the problem, after all it's a fairly isolated case (how often does this really happen?) and the IDE *does* provide a helpful means of detection in the form of automated formatting. Highlight the problem method and hit <CTRL>-<SHIFT>-F. When you let Eclipse reformat the code, the problem becomes immediately obvious. As you pointed out earlier, whitespace is insignicicant to the compiler and it's also insignificant to the re-formatter.

    This is just a question of style. Just as it's questionable practice to have short acronyms for variable names it's also questionable to have one line if branches, however under the right circumstances both of these things can make code *more compact and more readable*. Saying "never check this box" seems a bit overly dramatic to me. Never say never.

  • Language problem -- not IDE

    Java syntax was created in the C language, by non-typing mathematicians at Bell Labs in 1969 and it shows it. There's barely a dime's worth of difference between C, C++, and Java syntax -- they are all not so much fragile as -- hmmmm -- squirrelly.

    If you make a simple mistake, the compiler will just assume you knew what you were doing.

    Don't blame the IDE. The sort of syntax in which you can have subtly misplaced braces compile correctly and run is a no-win situation.
    • Got any better ideas?

      What language can you think of that doesn't have similar issues?
      Ed Burnette
      • He touched on it....

        Python and Ruby are two languages that come to mind as being largely immune from C/C++/C#/Java false economies. Performance? Search Google - not 'use Google to search for...' :-P

        I'm relearning both languages now after having not touched Python for a good five years (I have 27 years of C experience, 20 with C++ and 5 with Java) - and the productivity differences are truly amazing.

        To paraphrase the classic Windows/Macintosh comparison: Java lets you talk about everything you had to do to get your work done; Python lets you talk about all the great work you got done.