Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 206
abbas Avatar asked Apr 29 '10 06:04

abbas


People also ask

Does commented code affect performance in C#?

Comments and whitespaces are not not compiled by any compiler and are ignored, so these two have no effect on performance.

Does commented code affect performance?

No it does not effect performance. As most of the programming languages compile or interpret code and comments are skipped as computer has nothing to do with comments.

Can code have too many comments?

There are two main reasons why this can happen: Too many times comments are just an excuse for writing bad code. Instead of writing good code, programmers believe that if they write dirty code with some weird hacks, and describe it with a 5 lines of comments — that the code is readable and well written.

Does commented code affect performance HTML?

What are the negatives of HTML comments? worsens the UX - even not visible, the HTML comments are part of the DOM tree and increase the number of DOM elements. This, in turn, affects the quickness and responsiveness, also leads to slower CSS selectors and DOM manipulation.


3 Answers

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.

like image 178
Allon Guralnek Avatar answered Oct 29 '22 03:10

Allon Guralnek


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

like image 33
Daniel Dolz Avatar answered Oct 29 '22 05:10

Daniel Dolz


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.

like image 24
SRA Avatar answered Oct 29 '22 03:10

SRA