This is a bit pedantic, but I've seen some people use Id as in:

private int userId;
public int getUserId();

and others use:

private int userID;
public int getUserID();

Is one of these a better name than the other? Why? I've seen this done very inconsistently in large projects. If I were to set a standard which would most people be familiar with? Which is the conventional standard?

  • 44
    Consistency is the most important thing that matters. Be it camel case, or underscores or whatnot. Be consistent.
    – user40980
    Commented Feb 7, 2013 at 23:28
  • 42
    Look at your language's XML APIs to see how they do it. Java names classes like SAXParser and DOMException, .NET names classes like XmlDocument. Based on that, I'd say "ID" in Java, "Id" in C#.
    – luiscubal
    Commented Feb 8, 2013 at 0:12
  • 2
    But the upper-case identifiers, by convention, are used in Java for static fields, so the "ID" name for base field is not the best one. And there comes the consistency...
    – user11463
    Commented Feb 8, 2013 at 8:57
  • 9
    Would you name the variables EGO and SuperEGO? I didn't think so. ;)
    – kojiro
    Commented Feb 8, 2013 at 13:20
  • 4
    What?! Consistency? Where's the rage war?! That's it, I hereby nominate myself keeper of the sacred camel-case syntax flame and hereby decree that doing it with all-caps for acryonyms is for noobs. Also, it's correct to want to have the toilet paper roll from the top unless you have cats who get bored and do strange things, in which case they have much harder time unraveling the toilet paper set to roll from the bottom making such heresy acceptable for cat owners. I don't know why I get to decree on that. Bob the keeper of the toilet-roll-direction's sacred flame is busy I guess. Commented Feb 24, 2013 at 6:35

6 Answers 6


The most important rule to follow in these cases is consistency: Do as everyone else does.

For instance, look at your language's XML APIs to see how they do it.

Java names classes like SAXParser and DOMException, .NET names classes like XmlDocument.

Based on that, I'd say "ID" in Java, "Id" in C#.

However, I've seen that Java EE 6 has an annotation named @Id (see documentation), so it seems Java considers "Id" to be just a normal word.

  • @Id points to an annotation classname, not a variable name. Wrong example.
    – jwenting
    Commented Feb 12, 2013 at 7:26
  • 3
    SAXParser could be (and luckily is not) SimpleAPIforXMLParser (or even SimpleApplicationProgramingInterfaceforExtesibleMarkupLanguageParser). Each capital letter is begining of word. So even in java it should be "Id"
    – user470365
    Commented Feb 12, 2013 at 10:42
  • 2
    @jwenting The problem is finding out whether "id" is considered like a word or like two words. @Id says that it is a single word, so the variable name would be "id".
    – luiscubal
    Commented Feb 12, 2013 at 11:46
  • No. SAX is an acronym while Id is not.
    – nalply
    Commented Feb 14, 2013 at 19:18
  • 8
    You're right about using Id in C# (and .NET in general), but for a different reason. The rule is capitalizing all letters of a 2-letter acronym (e.g. IPAddress) and only capitalizing the first letter of longer acronyms (like the example of XmlDocument you gave). But Id and Ok are the exceptions to this rule, specifically mentioned. For the full brief, see the Capitalization Rules for Acronyms section of the Capitalization Conventions article. But even Microsoft breaks that rule (e.g. DbConnection vs. DBNull) Commented Feb 14, 2013 at 21:29

Consistency is king; pick one or the other, but do it consistently everywhere.

That said, I prefer the first variation, because it doesn't violate camelCase (doing so means you have two style rules to remember, not just one).

Two capital letters is sometimes used because of this, but an ID is really just a form of Id-entification.

  • 18
    I for one wouldn't like it if a computer program were trying to access my id.
    – Blrfl
    Commented Feb 7, 2013 at 18:17
  • 1
    userIdOfSender Commented Feb 7, 2013 at 18:39
  • 24
    @SeanMcSomething: Ick. SenderUserId Commented Feb 7, 2013 at 18:41
  • 6
    While I agree with you that "Id" is the preferred way I can see where the confusion comes in: In day-to-day conversation we actually say it as if it were an acronym, as in "can I see your I D?" Commented Feb 7, 2013 at 23:08
  • 3
    Look at other acronyms in camel case. There's SoapProtocol, not SOAPProtocol. ID is short for identity document, so I don't see why it should be treated in an exceptional fashion in camel case. That said, I'd prefer userID used consistently than userId and userID used inconsistently in my program.
    – Neil
    Commented Feb 8, 2013 at 10:20

