因此,我正在处理这个类,它应该通过web服务从供应商请求帮助文档。我试着把它命名为documententretriver, VendorDocRequester, DocGetter,但它们听起来不太对。最后,我在dictionary.com网站上浏览了半个小时,试图找到一个合适的词。
带着坏名字开始编程就像早上头发很糟一样,接下来的一天就会每况愈下。感觉我吗?
因此,我正在处理这个类,它应该通过web服务从供应商请求帮助文档。我试着把它命名为documententretriver, VendorDocRequester, DocGetter,但它们听起来不太对。最后,我在dictionary.com网站上浏览了半个小时,试图找到一个合适的词。
带着坏名字开始编程就像早上头发很糟一样,接下来的一天就会每况愈下。感觉我吗?
当前回答
Steve Mcconnell的《Code Complete》一书中有一个关于命名变量/类/函数/…
其他回答
我能感受到你的痛苦。:/
我希望有一种工具可以与数据字典(描述各种变量/方法名称的文件,我猜有点像javadoc)一起检查源代码,这样你就可以编写这样的代码:
class Battery
{
double I; // current
double T; // temperature
double V; // voltage
double Q; // charge
void update(double Inew, double dt) { I = Inew; Q += I*dt; }
// ... etc ...
};
and the code-reviewing tool could do a number of different things to make it easier to view code in context, including display reminders that I = current (e.g. in a pane on the right-hand-side of the window it would display variable definitions/semantics/comments for the place in the code you are clicking on), or even allow you to do "virtual refactoring" where as a code reviewer you could rename something to your liking for readability/display reasons without actually changing the code stored on disk.
就像我喜欢自我描述名字一样,我讨厌读像BatteryFilteredCurrentInMilliamps这样的东西。通常在嵌入式系统中,我们是基于代数方程来建模对象的,这样的方程名称非常麻烦。(另一方面,“I”上面有一顶帽子,下标“d”和上标“*”是相当令人困惑的。)
我首先是一个EE /系统工程师,负责少量的软件工作,最后我真的不关心变量的名称,只要我有一种方便的方法来告诉它是什么,并将它映射到我自己的被控制系统的内部模型。
不是真的。考虑到在编码中必须理解的所有困难,说命名类和方法是编程中最困难的事情之一是荒谬的。不要误解我的意思,有时很难想出一个好名字,但让我们现实一点。我可以说这是编程中最简单的部分之一。
同意了。我喜欢让我的类型名称和变量尽可能具有描述性,而不太长,但有时只是有一个特定的概念,你找不到一个好的词来形容。
在这种情况下,向同事寻求帮助总是有帮助的——即使他们最终没有帮助,它通常至少能帮助我大声解释出来,让我的车轮转动起来。
线程1:
function programming_job(){
while (i make classes){
Give each class a name quickly; always fairly long and descriptive.
Implement and test each class to see what they really are.
while (not satisfied){
Re-visit each class and make small adjustments
}
}
}
线程2:
while(true){
if (any code smells bad){
rework, rename until at least somewhat better
}
}
这里没有Thread.sleep(…)。
这也是为什么每个软件开发人员都应该具备写作和沟通技能的另一个原因。
我认为丰富的词汇量也很重要。