45

I am in the process of unifying these inconsistent naming conventions and this one problem has been a bit driving me crazy lately.

In the code base I am working with has no convention regarding "ID"; "ID", "Id" and even "iD" are used inconsistently.

****Question**: In .NET, how do you guys capitalize "ID"? For an example, nodeID, nodeId? FolderID or FolderId?

****Edit**: How about plural cases? then should I do "NodeIDs" or "NodeIds"?

Thanks

5
  • Just keep in mind that variable naming and GUI labels follow different rules! On the GUI, it's ID and OK, not Id and Ok.
    – Jon B
    Feb 27, 2009 at 19:00
  • Why would GUI labels be different from other identifiers? Feb 27, 2009 at 19:05
  • They should all follow similar rules. This chaos you see is what happened before FxCop and Framework Design Guidelines were widespread inside Microsoft. You should use "Id" and "Ok" on all new code. See my answer for a link to my post where I talk about this more.
    – Jeff Moser
    Feb 27, 2009 at 19:05
  • I was trying to find the answer to this same question. Is it true that identification is another word for identity document? This would explain the "ID" acronym. Apr 29, 2009 at 15:19
  • As I write, this question is now nearly six years old. Please see my answer where I cite Microsoft's guidance for .NET Framework 4.5.
    – DavidRR
    Jan 22, 2015 at 19:26

7 Answers 7

85

Capitalization is for 2 letters acronyms. UI, IP, etc.

"Id" is an abbreviation for Identifier, so it should stay pascal cased.

12
  • 6
    In the plural case it's still no acronym, so I'd say "NodeIds". Feb 27, 2009 at 19:02
  • 2
    From where does the rule that an "abbreviation" "should stay pascal cased" come from? M-W and OED2 both call it an "abbreviation", for example, and both still use all-upper-case.
    – Ken
    Dec 10, 2011 at 1:28
  • 4
    This answer is supported by the Code Analysis in Visual Studio: "CA1709 : Microsoft.Naming : Correct the casing of 'ID' in member name 'InvoiceSearch.DeliveryID' by changing it to 'Id'. 'Id' is an abbreviation and therefore is not subject to acronym casing guidelines." Oct 22, 2012 at 11:08
  • 2
    It is also a recommendation in the general .NET naming conventions (msdn.microsoft.com/en-us/library/vstudio/…) Jan 29, 2014 at 1:41
  • 2
    @IlliaRatkevych, you might want to know the difference between abbreviation and acronym. The two examples you gave are both Acronyms, where each letter represents a word, and therefore both letters should be capitalized. An abbreviation is a shortened form of a single word, just like Id is "short for" Identification.
    – Zack
    Aug 29, 2014 at 13:16
39

Microsoft's naming guidelines suggest using all capitalized for 2 letter acronyms made into identifiers (IP, IO, UI, etc), so I tend towards "ID" (even though it's not an acronym) because when I read it, I still say the letters individually.

But honestly, I don't think Microsoft knows/knew what to do with ID/Id either:

ID

System.Runtime.InteropServices._Activator.GetIDsOfNames()
System._AppDomain.GetIDsOfNames()
System.Runtime.InteropServices._Attribute.GetIDsOfNames()
System.Type.GetTypeFromProgID()
System.Threading.Thread.ThreadID
System.Threading.Thread.GetDomainID()
System.Runtime.Serialization.ObjectHolder.ContainerID
System.Globalization.Calendar.ID
System.Globalization.CultureInfo.InvariantCultureID
System.Web.UI.Control.ClientID
System.Web.UI.Control.UniqueID

Id

System.AppDomain.GetCurrentThreadId()
System.AppDomain.GetIdForUnload()
System.AppDomain.IsDomainIdValid()
System.AppDomain.GetId()
System.Attribute.TypeId
System.TypeLoadException.ResourceId
System.Reflection.AssemblyAlgorithm.AssemblyAlgorithmAttribute.AlgorithmId
System.Runtime.Remoting.Lifetime.Lease.GetNextId()
System.Xml.Xpath.XPathNavigator.UniqueId
System.Data.OleDb.DBPropSet.PropertyId

(from http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/dcb8e08b-026a-4903-a413-7dbdda131a82/)

I guess that's why they invented intellisense...

In regards to pluralization: in my mind the s should always be lower-case.

6
  • It seems like "System.IO" is correctly while "System.Data.Common.DbDataReader" was misnamed according to the guideline - But is this widely accepted convention?
    – dance2die
    Feb 27, 2009 at 18:52
  • 3
    "Honestly, I don't think Microsoft knows what to do:" <- that is exactly the statement of mind I am in...
    – dance2die
    Feb 27, 2009 at 18:57
  • 2
    @Sung - Why do you say DbDataReader was misnamed? by the book Framework Design Guidelines mentioned by @Jeff Moser, they write that compound words written as a single word (such as 'endpoint') should be treated as a single word, therefore - Db is an abbreviation and not acronym and should be Db and not DB. If already talking about Microsoft not knowing what to do, what do you say about this one System.Data.OleDb.DBPropSet - Microsoft, please decide: Db or DB??
    – BornToCode
    Sep 17, 2014 at 7:20
  • @BornToCode - I am now getting lost... Even after 5 years I am still struggling with Db & DB.. I just stick with Db nowadays.
    – dance2die
    Sep 18, 2014 at 13:54
  • 1
    Two letter abbreviations are not acronyms, so they follow the convention rule for abbreviations, thus the reason that all newer APIs use Db and Id.
    – AaronLS
    Oct 7, 2020 at 18:13
