因此,我正在处理这个类,它应该通过web服务从供应商请求帮助文档。我试着把它命名为documententretriver, VendorDocRequester, DocGetter,但它们听起来不太对。最后,我在dictionary.com网站上浏览了半个小时,试图找到一个合适的词。

带着坏名字开始编程就像早上头发很糟一样,接下来的一天就会每况愈下。感觉我吗?


当前回答

我所做的就是检查它是否太长如果我不记得它太长

其他回答

上个月我刚刚写了一篇关于命名惯例的文章:http://caseysoftware.com/blog/useful-naming-conventions

要点是:

verbAdjectiveNounStructure -结构和形容词作为可选部分

对于动词,我坚持使用动作动词:保存、删除、通知、更新或生成。偶尔,我也会使用“进程”一词,但只是专门指队列或工作积压。

对于名词,我使用与之交互的类或对象。在web2project中,这通常是任务或项目。如果是Javascript与页面交互,则可能是body或table。关键在于代码清楚地描述了与之交互的对象。

该结构是可选的,因为它对该情况是惟一的。列表屏幕可能会请求List或Array。在web2project的项目列表中使用的核心函数之一就是getProjectList。它不修改底层数据,只修改数据的表示形式。

The adjectives are something else entirely. They are used as modifiers to the noun. Something as simple as getOpenProjects might be easily implemented with a getProjects and a switch parameter, but this tends to generate methods which require quite a bit of understanding of the underlying data and/or structure of the object... not necessarily something you want to encourage. By having more explicit and specific functions, you can completely wrap and hide the implementation from the code using it. Isn't that one of the points of OO?

我不得不承认命名是一门艺术。如果你的类遵循特定的“设计模式”(工厂等),事情就会变得简单一些。

线程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(…)。

该类只有一个合理的名称:

HelpRequest

不要让实现细节分散了你对意义的注意力。

你用来描述问题的语言,就是你应该用来描述变量、方法、对象、类等的语言。一般来说,名词匹配对象,动词匹配方法。如果您缺少描述问题的词语,那么您也缺少对问题的全面理解(规范)。

如果它只是在一组名称中进行选择,那么它应该由您用来构建系统的约定来驱动。如果您遇到了以前的约定所没有发现的新情况,那么总是值得花一些精力尝试扩展它们(适当地、一致地)来覆盖这个新情况。

如果有疑问,那就睡一觉,选一个最明显的名字,第二天早上:-)

如果有一天你醒来发现自己错了,那就马上改变。

保罗。

BTW: Document.fetch()是非常明显的。