还有其他人发现命名类和方法是编程中最困难的部分之一吗? [英] Anyone else find naming classes and methods one of the most difficult parts in programming?

查看:63
本文介绍了还有其他人发现命名类和方法是编程中最困难的部分之一吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在研究该类,该类应通过Web服务向供应商索取帮助文档.我尝试将其命名为DocumentRetrieverVendorDocRequesterDocGetter,但是听起来不正确.我最终浏览了 dictionary.com 半个小时,试图找到一个合适的单词.

So I'm working on this class that's supposed to request help documentation from a vendor through a web service. I try to name it DocumentRetriever, VendorDocRequester, DocGetter, but they just don't sound right. I ended up browsing through dictionary.com for half an hour trying to come up with an adequate word.

使用坏名开始编程就像早上头发非常糟糕,一天的其余部分从那里走下坡路一样.感觉到我吗?

Start programming with bad names is like having a very bad hair day in the morning, the rest of the day goes downhill from there. Feel me?

推荐答案

您现在正在做什么很好,我强烈建议您坚持使用当前的语法,即:

What you are doing now is fine, and I highly recommend you stick with your current syntax, being:

上下文+动词+方式

我使用此方法来命名函数/方法,SQL存储过程等.通过保持这种语法,它将使您的Intellisense/代码窗格更加整洁.因此,您需要EmployeeGetByID()EmployeeAdd(),EmployeeDeleteByID().当您使用语法上更正确的语法(例如GetEmployee(),AddEmployee())时,如果在同一个类中有多个Get,则将变得非常混乱,因为无关的东西将被组合在一起.

I use this method to name functions/methods, SQL stored procs, etc. By keeping with this syntax, it will keep your Intellisense/Code Panes much more neat. So you want EmployeeGetByID() EmployeeAdd(), EmployeeDeleteByID(). When you use a more grammatically correct syntax such as GetEmployee(), AddEmployee() you'll see that this gets really messy if you have multiple Gets in the same class as unrelated things will be grouped together.

这类似于用日期命名文件,您想说的是2009-01-07.log而不是1-7-2009.log,因为当您拥有一堆文件后,该命令就变得毫无用处了.

I akin this to naming files with dates, you want to say 2009-01-07.log not 1-7-2009.log because after you have a bunch of them, the order becomes totally useless.

这篇关于还有其他人发现命名类和方法是编程中最困难的部分之一吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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