I was recently browsing thecode source of Managed Extensibility Framework and realizedthat this future part of .NET 4, full of tricky and advanced ideas, was naively relying on stringsto describe files and directories paths. It seems that the version 4 of .NET willmiss the need for a descent path API. There is the class System.IO.Pathbut it is feature limited, full of flaws and pitfalls (to not say bugs) and it fostersusers to encode their paths into raw strings. It seems to me that using strings to encode paths is as primitive as using String.IndexOf("") to parse some XML.



As many other applications,the tool NDepend needsto perform many complex paths operations. This includes:
  • Relative / absolute pathconversion + Path rebasing.
  • Path normalization API
  • Path validity check API
  • Path comparison API
  • List of path operations(TryGetCommonRootDirectory, GetListOfUniqueDirsAndUniqueFileNames, listequality…)
In mid 2007, during the development of NDepend we came to thepoint where relying on the naïve and flawed System.IO.Pathwas just not acceptable anymore. We then invested a few weeks in building ourown strong-typed path library NDepend.Helpers.FileDirectoryPath,that we released Open-Source on CodePlex. The library is bug-free (at leastthere is no known bug) 100% covered by tests but still, it didn’t attract the mass (only 477downloads in 14 months). Moreover I don’t know any other equivalent library (doyou know any?).



The conclusion isthat in 2009 and beyond, doing something as mainstream as handling pathsoperations in .NET, will still be a pain!







This reminds me the C#non-nullable types debatewhere half of the bugs in .NET code still comes from the pesky NullReferenceException.IMHO concerning this issue, the future .NET 4 contracts APIwill help a bit, but certainly not as much as a proper non-nullable strongtyping integration at language and platform level. Sadly, Anders Hejlsbergrecognized that the absence of non-nullable types is their biggest mistake indesigning C# and .NETand cut any hope for seeing them one day.



A.H: You sort of end up going, well ok,if we ever get another chance in umpteen years to build a new platform, we’lldefinitely get this one (i.e non-nullable types) right.



The problem is that bothMicrosoft and its partners have now capitalized for almost a decade in .NET and won’tlikely shift to another platform before a very long time. Maybe I am narrow-mindedbut I really can’t think of the post .NET era.
  • The last years shown that investment in research and innovation from the Javaworld cannot compare to what MS is doing. Since LINQ in 2007 and even.NET generics in 2005, Java doesn't lead the way anymore in technicalinnovation and they won’tlikely be able to change this trend.
  • Microsoft investsmassively into .NET for all its own products and it looks like it is just thebeginning. I can’t think of Microsoft replacing .NET with something else soon!
  • And except the Java communityor Microsoft, who else is able today to produce a mainstream platform?
Debug.Assert(… != null); or if you prefer CodeContract.Requires(… != null) will continue to be our friends for a very, very long time.







More...