DEV Community

Discussion on: 6 ways minimalism can help you write clean code

Collapse
 
xwero profile image
david duymelinck • Edited

Commented code is a thing from the time before version control solutions.
I stopped doing it when i started using subversion.
But there are codebases I inherit from other developers. Most of the time I just remove it when I start working with the code in one commit.

There are rare occasions where commented code is a convenience. In those cases I add the comment tag KEEP_CODE followed by the date. I do a periodical check for this tag and get a report for code that is older than a month. That is my expiry date for commented code.

Collapse
 
paulasantamaria profile image
Paula Santamaría

That's a nice tip. Last week I was looking for an ESLint rule to detect commented code and I run into a Github issue where they discussed that there're some cases where commented out code may be useful, like code usage examples. I have to agree that it's not a black or white thing.

Collapse
 
xwero profile image
david duymelinck

The case that comes to mind at the moment is when the client is a/b testing features and they are not sure if they want to keep it of remove it after the testing. When my report comes in I mail them about it, and most of the time they will have a definite decision.

The only time I would put code usage examples in commented code, is when the project has a comments to documentation parser like JSDoc