0

I recently found two posts in StackOverflow about adding comments in programming. Posts : 1,2

After going through these posts i was eager to know a thing a comments.i.e :

1.Do adding comments in programming utilize system resource while compiling the code ?

Community
  • 1
  • 1
Tharif
  • 13,794
  • 9
  • 55
  • 77
  • Given that comments are text and need to be parsed just like any other text in the file, *yes*. But this should make absolutely no difference to anyone (i.e. comment when appropriate, if you need a novel, put it in a seperate document). – crashmstr May 22 '15 at 12:08
  • I'd add to @crashmstr's comment that, if you need a comment, first ask yourself whether that's a sign that the code needs rewriting. Good comments are scarce comments (but only if the code is well written). If you have very few comments, then it'll have negligible affect upon he compiler. – David Arno May 22 '15 at 12:10

3 Answers3

2

Yes they do, but you probably have to add a lot of them to notice any difference.

Peter
  • 27,590
  • 8
  • 64
  • 84
  • The times where `\t` was preferred to 4 spaces for formatting because it was shorter are finished :-) – xanatos May 22 '15 at 12:08
0

Handling white space and comments is part of the "lexing" (lexical analysis) phase of compilation, so yes, they do consume resources in the process. As a previous commenter has said, it's so computationally cheap that you'd have to insert a lot of comments and white space (and maybe compile on a really slow computer) before you'd notice.

You may be interested in this document: Notes on How Parsers and Compilers Work.

Joey deVilla
  • 8,403
  • 2
  • 29
  • 15
0

The first rule of programming: write code that other people can easily read and modify. To achieve this:

  1. Write short, clear, code blocks that are easy to read and thus easy to determine the "what".
  2. Write unit tests to both convey the "why" and to provide a safety net when maintaining the code.

Everything else, including how long the code takes to compile, should be moot. So the answer to your question is "it doesn't matter".

David Arno
  • 42,717
  • 16
  • 86
  • 131