ReSharper complains about uppercase "ID" in member "EntityID"
Asked Answered
J

4

27

I have a property "EntityID" in a class. Resharper (5.1) says

Name 'EntityID' does not match rule 'Methods, properties and events'. Suggested name is 'EntityId'.

But IMHO according to the naming conventions in the Design Guidelines for Class Library Developers. 'EntityID' should be perfectly fine:

  • Do not use acronyms that are not generally accepted in the computing field.
  • Where appropriate, use well-known acronyms to replace lengthy phrase names. For example, use UI for User Interface and OLAP for On-line Analytical Processing.
  • When using acronyms, use Pascal case or camel case for acronyms more than two characters long. For example, use HtmlButton or htmlButton. However, you should capitalize acronyms that consist of only two characters, such as System.IO instead of System.Io.
  • Do not use abbreviations in identifiers or parameter names. If you must use abbreviations, use camel case for abbreviations that consist of more than two characters, even if this contradicts the standard abbreviation of the word

*Update: * The latest version of the guidelines also say:

Do capitalize both characters of two-character acronyms, except the first word of a camel-cased identifier. A property named DBRate is an example of a short acronym (DB) used as the first word of a Pascal-cased identifier. A parameter named ioChannel is an example of a short acronym (IO) used as the first word of a camel-cased identifier.

Am I understanding the guidelines correctly? If so, how can I make ReSharper accept "EntityID" (well known two letter acronym) but reject "HTMLReader" (it should be HtmlReader).

Johnsten answered 28/7, 2010 at 8:58 Comment(2)
@Steve It's not, but it can be; I saw in another question someone mentioning that ID can be an acronym for Identity Datum, so it's still valid.Br
Related: ID (and its variations) in a User Interface.Karena
E
24

Do you want to stick to the recommendations of the Framework Design Guidelines, or do you want to use uppercase ID regardless?

The latest version of the guidelines has this to say:

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.

So it seems that ReSharper is correct in the case of Id.

Out of interest, ReSharper also recommends that two character acronyms follow the same casing rules. This is at odds with the guidelines: "Do capitalize both characters of two-character acronyms, except the first word of a camel-cased identifier."

Extramundane answered 28/7, 2010 at 9:15 Comment(12)
I want to stick to the recommendations of the Framework Design Guidelines. So it should be EntityId, entityId, idOfEntity?Johnsten
@bitbonk: Since it is a property: EntityIdDowie
@bitbonk: The answer is yes, because Id is an abbreviation. (Watch out though, because ReSharper also recommends that two character acronyms -- for example, DB -- are pascal-cased too, which is not what the guidelines recommend.)Extramundane
@Johnsten - LukeH is right; the correct capitalization is Id not ID. If you want to convince yourself, you only have to look through the base class library and you'll see that Id is almost ubiquitous, except for a few cases that slipped through the net.Beeman
I wonder why MS is not sticking to this rules: OleDbReader.Johnsten
@Johnsten - Not sure what that link is supposed to illustrate? There is no Id property on that class. If you mean the fields in the SELECT statement then that's not a good example because those are from a database where different naming conventions may apply. Look at things like: msdn.microsoft.com/en-us/library/…, msdn.microsoft.com/en-us/library/…, msdn.microsoft.com/en-us/library/…Beeman
Db is a two letter acronym according to the guidelines. And two letter acronyms are to be written upper case. Do capitalize both characters of two-character acronyms (see above update) So OleDb* is wrong.Johnsten
@bitbonk: I suppose that the teams within Microsoft don't always adhere to the guidelines all the of the time, especially in the past when the guidelines weren't as well-established. blogs.msdn.com/b/sourceanalysis/archive/2008/05/25/…Extramundane
it seems to me that Db is an abbreviation for database (one word). IO is a two letter acronym for Input Output (two words) From wikipedia: "An acronym is an abbreviation formed from the initial components in a phrase or a word. " So I guess its kinda hard to make a distinction between abbreviation and acronymMolehill
@Extramundane Isn't DB actually an abbreviation though, rather than an acronym? I would use "database" rather than "data base" if I was writing English, therefore R# is correct, I think.Octofoil
@Extramundane what about ViewModels in MVC, are we supposed to call them EntityVm now?Croy
MySQL is mysql or MySQL, not Mysql or mYSQL, the naming rule have wrong suggestion for brand namesWept
G
49

