When this topic first appeared, I figured it would be wise for a C developer like myself to stay out of any possible ensuing religious wars on software conventions. However, after a few days I realized I didn’t have to join in the religious wars – I discovered that Alyoshapresented many arguments I agree with. Obviously, Alyosha
I share many similar beliefs on coding convention organization, including pragmatic function size :
"And though I may be in the minority, I both agree disagree with your above statements concepts.
As I stated above, "my rule is that a function should be as short as atomically reasonable – even if that means 2-5 lines for some functions or 10s/100s lines for others.
Each function should do what it requires with few if zero side effects. Whether a function requires two lines of code or 1000, functions should NOT be arbitrarily short JUST for the sake of a cliche."
– http://discuss.joelonsoftware.com/default.asp?design.4.202810.13#discussTopic203616
“Steve, meet #if 0. #if 0, meet Steve.”
Although I have certainly used #if 0, the advantage of this:
/*
…some code to comment out
*/
versus this:
#if 0
…some code to comment out
#endif
is in terms of visualization. Most of the editors I have used can easily color code the comment block.
Not so much with the #if 0 … #endif block.
Makes it far easier to clean up after you’re done, though …
– Steve Bush
I personally was trained to use the “#if 0/#endif” method for software maintenance reasons. So naturally I found Alyosha`s “meet Mr. #if 0” comment very funny.
However, Steve Bush correctly points out the primary advantage for using the “/* */” method is for IDE comment-coloring visualization. He also correctly points out one important advantage for using the “#if 0/#endif” method – it is “far easier to clean up”, i.e. enable/disable desired code blocks from compilation.
However, he fails to address the parallel problem using the “/* /" method. That is, it is often difficult to enable/disable code using "/ /" if the code block(s) themselves contain "/ */” comments. This is because ANSI C does NOT allow nested comment blocks. Even a careful developer could easily intend to comment out a code block but not realize that only some lines of the code block were commented out while some trailing lines are NOT commented out because of a nested comment block.
In fact, MISRA (Motor Industry Software Reliability Association) similar FAA FDA standards prohibit enabling/disabling code blocks using “/* */” for this very reason :
“Where it is required for sections of source code not to be compiled then this should be achieved by use of conditional compilation (e.g. #if or #ifdef constructs with a comment). Using start and end comment markers for this purpose is dangerous because C does not support nested comments, and any comments already existing in the section of code would change the effect.”
– MISRA-C 2004 Rule 2.4