# Deprecation fail

## Recommended Posts

Was the code originally a while loop?

Edited by Josh Klint

##### Share on other sites

That's not too uncommon in big code bases.  Using an if instead of a while is more frequent.

#define __FEATURENAME__ 0

if (__FEATURENAME__)
{
}


There are several benefits to this.

The most immediate and obvious benefit is in cross-platform code or multi-build code.  If you use the #if preprocessor directive it is easy for a programmer to mess up stuff inside an #if/#endif block that happens to not compile on their system.  In this case the compiler will still build the code and run all the syntax checks and such.

Another benefit is that while debugging, a programmer can step into the "dead" loop in debug builds.  In that case you probably want to mark it with a descriptive name such as DEBUG_ONLY_TEST_SOME_FEATURE, but leaving the code in place makes it mostly dead but still partially alive.

Now on the other hand, if the code really is dead and has no use, nuke it from orbit.  If you need it later you can use version control to recover it.

##### Share on other sites

Granted, the code didn't actually get executed and the compiler likely did away with the whole loop, but it was still blasphemous.

Yep, it probably isn't even present in the executable. The main advantage of removing code this way is that the compiler still has to check its syntax is valid which can help keeping it usable if you ever need it back. Of course, chances are by the time you go back to the code the program behavior changed so much that the old code isn't useful anymore anyway =P

##### Share on other sites

Was the code originally a while loop?

No, the while was added as a sort of /**/ block comment.
Personally I believe dead code like this should be outright deleted, especially if you have some subversion system in place, having to browse through dead code and in this case even maintain it is a huge waste of time in production.

##### Share on other sites

things get ugly with nested dead code

/*
{
*/
/*
*/

/*
}
*/

Edited by froop

##### Share on other sites

some of this is an area where nestable block-comments would be useful sometimes.

granted, there is always #if 0 ... #endif, but still...

##### Share on other sites

things get ugly with nested dead code

Yea, I wish C++ allowed: /*** /** /*    */ **/ ***/, and so on. Sometimes I use /* */ for multiline comments (that's what it's for, after all) and trying to comment out several functions means I need to go and add a space after the stars: /* / * * / */

##### Share on other sites

things get ugly with nested dead code

Yea, I wish C++ allowed: /*** /** /*    */ **/ ***/, and so on. Sometimes I use /* */ for multiline comments (that's what it's for, after all) and trying to comment out several functions means I need to go and add a space after the stars: /* / * * / */

or, possibly alternate syntax:

/[[ ... ]]/

which could be nestable, and shouldn't likely interfere with any other valid constructions (and wouldn't break on documentation-comments for Doxygen or similar).

if I could have a wish-list, I might also add:

endianess specifiers for struct members;

triple-quoted strings or similar;

...

##### Share on other sites

granted, there is always #if 0 ... #endif, but still...

I like #if 0. I have my editor setup to identify such "frozen code" blocks and highlight them in a different color (generally light gray or light blue, different from comments). I find it handy to temporarily remove large blocks of code for debugging or prototyping. I never leave this stuff after, though, it just looks ugly and confusing.

Sure, it could probably be argued that it's not using the preprocessor for its intended usage, but what the hell, it's an idiom now so who cares

I wouldn't mind a clean nested comment feature for C++, though. It should probably nest by default, anyway. What was the reason for not allowing /* /* */ */? Harder/impossible to parse or something? I doubt it so there must be some other explanation.

##### Share on other sites

granted, there is always #if 0 ... #endif, but still...

I like #if 0. I have my editor setup to identify such "frozen code" blocks and highlight them in a different color (generally light gray or light blue, different from comments). I find it handy to temporarily remove large blocks of code for debugging or prototyping. I never leave this stuff after, though, it just looks ugly and confusing.

Sure, it could probably be argued that it's not using the preprocessor for its intended usage, but what the hell, it's an idiom now so who cares

I wouldn't mind a clean nested comment feature for C++, though. It should probably nest by default, anyway. What was the reason for not allowing /* /* */ */? Harder/impossible to parse or something? I doubt it so there must be some other explanation.

in my language they do nest.

however, this can't be as-easily added to existing languages mostly as there is a risk of it breaking existing code (which may depend on the non-nesting behavior of these comments).

(decided to leave out a rant about the tendency of people to retain problematic edge-case behaviors in new languages with C-like syntax... even though a new language doesn't necessarily have piles of legacy code to maintain, and the new language will probably break stuff in other areas anyways, so some obscure edge-case behaviors are probably better off fixed as they are probably more often stumbled on by accident than by intention...).

Edited by cr88192

##### Share on other sites

Remember when C was made and it isn't hard to understand why. Basically when the preprocessor finds /* it keeps skipping characters until it finds a */ sequence, without doing anything else. I guess implementing nesting wouldn't have been hard (it's just a counter!), but that's what they decided to go with.

however, this can't be as-easily added to existing languages mostly as there is a risk of it breaking existing code (which may depend on the non-nesting behavior of these comments).

For the record, several old C compilers actually would parse comments like they could be nested. I know Borland C used to do this.

##### Share on other sites

A GCC extension would be nice.

##### Share on other sites

There could actually be a valid reason for putting the while(0) around it rather than commenting it out.

It avoids the situation where some later maintanence or refactoring caused the commented out code to not compile. That can help for when it starts getting used again.

Edited by iMalc

##### Share on other sites

things get ugly with nested dead code

Yea, I wish C++ allowed: /*** /** /*    */ **/ ***/, and so on. Sometimes I use /* */ for multiline comments (that's what it's for, after all) and trying to comment out several functions means I need to go and add a space after the stars: /* / * * / */

That would likely break things like Doxygen, where comment blocks beginning with /** are parsed to generate documentation.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628320
• Total Posts
2982057

• 12
• 9
• 9
• 13
• 11