5

I know it sounds silly, but in regards to CA1709, should we ignore this error and just do what Microsoft did (which is use Db as the acronym for Database)?

Just wondering what people out there are doing. To me, it seems silly to use DB when Microsoft uses Db all over the place.

TrueWill
  • 25,132
  • 10
  • 101
  • 150
myermian
  • 31,823
  • 24
  • 123
  • 215
  • 2
    Personally I think the "Uppercase two letter acronyms" rule is stupid, since it loses information about where the different parts of an identifier start. – CodesInChaos Jul 14 '11 at 21:56
  • 1
    @CodeInChaos - as @ChrisWue points out, it's about consistency. Nearly every standard is stupid, arbitrary, or both in some case. Microsoft put a lot of time and research into theirs, and staying reasonably close to it results in a codebase familiar to a large number of developers. (My two cents.) – TrueWill Jul 14 '11 at 22:10
  • 1
    Then you lose the ability to automatically transform to a different convention. One application of this is json serialization where the convention is usually to separate different words with an `_`. – CodesInChaos Jul 14 '11 at 22:18

2 Answers2

8

Quoting Brad Abrams in the excellent Framework Design Guidelines:

...I have heard every possible excuse for violating these naming guidelines. [...] For the most part, our customers have seen the places in which we have diverged from these guidelines (for even the best excuse) as warts in the Framework.

In other words, do as they say, not as they do. :)

Also, 'Db' is an abbreviation, not an acronym. Database is one word. Abbreviations should never be used in identifiers per the Guidelines. ('Id' is a special case.)

Sadly the CA1709 link lists 'DB' as an example. :(

TrueWill
  • 25,132
  • 10
  • 101
  • 150
  • So, is your answer stating that it should be 'DB' or 'Db'? – myermian Aug 17 '12 at 23:15
  • @m-y It should actually be "Database" per the Microsoft guidelines (which Microsoft doesn't always follow). I'd probably go with "Db" as in System.Data.Entity.DbContext - but as ChrisWue states, pick a standard for your team and be consistent. – TrueWill Aug 20 '12 at 16:44
  • Can you link to these guidelines, I could not find the actual link that states to use the full name 'Database' anywhere. – myermian Aug 20 '12 at 17:38
  • There's [Capitalization Conventions](http://msdn.microsoft.com/en-us/library/ms229043.aspx), but I'd suggest buying the book (see link in my answer). There's so much more good advice in there. – TrueWill Aug 21 '12 at 01:15
  • The two letters 'Db' should be an exception in the same way that Id is. I always wondered who create the class 'DBNull', which stands as an exception across all our APIs. – divega Aug 08 '13 at 17:45
5

It doesn't really matter, does it? Choose what you like best - but then make sure you use it consistently. With coding and naming conventions it's mainly about choosing one you like and be consistent

ChrisWue
  • 18,612
  • 4
  • 58
  • 83