Skip to main content

Lightning fast commenting (in and out)

·123 words·1 min
Programming
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

Empty lines and semantics in source code
·536 words·3 mins
Programming
The importance of empty lines for readability and semantics in source code.
Enterprise App now available with Maven
·46 words·1 min
Vaadin UI News
Learn how to add the Enterprise App Vaadin plug-in to your Maven project for Vaadin.
A strategy to manage large SQL tables
·395 words·2 mins
SQL Databases
A detailed approach to handling large SQL tables for report generation.