Legacy Guidelines

Microsofts coding guidelines seem to be long outdated - why aren't they changing them?

During the MVP Summit I heard some statement that gave me shivers: "We need to replace the var as we want to mention the type explicitly". I don't even know where to start complaining about this statement...

Long story short this style guide from Microsoft should never have found its way out of Microsoft. Microsoft should admit now that using var is a best practice and everything that can be var should be var. There is no excuse for making code more cluttered and harder to read. Harder I wrote? Yes. I do not care if the result of calling a function is Foo or Bar. I just want to know what and how result is used. For everything else I would need the IDE / extended knowledge anything.

The old argument is that if Foo or Bar is stated then I know that without having an IDE. Come on, what a weak argument is that? Especially, since that still does not give me the knowledge what Foo or Bar is. So as long as I have not memorized Foo or Bar the information that result is either Foo or Bar is useless to me. Furthermore, when result is used as an argument for another function, I would still need to know if that argument needs to be of type Foo or Bar. Again, the knowledge I have (result being Foo or Bar) is useless.

On the other hand, however, keeping types implicit (i.e., making use of the compilers type inference) will result in additional robustness regarding refactoring. It does not matter if result is Foo or Bar, it just matters if it is compatible in further usage. So changing Foo to Bar should make no difference if the usage is agnostic to it. If I use explicit typing I will hit problems that do not help me in making things compatible or solving incompatibilities. Instead, I need to change some characters (i.e., change lines of code) without any real world contribution. This is the definition of unnecessary clutter.

Microsoft I would appreciate if you could get over your style guide and change it for the sake of saving keystrokes in multiple scenarios. Either write nothing or state the right thing. Thanks!

Remark: The C# and VS team is well aware of this. They also believe in the freedom of choice. Therefore, we can now also set the implicit typing as default, which transforms the standard light bulb to fix implicit to explicit typing into the opposite direction (one fix to make all unnecessary explicit occurrences go away).

Created .

References

Sharing is caring!