If you wish ReSharper to have "ID" as a valid abbreviation for "Identity" then simply select the Property, press "Alt-Enter" and then select "Add 'ID' to the abbreviations list" from the ReSharper context-menu.

Gazzo answered 28/7, 2010 at 9:14 Comment(2)
awesome, I'm dealing a lot of acronyms (SMS, XML, SCAC, DOT, TLA) and this was getting annoying trying to ignore all the warnings. completely missed this resharper option when clicking on the resharper diamond on the side.Tilt
This does not appear to stop R# from complaining about ID when in parameter lists.Margalit
E
24

Do you want to stick to the recommendations of the Framework Design Guidelines, or do you want to use uppercase ID regardless?

The latest version of the guidelines has this to say:

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.

So it seems that ReSharper is correct in the case of Id.

Out of interest, ReSharper also recommends that two character acronyms follow the same casing rules. This is at odds with the guidelines: "Do capitalize both characters of two-character acronyms, except the first word of a camel-cased identifier."

Extramundane answered 28/7, 2010 at 9:15 Comment(12)
I want to stick to the recommendations of the Framework Design Guidelines. So it should be EntityId, entityId, idOfEntity?Johnsten
@bitbonk: Since it is a property: EntityIdDowie
@bitbonk: The answer is yes, because Id is an abbreviation. (Watch out though, because ReSharper also recommends that two character acronyms -- for example, DB -- are pascal-cased too, which is not what the guidelines recommend.)Extramundane
@Johnsten - LukeH is right; the correct capitalization is Id not ID. If you want to convince yourself, you only have to look through the base class library and you'll see that Id is almost ubiquitous, except for a few cases that slipped through the net.Beeman
I wonder why MS is not sticking to this rules: OleDbReader.Johnsten
@Johnsten - Not sure what that link is supposed to illustrate? There is no Id property on that class. If you mean the fields in the SELECT statement then that's not a good example because those are from a database where different naming conventions may apply. Look at things like: msdn.microsoft.com/en-us/library/…, msdn.microsoft.com/en-us/library/…, msdn.microsoft.com/en-us/library/…Beeman
Db is a two letter acronym according to the guidelines. And two letter acronyms are to be written upper case. Do capitalize both characters of two-character acronyms (see above update) So OleDb* is wrong.Johnsten
@bitbonk: I suppose that the teams within Microsoft don't always adhere to the guidelines all the of the time, especially in the past when the guidelines weren't as well-established. blogs.msdn.com/b/sourceanalysis/archive/2008/05/25/…Extramundane
it seems to me that Db is an abbreviation for database (one word). IO is a two letter acronym for Input Output (two words) From wikipedia: "An acronym is an abbreviation formed from the initial components in a phrase or a word. " So I guess its kinda hard to make a distinction between abbreviation and acronymMolehill
@Extramundane Isn't DB actually an abbreviation though, rather than an acronym? I would use "database" rather than "data base" if I was writing English, therefore R# is correct, I think.Octofoil
@Extramundane what about ViewModels in MVC, are we supposed to call them EntityVm now?Croy
MySQL is mysql or MySQL, not Mysql or mYSQL, the naming rule have wrong suggestion for brand namesWept
F
10

The simplest solution would be to go into ReSharper Options, under the "C# Naming Style" tab, make sure "Override common settings" is selected and then double-click "Methods, properties and events". Click on "Add" to add a new one and set it to "UpperCamelCase" with a Name Suffix of "ID".

Add additional suffixes as you like.

You can also do it with the "Advanced settings..." button on the "C# Naming Style" page, which gives you a lot more flexibility, but I wouldn't bother with that...

Fluency answered 28/7, 2010 at 9:4 Comment(1)
@bitbonk: No, you're not! Since ID and OK are abbreviations then, according to the guidelines, they should be pascal-cased as Id and Ok respectively. ReSharper is right about this. (However, ReSharper is wrong when it comes to two character acronyms (for example DB). According to the guidelines, two character acronyms should be all uppercase, but ReSharper recommends that they are pascal-cased too.)Extramundane
T
5

What about "Add 'ID' to the abbreviations list" ??

Tamelatameless answered 28/7, 2010 at 9:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.