views:

301

answers:

5

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.

+2  A: 

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

robinr
Wow, I have made some tests with it and this is *exactly* what I was looking for ! Many thanks for the hint :o)
Sylvain
A: 

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?

Alex B
Sorry, I'm pretty bad in english - in fact, I *really* care about comments ! This is why I always adding some when I have to figure out how things works.
Sylvain
A: 
JRL
Great hint. Problem in my case : most of the time, I do not modify comments, I add some. Thanks for your answer !
Sylvain
A: 

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.

Alex Feinman
Well, most of the time, I do not comment code while I understand it - in fact, I comment it to ease the work for my fellowers. So all my comments MUST be checken-in.But your idea is pretty interesting - we can strip the comments for the compare tool, and then bring them back just before checking-in...Thanks for your answer Alex !
Sylvain
A: 

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.

Fred Yang
Well, you are right : good code does not need comment.The problem is that my fellow deveppers write pretty good code (they always use known Design Patterns, and they are clever) But clueless people like me cannot understand what they did ! I'm not the guy who write software, I'm the guy who have to maintain it. And it is most of the time pretty complicated.Why not tell the reader what was the intend ? To me, not saying the purpose of a class at least a 2 lines comment is a crime.
Sylvain