当前位置: 动力学知识库 > 问答 > 编程问答 >

java - Do comments affect compile time?

问题描述:

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?

网友答案:

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:

  • How To write comments
  • How do I write in-code comments and documentation in a proper way? Is there any standard for this?
  • How to write good javadoc comments?
网友答案:

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.

网友答案:

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 :-)

分享给朋友:
您可能感兴趣的文章:
随机阅读: