views:

944

answers:

9

Pretty simple question: When i have a persistable object, it usually has a property called ID (for abstract classes).

So .. is the naming convention ID or Id?

eg.

public int ID { get; set; }

or

public int Id { get; set; }

cheers :)

PS. This is for .NET btw. FXCop conformat would be a bonus.

A: 

I prefer ID, also in combination with other words (e.g. CustomerID), but strictly speaking that is against the regular naming conventions.

Treb
+2  A: 

We use ID internally, because Id seems to me like psychology speak, but FxCop complains, as ID is not an acronym, its an abbreviation (for Identity/Identifier). According to the FxCop rule, only acronyms that are two characters long are allowed to be all caps. Everything else should be Proper case.

We put a SuppressMessage attribute on the ID property, and everyone is happy.

Ch00k
+4  A: 

Whatever you like it to be, just be consistent. ID is not a word, it's an abbreviation of identity. How to write abbreviations is something people argue about for a long time. E.g. is it

getResourceURL

or

getResourceUrl

actually both can be found in use in different frameworks. Another popular abbr. with similar problem is UTF8.

It's just important to be consistent, because otherwise people always have to look up the correct capitalization for every method, if every method handles it in a different way.

I have my own convention for that. If the abbr. is at the end of the name, it is all capitalized, if it's somewhere else, it follows camel notation rules. E.g.

getResourceURL
urlOfResource
compareUrlToString

Why? I like abbr. to be capitalized. Most people expect URL or UTF to be capitalized. However, if in the middle of a name, it destroys the advantage of camel notation. The advantage of camel notation is that you see where a new word starts by capitalization. So compare:

compareURLToString
compareUrlToString

In the first case, I don't see immediately the URL is one word and To is the next one. The T might be part of URL (URLT) and be a different abbr., thus I'll use the second form. If it's at the end however, it won't play a role, no other word follows, thus I prefer the capitalized form. I stick to this convention throughout all of my code.

Mecki
+18  A: 

I usually go with Identifier. If I really want to keep it short (as part of a longer identifier, for example), I use Id, unless it's a parameter or private member.

The .NET Framework Naming Guidelines say this:

An acronym is a word that is formed from the letters of words in a term or phrase. For example, HTML is an acronym for Hypertext Markup Language. You should include acronyms in identifiers only when they are widely known and well understood. 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.

OregonGhost
A: 

We around here see things like "Id" or other acronyms as a word, and "Id" is the easy one because in the banking business we do get lots of strange letter combinations. So we treat it as a word, only with the first letter capitalized, and that's how we ended up being defined in our internal coding conventions paper.

But the bottom line is: choose what convention is more comfortable for the developer team and other people that look at the source code and stick with it.

t3mujin
+6  A: 

The guidelines say "Id".

Fortunately the the .Net guys were king enough to give us "naming guidelines" and not "naming laws" ;), so basically if you strongly feel that breaking a guideline rule does add more value than following it, then by all means break it, no one will take you accountable for it if they understand your reasons (like it provides more readability and accentuates the meaning of the name)

In my shop we use 'ID' even if the guidelines say 'Id', but no one, really feels guilty about it.

Pop Catalin
+3  A: 

As others pointed out, Id is right according to .NET conventions, but somehow it doesn't feel right, so many people use ID (and still live).

I don't know what the content of your field will be (numbers, strings, guids), but if you want to skip the problem you may simply use another .NET convention for object identifiers: Name

Filini
A: 

"ID" is one of abbreviations hardcoded in FxCop naming rules that are always considered wrong spelled even if they are parts of other words. The only way I found to override it is adding "ID" to Acronyms as (): ID

It worked with FxCop 1.36. P.S. In general, I think that "Id" is a better alternative but sometimes it's impossible to change a name if it's generated based on XML files (or web services) which we don't control

Oups, it cut all tags.. It should be Acronym with "ID" content in Acronyms/CasingExceptions
A: 

http://en.wiktionary.org/wiki/id#Abbreviation

Why fight it?

rnell