When not to use multi-line comments.
I know I haven't posted for quite a while. That's because I'm mostly working and doing homework. :)
But still, a small and useful tip I realized: Prefer not to use the multi-line comment syntax for commenting blocks of code. Only use it for stuff like external method documentation, file documentation, et cetera.
The reason? Who needs reasons? Well, actually, let's look at the following piece of code:
void F()
{
/* Do something here. */
doSomething();
/* Do some more stuff here. */
doOne();
if(shouldDoTwo())
{
doTwo();
}
}
Let's say I wanted to comment out the whole "doOne ... doTwo" part, just for testing something, then I'd have no choice but to use the shift-scroll method and then an editor shortcut to prefix all those lines with "//". That's because any "*/" after an "/*" cancels the first one out (i.e. there is no multi-line comment nesting).So as I've said, it's possible to use editor shortcuts to prefix a bunch of lines with "//", but it's much nicer to use "/*" and "*/" to comment out chunks of code out. But yes, it doesn't make a real difference. Just a matter of preference.
Try
ReplyDelete#if 0
void MyCode()
{
...
}
#endif
to comment out code blocks. This way you don't have to worry about comment blocks.
That's actually a good idea that solves this problem. Thanks for the comment!
ReplyDelete