36

Microsoft has updated its guidelines since this question was asked.

In the MSDN article Capitalization Conventions (.NET Framework 4.5), there is a section named Capitalizing Compound Words and Common Terms. Within the table in this section, the following capitalization guidelines are given for the abbreviation for "identifier" when naming identifiers:

  • When Pascal casing applies, use Id. (Example: System.Attribute.TypeId)
  • When Camel casing applies, use id. (Example: var id = 42;)
  • Never use ID.
9

The latest guidance is "Id", for more on this and others (e.g. "Ok"), see my post on the very latest Framework Design Guidelines (2nd edition)

5
  • 8
    Let's just go with "Okay" and make everyone unhappy :)
    – Jon B
    Feb 27, 2009 at 19:01
  • +1 Never heard of that book(Framework Design Guidelines) before. Let me check it out. Sounds like an interesting book to read. Thanks Jeff
    – dance2die
    Feb 27, 2009 at 19:02
  • Why is it UserName, FileName, but not HashTable? HashTable, Username, and Filename all make more sense to me.
    – Mike
    Feb 27, 2009 at 19:19
  • @Mike - I agree with Jeff Moser's convention but I would like him to explain as well. Perhaps we have to buy the book?
    – jpierson
    May 11, 2011 at 3:25
  • "Ok" should be capitalised "OK" since it's an acronym for "oll korrect".
    – Kevin
    Feb 3, 2014 at 9:42
6

I always capitalize ID when it is an abbreviation for identifier, etc. It just looks wrong and makes me think of Freud, otherwise -- which is definitely not a good thing.

5
  • 2
    Easy to call others humorless, hard to realize the joke is lame. :D Feb 27, 2009 at 19:05
  • 3
    I, too, tend to think of Freud when I see Id instead of ID for the abbreviation of identifier in a variable or function name. (@jfar and tvanfosson: I don't see it as a joke, just a statement of fact.) +1 for being on the same wavelength as me (and to offset that downvote).
    – RobH
    Feb 27, 2009 at 19:11
  • 2
    When you see Io, do you think of jupiter's moon? Feb 27, 2009 at 19:17
  • 2
    Actually I think of Shakespeare when I see it in SO, darn sans-serif fonts! bartleby.com/70/50007.html
    – tvanfosson
    Feb 27, 2009 at 19:23
  • Id up vote you on the Freud comment but I cannot agree with capitalizing ID yet. I'm still pulling a Microsoft and choosing whichever seems right today. Wish we could all settle on something.
    – jpierson
    May 11, 2011 at 3:16
2

If you would care to check the dictionary, you would find that ID is not treated as an abbreviation. In fact, the form is specified as ID or I.D. there. This is probably because it came from an expression like "Identity Documentation" or "Identification Data", and was not originally taken as a short form of "Identifier". Thus the form ID is not only recommended, but is directly supported by the dictionary.

3
  • Capitalization is for 2 letters acronyms. UI, IP, etc. "Id" is an abbreviation for Identifier, so it should stay pascal cased.
    – Nickolaus
    Feb 16, 2013 at 18:15
  • @Nickolaus: Douglas's point is that the word ID is listed in the dictionary (confirmed at least in Merriam Webster) all capitalized, rather that as Id.
    – Ergwun
    Apr 30, 2013 at 2:38
  • Let's see if I get some sort of necro badge for chiming in on this nine years later. Yes, the dictionary says "ID" (all caps) for an identifying DOCUMENT such as a driver's license or a passport. That is a physical thing. A document. In code, such as what we're discussing, there is no document. There is only a number or a GUID. We're not talking about an identifying DOCUMENT in this context. We're merely talking about an identiFIER. Totally different things.
    – Mel
    Apr 21, 2022 at 11:50
1

I think that the reason some people are using 'ID' instead of 'Id' is because it is a subset of 'GUID', 'UUID' or 'UID' that are generally capitalized.

I agree that it should be 'Id' but I think that it strongly depends on the context because in some environments it might be more appropriate to use 'ID'.

So to me 'ID' is a technical term and a subset of the above or used to refer either one of these technical terms whereas 'Id' is the shorthand to any kind of identifier and in a non-technical context when you need a person to read it like in your public APIs or UML you should (in my opinion) use 'Id'.

1
  • Nine years later, but why not chime in, right? If I wanted to get pedantic about things, I'd say that the acronym should be "GUId" or "UUId" then. Even more pedantically, if it's truly an acronym, then you wouldn't include ANY of the lower-case letters, and you'd be left with "UUI" (presumably pronounced "weeeeeee!", in an excited childlike tone) or "GUI" which is already taken and means "graphical user interface". Maybe that's why they threw the "D" on there to disambiguate.
    – Mel
    Apr 21, 2022 at 11:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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