After using version control tools, it is no longer necessary to comment out old code.
However, some team members still comment out old code. Therefore, I want to clean them up.
I want to mark commented lines which are really comments / documentation, so that every time I do not need to re-read all commented regions. The unmarked lines left are new commented code.
How do I achieve this? Any existing tools or need to write on my own?
Similar concept: in git, we have ‘partial commit’ to select some lines to commit.
However, the lines marked in ‘partial commit’ is valid once only.
How to discriminate commented code and documentation comments
After using version control tools, it is no longer necessary to comment out old code.
However, some team members still comment out old code. Therefore, I want to clean them up.
I want to mark commented lines which are really comments / documentation, so that every time I do not need to re-read all commented regions. The unmarked lines left are new commented code.
How do I achieve this? Any existing tools or need to write on my own?
Similar concept: in git, we have ‘partial commit’ to select some lines to commit.
However, the lines marked in ‘partial commit’ is valid once only.
1
Don’t mark comments as comments, if you find commented out code while working in a file just delete it. Also try to get those that still insist on commenting out code to stop doing that, nothing is going to change unless you can stop people from commenting out blocks of bad code and not just deleting them. Then its just a simple matter of your team all working together to eliminate commented code when they find it, trying to make those that left commented code go back and clean it up is just a recipe for unnecessary drama.
2
Be careful, because documentation comments sometimes also contain code examples. You want to keep those. For example:
There is probably no error-proof method, but you could write a short Perl script that finds all comments in the code, keeps the documentation comments, and then makes a guess about the remaining ones using a few regular expressions for the beginning of the comment.
I think that the “nuke on sight” strategy suggested by @Ryathal is sound.
If you want to detect commented out code (please don’t call it “commented code” because lots of people think that means code with comments!) then I think you are going to need to do this by examining the diffs between successive versions. Even then it is not straight forward because there is a variety of ways to comment out code … depending on the programming language.
If you want an automated solution you could parse the comments to see if they are valid code. In general this would identify commented out code. Example code is one thing you have to be wary of accidentally deleting. Though you could check if there is a somewhat standard way of formatting them that you could use to identify or ignore them. E.g. they are in a header or function comment block, or marked in some other way.
Filed under: softwareengineering - @ 06:02
Thẻ: comments, version-control
« Declaring interface in the same file as the base class, is it a good practice? ⇐ More Pages ⇒ Object construction design »