-1

Is it possible to automatically remove code comments in Visual Studio files before committing to source control, or is it possible to virtually have comments in files but physically store those in separate files?

The end goal is not to have comments in source control, but be able to have those locally.

BuzzBubba
  • 693
  • 1
  • 8
  • 20
  • 5
    Why don't you want the comments in source control? – Matthew Strawbridge Nov 27 '11 at 23:19
  • The reason is that we have a stupid system that has a special deploy SC that goes automatically into build and deploy. Since we have complex APIs we have a lot of Intelli-Sense friendly XML and other comments that are not required within a deployed application. – BuzzBubba Nov 28 '11 at 00:05
  • 2
    What does automated build have to do with this? It sounds now like you are presuming that the generated byte code includes the comments, and the resulting deployment is larger than necessary as a result. I'd test that: pick a class and compile it with and without comments. If the byte code is the same size, problem solved. The compiler might be smart enough to only add the executable bits to the deployed byte code. – duffymo Nov 28 '11 at 00:55
  • You should tell that to our program manager :) – BuzzBubba Nov 28 '11 at 18:11
  • 1
    If you really want to do this then then what you have to do is add a step to your build process that strips the comments from the code at build time. This is fairly easy to do if you use a tool like SED or AWK. – jussij Dec 07 '11 at 23:45

2 Answers2

4

This is wrong-headed.

What you should remove is commented out code. Let the version control system do its job. Comments that illustrate what's in the code and why should remain.

How do you expect to retain them if you remove them in source control? The next time you check out the code, the comments won't be there.

duffymo
  • 293,097
  • 41
  • 348
  • 541
1

For development, It is good to keep comments in your code. Don't remove them. You cannot let your comments locally and commit non-commented files, because when checking out your repository, it'll have no comments at all.

Through comments, other developers are able to figure out what's going on much faster and be more precise as well. They can find bugs and improve your code. So, comments are cool. I mean, good comments. I know code must speaks by itself, but comments are important as well.

If you intend to save storage, please, don't do that for development process. What you can do is deploy your code withou any comment, and, if possible, compressed.

We are being programming language agnosic, but I am pretty sure every language has some way to strip out comments and optimize it for deploy.

gustavotkg
  • 3,501
  • 1
  • 17
  • 29