I have a doubt about CamelCase. Supose you have this acronym: Unesco = United Nations Educational, Scientific and Cultural Organization.
You should write: unitedNationsEducationalScientificAndCulturalOrganization
But what if you need to write the acronym? Something like:
getUnescoProperties();
Is it right to write it this way? getUnescoProperties() OR getUNESCOProperties();
First, I have to clarify that I am not a native English speaker, so my claim about English grammar can simply be wrong. If you discover such errors, please let me know, and I will be very thankful.
Best practice for acronym would be avoiding acronyms as much as possible. Anyway, this is not the case because acronym
UNESCO
is more familiar than full nameUnitedNationsEducationalScientificAndCulturalOrganization
.Then, I think
UNESCO
makes more sense thanUnesco
because simply it's closer to real life form so more familiar. I had some trouble to figure out what the wordUnesco
actually means.As an another example, think about
Arc
. This sounds like a curve around a circle, but in Rust, this meansAtomically Reference Counted
. If it's been written likeARC
, at least readers would recognize that the word is an acronym of something else rather than a kind of curve.Modern programs are written mainly for human readers. Then those naming rules must be set for human readability rather than machine processing or analysis.
In this perspective, we lose some readability by using
Unesco
overUNESCO
while gaining nothing.And for any other cases, I think just following plain English acronym rules (or conventions) is enough for most cases for best readability.
Some guidelines Microsoft has written about
camelCase
are:Summing up:
When you use an abbreviation or acronym that is two characters long, put them all in caps;
When the acronym is longer than two chars, use a capital for the first character.
So, in your specific case,
getUnescoProperties()
is correct.In addition to what @valex has said, I want to recap a couple of things with the given answers for this question.
I think the general answer is: it depends on the programming language that you are using.
C Sharp
Microsoft has written some guidelines where it seems that
HtmlButton
is the right way to name a class for this cases.Javascript
Javascript has some global variables with acronyms and it uses them all in upper case (but funnily, not always consistently) here are some examples:
encodeURIComponent
XMLHttpRequest
toJSON
toISOString
getUnescoProperties()
should be the best solution...When possible just follow the pure
camelCase
, when you have acronyms just let them upper case when possible otherwise gocamelCase
.Generally in OO programming variables should start with lower case letter (
lowerCamelCase
) and class should start with upper case letter (UpperCamelCase
).When in doubt just go pure
camelCase
;)parseXML
is fine,parseXml
is alsocamelCase
XMLHTTPRequest
should beXmlHttpRequest
orxmlHttpRequest
no way to go with subsequent upper case acronyms, it is definitively not clear for all test cases.e.g. how do you read this word
HTTPSSLRequest
,HTTP + SSL
, orHTTPS + SL
(that doesn't mean anything but...), in that case follow camel case convention and go forhttpSslRequest
orhttpsSlRequest
, maybe it is no longer nice, but it is definitely more clear.There is also another camelcase convention that tries to favor readability for acronyms by using either uppercase (
HTML
), or lowercase (html
), but avoiding both (Html
).So in your case you could write
getUNESCOProperties
. You could also writeunescoProperties
for a variable, orUNESCOProperties
for a class (the convention for classes is to start with uppercase).This rule gets tricky if you want to put together two acronyms, for example for a class named XML HTTP Request. It would start with uppercase, but since
XMLHTTPRequest
would not be easy to read (is it XMLH TTP Request?), andXMLhttpRequest
would break the camelcase convention (is it XM Lhttp Request?), the best option would be to mix case:XMLHttpRequest
, which is actually what the W3C used. However using this sort of namings is discouraged. For this example,HTTPRequest
would be a better name.Since the official English word for identification/identity seems to be ID, although is not an acronym, you could apply the same rules there.
This convention seems to be pretty popular out there, but it's just a convention and there is no right or wrong. Just try to stick to a convention and make sure your names are readable.
There are legitimate criticisms of the Microsoft advice from the accepted answer.
playerID
vsplayerId
vsplayerIdentifier
.USTaxes
vsusTaxes
USID
vsusId
(orparseDBMXML
in Wikipedia's example).So I'll post this answer as an alternative to accepted answer. Votes can decide. All acronyms should be treated consistently; acronyms should be treated like any other word. Quoting Wikipedia:
So I re: OP's question, I agree with accepted answer; this is correct:
getUnescoProperties()
But I think I'd reach a different conclusion in these examples:
US Taxes
→usTaxes
Player ID
→playerId
So vote for this answer if you think two-letter acronyms should be treated like other acronyms.
Camel Case is a convention, not a specification. So I guess popular opinion rules.
And in searching for the "popular" answer in existing code or markup, maybe the accepted answer got it right.