我们都知道类/对象应该代表事物
而方法/消息应该代表操作(动词)。
但是如何选择正确的动词?
我听说过一个“方法命名规则”是
想象一些完全不同的实现,然后
只需选择对所有人通用的名称即可。
编辑:我也知道方法的命名应尽可能接近域。
(意思是在意图之后而不是在实施之后)
您还知道哪些其他人?
We all know that classes/objects should represent things
while methods/messages should represent operations (verbs).
But how to pick the right verb?
I've heard one "rule for method naming" is to
imagine some completely different implementations and then
simply pick name that is general for all of them.
EDIT: I also know that methods should be named as closest to domain as possible.
(means after intention not after implementation)
What others do you know?
发布评论
评论(1)
我喜欢尝试命名事物,以便给定的代码行尽可能具有语法和句法意义,即使对于非程序员也是如此。 (这是我在 .NET 代码中如此喜爱 lambda 的原因之一。这就像从拉丁词根创建新单词一样,只需将事物链接在一起即可。)
有一篇非常好的文章 此处介绍了在构建存储库时命名类和方法。
I like to try to name things so that a given line of code would make as much grammatical and syntactic sense as possible, even to a non-programmer. (One of the reasons why I love lambda so much in my .NET code. It's like making new words from Latin roots, you just keep chaining things together.)
There's a pretty good article here on naming classes and methods when building a repository, for example.