views:

264

answers:

4

if we have too much commented code in .net would it effect code performance?

+12  A: 

It will only effect the time it takes to compile your code (by the C#/VB compiler) to IL. For C# and VB.NET there is no difference in runtime performance, guaranteed.

Steven
+10  A: 

Almost all compiled languages discard comments when creating the resulting binary (this includes all .NET languages, Java, unmanaged languages, etc).

Interpreted languages (like JavaScript, when not compiled), may have a tiny performance hit, since the interpreter has to skip over the comments. But it's so small you shouldn't concern yourself with it.

The real question is why you need to have so many comments? An excess of comments can hurt readability and thus maintainability. Comments should be concise, precise and succinct, and should not state the obvious (e.g. i++; // increment loop counter). They should help explain why something was done (edge cases, hacks), describe how and when to use the code (API documentation) or explain the gist of what is going on in the method or class. If the code isn't readable, try refactoring it. If there are complex business processes, describe them in depth in the appropriate project documentation, not in code comments. Also, don't leave large amount of comment-out code, it hurts readability even more. If it is no longer needed, remove it - the removed code should exist in your source control anyway.

Allon Guralnek
+1 for the better answer. Definitely better than "guaranteed" :)
Kobi
A: 

Common interpreted languages will get effected due to more comments in code. But c# is a compiled language and comments do not effect the execution.At the start ofcompilation, compilers removes all lines beginning with the // characters and also the text between the /* and */ delimiters.So there will be no performance degradation.

Sunil Ramu
+2  A: 

No at all. Resulting IL bytecode will be same, with or without comments, with or without indentation, etc.

Daniel Dolz