什么是黄金代码/评论比例? [英] What's the golden code/comment ratio?

查看:155
本文介绍了什么是黄金代码/评论比例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



你可以给出一些开源项目的代码/评论比例,被认为具有良好的编码和各自的评论比率?



(我意识到,对于每个项目,没有比例是真实的,而且可能会表现出这样的项目理论黄金比例还有...)

解决方案

评论应该是非常罕见和有价值的,几乎总是表达为什么和从来没有如何(例外是如何复杂,不容易从代码中辨别出来)。



每个评论都是一个提示,你可能需要重构使代码的意图更清晰。每个评论都会在写入后立即变得过时。



除了 xUnit.net项目,但一些人们似乎发现代码清晰易读。 :)


Is there a code/comment ratio that you consider to be a sign of good (bad) code health?

Can you give examples of open source projects that are considered to be well coded and their respective comment ratio?

(I realize that no ratio is "true" for every project and there may very well be crappy projects that exhibit this theoretical golden ratio. Still...)

解决方案

Comments should be very rare and valuable, almost always expressing the "why" and never the "how" (the exception being when the how is complex and not easily discernible from the code).

Every comment is a hint that you may need to refactor to make the code's intent clearer. Every comment risks becoming out of date as soon as it's written.

We have almost no comments aside from XML comments in our xUnit.net project, but some people seem to find the code clear and easy to read. :)

这篇关于什么是黄金代码/评论比例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