Naming Conventions For Class Containing Acronym

我与影子孤独终老i 提交于 2019-12-07 08:05:59

问题


If I am naming a new class in an OOP language, which is a better convention:

  1. XMLWriter
    • Most common
  2. XMLwriter
    • Easier to distinguish
  3. XmlWriter
    • No longer an acronym
  4. XML_Writer
    • Removes the point of camel case

Pedantic yes, but I'm curious who uses what and why.


回答1:


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!




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/7410304/naming-conventions-for-class-containing-acronym

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!