Lazy Block Comment Trick
If you like using block comments then you might like this little time saver to toggle block comments much more lazily. The lazy block comment syntax uses /*
and //*/
instead of the conventional /*
and */
. I have not seen this syntax anywhere else but I’ve been using it for years. Here is how it looks in code:
$id = get_user_id(); $age = get_user_age($id); /* debug_output($id); debug_output($age); var_dump(get_user_data($id)); //*/ $data = get_user_data($id);
To uncomment the entire block just add an extra /
to the opening comment, essentially commenting out the opening block comment by converting it into an inline comment. This makes it very easy to toggle the entire comment block:
$id = get_user_id(); $age = get_user_age($id); //* debug_output($id); debug_output($age); var_dump(get_user_data($id)); //*/ $data = get_user_data($id);
The whole block is now uncommented because the starting and ending block comments are themselves commented out using the inline comment syntax //
.
From now on when you consider block comments, remember the lazy syntax: /*
and //*/
to comment. //*
and //*/
to uncomment.
[…] to Aleem Bawany for the second trick (he uses //*/ as the closing comment, which works pretty much the same […]
[…] to Aleem Bawany for the second trick (he uses //*/ as the closing comment, which works […]
Yup, that is useful tip to have around 😉
You did by no means invent this or the term “Lazy Block Comment” and I would appreciate if you would stopping adding this link into my Stack Overflow answer. A meta discussion (http://meta.stackoverflow.com/questions/50039) has deemed it unacceptable behavior.
I’m writing this as a comment to your blog post because I have no real way of replying to you on the official stack overflow system, feel free to delete this after you have read it.
Thank you.
I dubbed the technique “Lazy Block Comments” and I challenge you to find any prior citations of this technique.
As surely as I am writing this email to you, I wrote out this blog post and came up with the name “Lazy Block Comments” which you referred to verbatim in your post on SO. If you want to have integrity then I suggest you cite your sources instead of passing it off as your own.
I wasn’t ripping you off and passing it off as my own. I certainly haven’t read your blog before you posted the link. Lazy is just the best word used to describe a special block comment, it’s not very unique or special, just a description of what lots of people have evidently discovered.
I’m sure many would use to word “lazy” to describe the programing practice, I think it’s naive to take credit for being the “first” person to use such a common adjective.
Many could but no one did. The idea is trivial but you clearly cited this blog post but are adamant that you came up with it or all citations to this post should be removed everywhere. It’s just petty. Google up “lazy block comment” and let me know what you find.
With all due respect, that trick is applicable in all languages with c++ style comments, it probably exists for over 20 years. I’ve seen and used it many times, and I think most developers can come up with that.
Obviously, you wouldn’t see too many of these in final code, most commented code gets deleted before it is released, and even after a specific bug was fixed.
Now, just for the challenge, I found this one quite quickly, from 2007, and I’m sure there are more: http://forums.xkcd.com/viewtopic.php?f=3&t=4029
Anyway, happy coding
:)
Absolutely agree with you. Block comments are simple enough that I am sure hundreds have stumbled across the same but it was after this post that “Lazy block comments” came into use and you can see it cited on other blogs because the idea has a name which improves transferability. If you Google the phrase there are no other citations. @Sam152 got it from this post or from a post that got it from this post. Personally I don’t care much either way, but he went out of this way to debunk this post despite borrowing the same terminology and I am compelled to respond.
Design patterns have existed for a long time but the attribution and naming of these patterns is what brings them into common use (read Head First Design Patterns for excellent commentary on this). A good example is XMLHttpRequest which was tucked away and hidden until AJAX.
May not matter much but it is what it is.
[…] just have to change the slashes in /* and the content is comment out. I got this tip from Aleem Bawany; he explains it thoroughly in his […]
[…] just have to change the slashes in /* and the content is comment out. I got this tip from Aleem Bawany; he explains it thoroughly in his […]