开发者

How and how much comments will impact on application performance?

I created a small Ruby on Rails 3 application. In my file I have commented a lot of code that serves to document in detail each method. The documentation for each file is about a quarter of the entire file.

How 开发者_如何学Pythonand how much this will impact on application performance? Running the production environments (maybe compiling the application), comments will be evaluated on loading files or on loading them will be completely ignored without effects on performance?


The effect will be essentially zero performance difference. One could argue that evaluating comments is marginally slower, but the effect on the maintainability and readability of your code will be so great that no amount of shaving microseconds of time off Ruby's evaluation could be worth it.

In production, your objects should be evaluated once and cached if you have the cache_classes settings specified in your config/environments/production.rb file (you should - it's the default):

# The production environment is meant for finished, "live" apps.    
# Code is not reloaded between requests
config.cache_classes = true

Way to comment thoroughly! Future-You will thank Past-You for it.


Pray that you are so successful that you must trim back your comments.


I think the answers might be missing the point. In a different environment I've maintained the development version of code (fully commented); and the implementation process migrated the code, but not the comments (for the sake of performance). If you are confident of your implementation procedure you can thus have the best of both worlds.

Not answering the question, but clarifying what would be ideal - no overhead in production, but still fully commented code.

And as has been said - never scrimp on comments. Rather too much than too little.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