Jump to content
  • Advertisement
Sign in to follow this  
NEXUSKill

Deprecation fail

This topic is 1935 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement

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

 

 

 

#define __FEATURENAME__ 0

if (__FEATURENAME__)
{
 // somewhat dead code here.
}
 

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites

things get ugly with nested dead code

 

/*
void deadcode()
{
*/
	/*
		deadcode();
	*/

	deadcode();
/*
}
*/
Edited by froop

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 wink.png

 

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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!