包含首字母缩略词的类的命名约定
如果我用 OOP 语言命名一个新类,这是一个更好的约定:
- XMLWriter
- 最常见
- XMLwriter
- 更容易区分
- XmlWriter
- 不再是缩写词
- XML_Writer
- 删除了驼峰式的点
迂腐是的,但我很好奇谁使用什么以及为什么。
If I am naming a new class in an OOP language, which is a better convention:
- XMLWriter
- Most common
- XMLwriter
- Easier to distinguish
- XmlWriter
- No longer an acronym
- XML_Writer
- Removes the point of camel case
Pedantic yes, but I'm curious who uses what and why.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Java 约定最近似乎倾向于将众所周知的首字母缩写词视为单词,因此:“XmlWriter”...
http://www.ibm.com/developerworks/library/ws-tip-namingconv.html
带有缩写词的 Java 命名约定 <-重复问题?
http://geosoft.no/development/javastyle.html
但似乎没有人非常一致。以 JavaScript 的 XMLHttpRequest 为例。真是一场火车失事!
Java conventions seem lately to favor treating well-known acronyms like words, so: "XmlWriter"...
http://www.ibm.com/developerworks/library/ws-tip-namingconv.html
Java Naming Convention with Acronyms <-dupe question?
http://geosoft.no/development/javastyle.html
But nobody seems to be very consistent. Take JavaScript's XMLHttpRequest for example. What a trainwreck!
我很确定所有不同命名约定的人都会因为我这么说而对我进行指责。但在我看来,您应该使用的命名约定应该是最容易阅读的命名约定。名称仅供人类使用,因此它们应该是最容易阅读/理解的名称。因此,对于像 XMLWriter 这样的东西,我可能会将其称为 XmlWriter,因为这看起来更容易阅读。对于非常非常常见的事物(即 XML),我认为将其视为一个单词效果最好。如果您有一些特定于您的域的首字母缩略词,那么我可能会将其大写,以便不经常使用它的人会明白它是首字母缩略词。基本上使人们更容易理解名称的真实意图,即使它使阅读起来稍微困难一些。我认为使用常识和最佳判断比试图坚持一套绝对的命名规则要好。尽管命名应该尽量遵循一组合理的命名约定。
I'm pretty sure all the different naming convention people will want to string me up for saying this. But in my opinion the naming convention you should use should be the one that is easiest to read. Names are only used by humans, so therefore they should be whatever is easiest to read/understand. So for things like XMLWriter, I would probably put it as XmlWriter since that seems a little easier to read. For things that are very very common (i.e. XML) I think treating it as a word works best. If you have some acronym that is specific to your domain, then I might capitalize it so that people who don't use it all the time would understand that it's an acronym. Basically make it easier to understand the names real intention even if it makes it slightly harder to read. I think using common sense and best judgment is better than trying to stick to a absolute set of rules in naming. Although the naming should try it's best to follow a reasonable set of naming conventions.
我想说你应该总是更喜欢最具可读性的(正如 zipper 所说)并且至少以大写字母开头,因为我在某处读到它是 Java 标准约定,而且我也觉得以大写字母开头总是让你确保它是一个Java类。
I would say you should always prefer the most readable one (as zipper said) and atleast start the class name with capital letter as somewhere i read that its a Java standard convention and I also feel that starting with a capital letter always makes you sure that its a Java class.