This is just a quick trick I have used. Specially in long SQL
scripts.
The idea is mixing single and multiline comments for easier handling.
SQL Basics
-
--
Single line comment. -
/*
Multiline comment opening. -
*/
Multiline comment closing.
Mixing
Take this simple SQL operation.
SELECT * FROM users;
Now let's use both single and multiline comments.
--/*
SELECT * FROM users;
--*/
The operation will be the same, but if we delete the single line comment --
before the multiline opening /*
, then the operation will be commented out. The --*/
will be interpreted as the end of the multiline comment if multiline is enabled or just a regular comment otherwise, so we do not need to touch it.
This have the following advantage, just need to delete or add the single line --
once, and a whole block of code will be (un)commented out.
Multiline Enabled
/*
SELECT * FROM users;
--*/
Other Programming Languages
This technique can be used in any programming language that supports single and multiline comments.
<?php
// /*
echo "Hello";
// */
my_not_commented_out_function();
<?php
/*
echo "Hello";
// */
my_not_commented_out_function();
Top comments (2)
Yeah, I do this since decades 🤓 nice to see it in the wild.
For
/
,/*
comments you can save a key stroke:I've always called that a scissor comment, but nobody understood what I meant 😅
Thanks! Nice catch too 🔥