Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the proper naming convention for a property 'ID' : ID or Id?

Tags:

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.

like image 719
Pure.Krome Avatar asked Nov 05 '08 10:11

Pure.Krome


People also ask

Which is correct ID or ID?

The correct one is "Id". "ID" appears to be an acronym of two words, though there is only one word, "identifier".

Should ID be capitalized in code?

If you are a programmer and you are referring to the row number of a record in a table, then you are referring to a Unique identity or Unique identifier, both of which can be referred to an Id. Because the letters are only representing a single word the "d" should never be capitalized.

What are some conventions for naming identifiers?

There are some rules you have to follow for naming identifiers: The first character of the identifier must be a letter of the alphabet (upper or lowercase) or an underscore ('_'). The rest of the identifier name can consist of letters (upper or lowercase), underscores ('_') or digits (0-9).

How do you name ids and classes?

Always favor lowercase, for elements, for attributes and their values, for classes and ids. Multi-word names for classes and ids should either 1., concatenate the words in lowercase without any in-between character, or 2., separate each word with a "-" (not "_") and maintain lowercasing throughout.


1 Answers

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.

like image 101
OregonGhost Avatar answered Oct 16 '22 18:10

OregonGhost