Question

I'm using C# and VB.NET.

I often (every days...) add comments to existing source files. When I check-in these files, I would like to have my merge tool to ignore any changes made to comments - I just want to be sure that I did not change the code.

I use WinMerge and Team Foundation Control Server (yes, no chance : Subversion was not an option when I accepted this job :o). Both of them can ignore white spaces but cannot ignore comments. Result : I have to carefully look at all the changes that I have made to each file before checking them in. And this is pretty cumbersome.

(Well, since most of my co-workers do not comment at all -- hey, they use pretty long namespace/class/methods/property/type/constant names that tell it all, guys ! -- it's a lot of work.)

Any suggestions ?

All the best, Sylvain.

Was it helpful?

Solution

BeyondCompare has a filter for ignoring "unimportant" changes and comments belong to that category by default.

OTHER TIPS

Compare++ has an option "Ignore comment changes" and "Ignore pure formatted changes" which should honor your request.

You said you used WinMerge - well it has the ability to filter out comments.

However it only works for comments that are on a separate line, so for example:

int i; // comment

will be detected as different from

int i;

It sounds like you're using commenting as a tool to understand the code as you work with it. That's an interesting idea, the equivalent of highlighting a book or taking notes. But you need to make sure you strip out all these transient comments before working with others.

Before comparing or promoting, run your source files through a filter program that strips the comment. This could be a one-liner perl script.

To make it easier, use a distinctive pattern for your non-permanent comments, to make them easier to filter out (and to distinguish between these transient comments, and comments you really want to leave in the source). E.g. if you were writing in C++, always comment using

 //Sylvain: this is my comment here.

or some other pattern that is even easier to grep for.

If the content of the comments are not something you care about, and do not matter, why not delete them?

If well documented code that is readable and understandable is part of what you create, why not review changes to that meta-data?

Adding comment to your code is smell that your code is hard to read, code should be self describing, like someone has said that , good code is like good joke, it does not need to be explained. It is better to change your variable name, put section of your code into a subroutine. Re factoring is better than commenting. Even you find a tool to solve you commenting problem, it does not solve the real problem that is make you code easy to understand.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top