.NET naming convention for “ID” (anything identification: Capitalization)

前端 未结 7 791
情歌与酒
情歌与酒 2021-01-31 08:52

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

相关标签:
7条回答
  • 2021-01-31 09:04

    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.
    0 讨论(0)
  • 2021-01-31 09:15

    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.

    0 讨论(0)
  • 2021-01-31 09:15

    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.

    0 讨论(0)
  • 2021-01-31 09:16

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

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

    0 讨论(0)
  • 2021-01-31 09:17

    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)

    0 讨论(0)
  • 2021-01-31 09:19

    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'.

    0 讨论(0)
提交回复
热议问题