开发者

CamelCasing: HTMLReport vs. HtmlReport

开发者 https://www.devze.com 2023-03-13 18:33 出处:网络
Often you would use well or somewhat established abbreviations in class or method names. But how do you CamelCase or camelBack them?

Often you would use well or somewhat established abbreviations in class or method names. But how do you CamelCase or camelBack them?

  • 开发者_C百科HTMLReport vs. HtmlReport
  • CustomerDAO vs. CustomerDao
  • XMLRPC vs. XmlRpc

Which side is correct (or which would you prefer)?


In Java there's little choice, if you want to treat HTML as one word, it has to be written as html or Html. For example, due to Java beans convention, getHTML() implies a property named hTML.

It's really up to the opponent to answer this question, why should HTML be in all capital letters? English convention? Who cares? If we follow English convention we should have spaces between words.


i prefer the later. eventually html becomes a word as opposed to an abbreviation.


camelCasing doesn't capitalize the first letter, that's PascalCasing - I don't have a problem with HTMLReport, but I have found that many companies' naming conventions specify the other way: HtmlReport, with no multiple letters in a row.


There is no correct answer to this one. The most important thing is you are consistent. Its annoying when some classes are XMLMyClass and others are XmlMyOtherClass and you are using auto-complete features of IDE's as two related classes that have similar names don't show up next to each other.

As a personal preference, in general I like capitalizing only the first letter of an acronym unless the acronym ends the name. If it ends the name then I think all caps for it is good. I say this for two reasons.

  1. Its hard to parse where an acronym ends if it starts or is in the middle of the word and it is in all caps. For well known acronyms its not as big of a deal but if you are creating new acronyms it can be harder to read.
  2. You don't wind up with back to back acronyms creating all capitals like in your XMLRPC case.

That being said the a good strategy to use in making the decisions is I go with the conventions of the standard library of the language.

For example since you tagged this with C# and Java we can look at how those languages handle acronyms.

  • C# has only the first letter of the acronym captialized like in XmlReader

  • Java has all the letters capitalized like in XMLStreamReader


I'd say it depends. XML and HTML can be camel case. DAO is a more "strict" abbreviation and should probably be all upper case

0

精彩评论

暂无评论...
验证码 换一张
取 消