Art of code comment

Summary

The article presents two creative, albeit unconventional, code commenting techniques primarily for debugging, strongly advising against their use in production environments. One method, dubbed "if else style," demonstrates how to use nested block comments to conditionally execute specific code paths, effectively allowing developers to toggle between different implementations. Another technique, "Block comment," illustrates variations of block comments like `/**/` to quickly enable or disable sections of code. While these offer interesting ways to manage code during development, modern IDEs provide more streamlined and safer shortcut keys for commenting.

Note : This post is just for fun. Please be careful about these tricks.

Code comment is to provide complementary comment to abstract codes. We will introduce two comment styles while we are debugging our codes. we should avoid these styles in production codes.

1. if else style

Only execute eatKfc()

//*                     
eatKfc();
/*/                     
eatMcdonalds();        
//*/

Only execute eatMcdonalds()

/*
eatKfc();
/*/
eatMcdonalds();
//*/

Execute both

//*
eatKfc();
//*/
eatMcdonalds();
//*/

2. Block comment

Don't comment

/**/
var foo = function() {
    ...
};
/**/

Block comment 1

/** /
var foo = function() {
    ...
};
/**/

Block comment 2

/**
var foo = function() {
    ...
};
/**/

These are old age comment styles. Now the advanced IDEs support shortcut keys for commenting some codes.

Source : http://segmentfault.com/a/1190000000265197

STYLE COMMENT

  RELATED

  COMMENTS

0

No comment for this article.