Skip to content

Unreachable code Error or Warning?

 

In Java, unreachable code is treated as compilation error. What do you think? Isn’t making it warning would have made developers’ life simpler?

Of course you can write –

if( true )
   return;

What if you could simply write return. This helps in testing a function quickly. As a good programming practice we always remove all warnings from code, and such unconditional return statements can be rectified later.

2 Comments

  1. I agree. Not only would this be more useful for coders wishing to test something, but what if you have a program that autogenerates Java code as its output? Now you have to create a special case for this sort of thing, re-engineering the code validator when the compiler could do the job just as well if this were a warning instead of an error.

    Posted on 22-Jul-09 at 4:20 am | Permalink
  2. Yes. C# for example treats unreachable code as just a warning. Sometimes this is simply volitional. I need this right now. The only choice I have is commenting out anything after the return. Unreachable code should definitly be only a warning.

    Posted on 18-Aug-09 at 6:25 pm | Permalink

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-spam image