8

I'm an Android developer and the following question came to my mind: When I put a big comment in order to compiling process, is that while we put our useful comment in code , can compiler take some time at comment portion?

If no, then is it not get any effect since how long our comment?

RossFabricant
  • 12,364
  • 3
  • 41
  • 50
Nikunj Patel
  • 21,853
  • 23
  • 89
  • 133

3 Answers3

20

can compiler take some time at comment portion?

Apart from the IO overhead of traversing the bytes corresponding to the comment (which should be negligible as long as it's not a several megabyte long comment), it will make no difference what so ever. Most compilers don't even include the comments in the AST, which means that the comments are completely gone after parsing.

Never decide whether or not to include a comment based on compilation time. Base your decision solely on whether it makes the code more readable or not.

Further reading:

Community
  • 1
  • 1
aioobe
  • 413,195
  • 112
  • 811
  • 826
10

Yes, each comment that you write will make the compilation slower, because the compiler has to read more text. But: reading comments is very easy for a compiler, and it is quickly done, so you should not worry about it.

You can try it out yourself. Make a program that generates some simple source code with lots of comments in it.

int i = 0;
...
i++; /* This is a comment, and maybe a very long one. */
...

Now you can experiment with making this (generated) comment very long, possibly even megabytes. Then measure the difference when compiling the code with small and large comments, and you will see that the speed is still acceptable.

Roland Illig
  • 40,703
  • 10
  • 88
  • 121
9

It takes time to read and parse these comment block but this time is so short you won't notice and anyways not an excuse not to put (extended and useful) comments in your programs :-)

fvu
  • 32,488
  • 6
  • 61
  • 79