One of our coding standard ‘rules’ is:
- Use the common type system. For example, use
Int32instead ofint.
I have not seen a similar rule before, although our other guidelines are roughly based on Microsoft’s Design Guidelines Digest. It doesn’t seem like what the Common Type System is, either.
I find it inconvenient as I end up having to rewrite default Visual Studio and ReSharper refactorings to convert string to String, float to Single, long to Int64 etc.
It’s also applied fairly inconsistently (e.g. not for object to Object), possibly as a consequence of its inconvenience, and no StyleCop rule exists to check it is applied.
I am therefore wondering why this rule was ever set. Could there be a good reason? Are there any cases (perhaps historical) where Int32 must be used instead of int for example?
Update:
I read through the recommended Framework Design Guidelines (2006, Cwalina & Adams) section 3.2.3 Avoiding Language-Specific Names and they state “it is important to avoid the use of these language-specific type names in identifiers” (my emphasis). Agreed.
However, Jeffrey Richter then goes on to comment “I take this a step farther and never use the language’s alias names [as it] adds nothing of value and introduces enormous confusion“.
Perhaps this is where this rule has come from?
I suspect this rule comes from a misinterpretation of the framework guidelines.
The guidelines say in the General Naming Conventions section:
If you create identifiers which contain a type as part of their name, for example a set of
SomeType ReadSomeType()methods, then you should use the actual type name forSomeTypeand not the C# alias.A programmer who works in a different language might associate different meanings with a type. For example if you had a
ReadFloat()method, a C# programmer would assume it returnsSystem.Single, and a F# programmer would assume it returnsSystem.Double. So you should name itReadSingleorReadDouble.This rule does not apply to the simple type names you use to refer to a type in your code. A programmer consuming your library will never see which for you used.