Skip to main content

Lightning fast commenting (in and out)

·123 words·1 min
Alejandro Duarte
Author
Alejandro Duarte
Alejandro Duarte is a Software Engineer, published author, and Developer Relations Engineer at MariaDB. He has been programming computers since the mid-90s. Starting with BASIC, Alejandro transitioned to C, C++, and Java during his academic years at the National University of Colombia. He relocated first to the UK and then to Finland to foster his involvement in the open-source industry. Alejandro is a recognized figure in Java and MariaDB circles.

I have used this two or three times in my life but it’s one of those simple (and useful?) hard to forget tricks. It could be useful during tough debugging times.

If you have several lines of code and you want to comment them out, you can use standard multi-line comments (this is for C++, Java, and others):

/*
Component contentArea = getContentArea();
layout.addComponent(contentArea);
layout.setExpandRatio(contentArea, 1);
*/

Notice that you can also “comment out” the first and last lines using single-line comments:

//*
Component contentArea = getContentArea();
layout.addComponent(contentArea);
layout.setExpandRatio(contentArea, 1);
//*/

Now you can comment in and out your code just by removing or typing the first “/”:

CAUTION: Avoid usage in programmers with chronic lava flow disease, including junior and senior developers.

Enjoyed this post? I can help your team implement similar solutions—contact me to learn more.

Related