Nov 18, 2014

.NET is Open Source

Well, the trend of the latest years resulted in .NET going open source. That is pretty amazing, now it is possible to see what is there under the hood, without searching info in blogs and Q&A.
We've got reference source repository, which is intended to serve as a reference, located at https://github.com/Microsoft/referencesource
The new development will be in https://github.com/dotnet/corefx, it already has some libraries uploaded and the rest will come soon.
I decided to take a look into reference source, and the first place I went to was mscorlib assembly. Some notes on internals:
  • Extensive use of Code Contracts there
  • Some of the classes` internals do not match coding standards (or I comprehended the rules incorrectly)
  • There is non-generic static class Nullable :) that is a container for static methods operating on nullables. I’m just curious what is the reason having it? There is no such thing for DateTime, for example.
  • mscorlib, System.Web, System.ServiceModel are the monsters, taking more than 17 Mb of code each.
  • largest file with code is System.Web.Services\System\Web\Services\Description\ServiceDescriptionSerializer.cs which seems to be obfuscated. It takes about 668KB.
  • Task class is more than 6600 LOC
  • Not only XML verbose, but its handling routines also – XLinq.cs from System.Xml.Linq\System\Xml\Linq has over 9k LOC and 390 KB size. It’s actually 3rd biggest file that contains code.
What's interesting is that it is now easier to go and look at what the class does inside in case of any doubts. From the other hand, that is an abstraction leak - you are not supposed to take into account actual implementation. However, according to a law of leaking abstractions, sometimes that’s inevitable.