Naming Conventions For Class Containing Acronym

倾然丶 夕夏残阳落幕 提交于 2019-12-05 15:33:56
david van brink

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!

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.

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.

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