Efcore: Question: style guide for abbreviations

Created on 2 Feb 2017  路  4Comments  路  Source: dotnet/efcore

I noticed that EntityFramework does not follow the Microsoft guideline:
Capitalization Conventions

A special case is made for two-letter acronyms in which both letters are capitalized, as shown in the following identifier:
IOStream

DbSet, DbContext should be written as DBSet, DBContext. Examples: IDataRecord.IsDBNull, System.DBNull.

Another example:

c# public static partial class EF

It should be written as Ef, if another guidelines are used.

However, I did not find any info that Microsoft team has changed the capitalization rules. The document has no any description about it:
https://github.com/dotnet/corefx/blob/master/Documentation/coding-guidelines/coding-style.md

Can you clarify ASP.NET team position about 2-letter acronyms?

StyleCop and CodeFormatter have no special rules for this case.

SonarQube has a wrong rule S101:

warning S101: Rename class "RabbitMQTest" to match camel case naming rules, consider using "RabbitMqTest".

closed-question

Most helpful comment

Even within our team there isn't full agreement on this, but personally I am used to "EF" for the initials in "Entity Framework", which I think happens to align unambiguously with the original .NET Framework guidelines that rule the majority of the type names in .NET. For what it is worth, "Db" as a prefix works for me because I tend to think about it as the super common abbreviation of the compound word "database" as opposed to the initials of "data base".

All 4 comments

@dermeister0 We try to select the best names we can based on:

  • Historical context--how similar and related classes have been named in the past
  • Communicating the semantics and use of the type
  • Style guidelines
  • .NET community conventions (which can be different from Microsoft style guidelines)
  • Some hard-to-quantify element of what is aesthetically pleasing

The primary reason DbContext got the casing it did was to align with existing classes like DbConnection. Since then the casing has remained for historical consistency and to prevent breaking changes. It is unfortunate that some types, like DBNull, got casing that is inconsistent with this, but that is a long way in the past now.

With regard to EF, we did discuss this at length but despite Ef being more consistent with the Db names (and some other things) the consensus was that "EF" better communicated the intent of the class and worked better in the way it is typically used.

Thanks for your answer.

We have a utility library for EntityFramework. It's called Company.Tools.Ef6.dll and has classes EfSession, EfSessionFactory. EfUnitOfWork, etc.

Do you think it would be better to use EFUnitOfWork, EFRepository style to be consistent with EntityFramework naming?

Even within our team there isn't full agreement on this, but personally I am used to "EF" for the initials in "Entity Framework", which I think happens to align unambiguously with the original .NET Framework guidelines that rule the majority of the type names in .NET. For what it is worth, "Db" as a prefix works for me because I tend to think about it as the super common abbreviation of the compound word "database" as opposed to the initials of "data base".

Got it. Db word may be part of the Capitalizing Compound Words and Common Terms table, it makes everything consistent.

Was this page helpful?
0 / 5 - 0 ratings