views:

818

answers:

5

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

+6  A: 

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.

Daniel LeCheminant
It seems like "System.IO" is correctly while "System.Data.Common.DbDataReader" was misnamed according to the guideline - But is this widely accepted convention?
Sung Meister
"Honestly, I don't think Microsoft knows what to do:" <- that is exactly the statement of mind I am in...
Sung Meister
+16  A: 

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

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

Romain Verdier
How about plural cases? then should I do "NodeIDs" or "NodeIds"?
Sung Meister
In the plural case it's still no acronym, so I'd say "NodeIds".
Tom Lokhorst
+3  A: 

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)

Jeff Moser
Let's just go with "Okay" and make everyone unhappy :)
Jon B
+1 Never heard of that book(Framework Design Guidelines) before. Let me check it out. Sounds like an interesting book to read. Thanks Jeff
Sung Meister
Why is it UserName, FileName, but not HashTable? HashTable, Username, and Filename all make more sense to me.
Mike
+2  A: 

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.

tvanfosson
Nice downvote from the humorless...
tvanfosson
Easy to call others humorless, hard to realize the joke is lame. :D
jfar
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
When you see Io, do you think of jupiter's moon?
Daniel LeCheminant
Actually I think of Shakespeare when I see it in SO, darn sans-serif fonts! http://www.bartleby.com/70/50007.html
tvanfosson
A: 

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.

Josiah Ruddell