我花了太多时间试图想出变量、类、函数等......名称。我可以使用某种工具、方法或技巧来缩短这个时间吗?
目前我最好的工具是同义词库,但我想扩大我在这个问题上的视野。
Currently my best tool for this is a thesaurus, but I would like to expand my horizons on the matter.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
投资一个可以让重构变得更容易的工具。与在 NetBeans 中一样,您可以轻松地重命名类和变量。如果你使用它,即使犯错误也不会产生太大问题。
但考虑一下名称的结构是明智的。
我将类视为一个实体,因此它的名称是名词,例如 Customer 是代表客户的类的名称。
函数(也是方法)是一个动词。它描述了它的作用,例如 getName() 返回名称。 get 和 set 是返回或设置属性的函数的常见前缀。这就是为什么它们被称为“getters”和“setters”。函数名称也可以是 saveCustomer 来保存客户,或者仅保存(如果它是客户类的方法)。
有了这样的一些基本规则,应该很容易想出一个合理的名称,您可以随时使用许多编辑器中的重构工具来更改它。
有时很难找到一个好名字。我自己不是英语母语,而我编写的代码(和注释)是英文的,因为它更符合现有的库。有时我发现很难找到合适的词。在这种情况下,我会使用字典或谷歌来查找翻译。通常,在谷歌上搜索“WordInYourLanguage 翻译”会为您提供词典网站上的条目列表,您可能会从中识别出正确的术语。
Invest in a tool that makes refactoring easier. Like in NetBeans, you can easily rename classes and variables. If you use that, you can make a mistake without much problems.
But it is wise to think about the structure of names.
A class I think of as an entity, so its name is noun, like Customer is the name for a class respresenting a customer.
A function (and method too) is a verb. It describes what it does, like getName() returns the name. get and set are common prefixes for functions that return or set a property. That's why they're even called 'getters' and 'setters'. A function name could also be saveCustomer to save a customer, or just save, if it is a method of the customer class.
With some basic rules like that, it should be easy to come up with a reasonable name, which you can always change using the refactory tools found in many editors.
Sometimes it is hard to find a good name. I'm not a native english speaker myself, while the code I write (and the comments) is in english, because it conforms more to existing libraries. Sometimes I find it hard to find the right word. In that case I use a disctionary or just Google to find a translation. Usually googling for 'WordInYourLanguage translation' will give you a list of entries on dictionary sites, from which you probably will recognize the right term.
对我来说听起来有点强迫症......
我的大部分代码都不面对第二双眼睛,所以我有时将我的变量命名为“BigBoobs”之类的东西......在一天结束时,唯一需要的人知道变量是您和其他可能正在查看代码的人...
至于认真解决您的问题:
我认为不会真的有一个变量名称生成器,因为这将涉及它知道您的程序是什么实际上就是按照你做的那样做。如果存在这样的技术,我想我就会失业。
Sounds a bit OCD to me...
Most of my code does not face a 2nd pair of eyes, so I sometimes name my variables things such as "BigBoobs"... At the end of the day, the only people that need to know the variable are you and anyone else who may be looking at the code...
As for seriously addressing your question:
I don't think there would really be a variable name generator out there, because that would involve it knowing what your program is actually doing as you do it. If technology like that exists, I guess I will be out of a job.