TL;DR: In the context of .NET class libraries, Microsoft recommends that you use Id. This is slightly counter-intuitive, since it's a rare example of an abbreviation that is allowed / recommended (abbreviations are generally frowned upon).

If we're talking about C# or .NET class library conventions, Microsoft has some fairly well defined naming guidelines available. They are well thought out, with many explanations on a variety of issues - actually, every developer should take some time to read the entire Design Guidelines section.

When it comes to acronyms, the rule of thumb is: for two letter acronyms, you tend to keep them upper case (where Pascal case is applicable), so e.g. IOStream might be the name of a class. For a longer acronym, you lower case the rest of the acronym, e.g. XmlDocument or HtmlParser. This is actually a mostly unambiguous rule (there's no confusion as to where the one word ends and the next begins, unless you're chaining two-letter acronyms), and you get used to it very quickly.

So, is it ID, or Id? Well, according to Microsoft, it might not be what you think:

Acronyms differ from abbreviations in that an abbreviation shortens a single word. For example, ID is an abbreviation for identifier. In general, library names should not use abbreviations.

The two abbreviations that can be used in identifiers are ID and OK. In Pascal-cased identifiers they should appear as Id, and Ok. If used as the first word in a camel-cased identifier, they should appear as id and ok, respectively.

Anecdotally, I'm not actually sure when this distinction started appearing in the guidelines, but a few years back (around 3.0 / 3.5) the general naming trend in class libraries went from ID to Id.

  • 2
    This is the guideline I usually follow. Since id is an abbreviation and not an acronym, I always prefer to use 'Id'.
    – Toby
    Commented Feb 8, 2013 at 14:51
  • I use ID becuase then it breaks the convention and stands out as being unique, and i like the irony of that :)
    – user78252
    Commented Feb 8, 2013 at 15:17
  • 1
    I think Microsoft are wrong. I.D. is an initialism for Identity Document, it isn't short for identity. (Pedantically, acronyms are pronounceable.) Commented Feb 10, 2013 at 1:42
  • @TomHawtin-tackline You make an interesting point, although I suspect that it depends on the context. Something like an IDNumber property on a Person object would make a lot of sense, but for a VehicleId to read as "Vehicle Identity Document" versus "Vehicle Identifier"? In programming contexts, identifier is a pretty common word for anything which uniquely identifies an instance, and I'd argue that it's more applicable here.
    – Daniel B
    Commented Feb 11, 2013 at 7:15
  • 1
    Erm your own link says otherwise as OK stands for OLL KORRECT (and similar) and thus it is not an abbreviation. Okay is the phonetic version of OK (from oh kay)
    – Sklivvz
    Commented Feb 24, 2013 at 23:13

I read a very good explanation in some coding conventions' document. CamelCase should always be used for acronyms and abbreviations, because it is easier to distinguish word boundaries (compare XmlIdWriter to XMLIDWriter).

  • 16
    Here is an even better idea for distinguishing word boundaries: actual word boundaries! xml_id_writer.
    – Kaz
    Commented Feb 7, 2013 at 23:01
  • 5
    @Kaz Well, duh! However, CamelCase is used traditionally in some languages and it would look rather out of place to use underscores in such situations. Consistency is king, as mentioned earlier.
    – kgilden
    Commented Feb 8, 2013 at 10:38
  • 1
    Using CamelCase just because the core libraries of some language use it isn't consistency, but rather conformity.
    – Kaz
    Commented Feb 8, 2013 at 19:00
  • 5
    @Kaz: You have bigger battles to fight in your shop than code conventions. Commented Feb 13, 2013 at 16:22

As we can see in JavaScript's default function getElementById(); Id is written in Camel case...

Use 'id' if using with an underscore. Example: user_id

Use 'Id' if naming a var without any Underscore to differentiate the different words. Example: userId

If its a single word variable it should be in complete lowercase, if multiple word var then use lower Camel case. Example: thisIsExample

But I highly would not recommend 'ID' all in CAPS because we generally use all caps for defining CONSTANTS.

  • In your third paragraph, your example does not seem to match your text?
    – ruakh
    Commented Feb 8, 2013 at 17:33
  • @ruakh thanx.. Rectified.. Commented Feb 11, 2013 at 10:31
  • 2
    Except for XMLHttpRequest, encodeURIComponent, etc.
    – Yeti
    Commented Aug 25, 2020 at 16:27

First, eschew abbreviation.

Second, If the abbreviation is super well known, I recommend to use camel case.

That's because you're not need to consider the meaning of that. just treat as a normal word

Not the answer you're looking for? Browse other questions tagged or ask your own question.