views:

159

answers:

4

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

+2  A: 

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

Dean Harding
So I *am* undertanding the guidelines correctly?
bitbonk
@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.)
LukeH
+1  A: 

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

ŁukaszW.pl
+2  A: 

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.

chibacity
+5  A: 

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

LukeH
I want to stick to the recommendations of the Framework Design Guidelines. So it should be `EntityId`, `entityId`, `idOfEntity`?
bitbonk
@bitbonk: Since it is a property: `EntityId`
Albic
@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.)
LukeH
@bitbonk - 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.
Greg Beech
I wonder why MS is not sticking to this rules: `OleDbReader`.
bitbonk
@bitbonk - 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: http://msdn.microsoft.com/en-us/library/system.diagnostics.process.id.aspx, http://msdn.microsoft.com/en-us/library/system.threading.thread.managedthreadid.aspx, http://msdn.microsoft.com/en-us/library/system.threading.tasks.task.id.aspx
Greg Beech
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.
bitbonk
@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. http://blogs.msdn.com/b/sourceanalysis/archive/2008/05/25/a-difference-of-style.aspx
LukeH