Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming Conventions For Class Containing Acronym

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.

like image 592
Aram Kocharyan Avatar asked Sep 14 '11 01:09

Aram Kocharyan


2 Answers

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!

like image 114
david van brink Avatar answered Sep 28 '22 08:09

david van brink


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.

like image 42
Zipper Avatar answered Sep 28 '22 07:09

Zipper