Spec#: should we really wait for it?
Julien on May 13th 2008
A friend of mine just posted about his desire to have Spec# ready for production. Funnily, many people in Alt.net expressed a similar desire in the past weeks (See that or that).
I don't have any problem with Spec#. On the contrary, I believe that it's a great addition to the language, one that would result in a significant improvement in code quality. However, I also don't think we should expect anything soon for various reasons:
- Spec# is only a research project. Even if Microsoft did publish previews, I don't think they've communicated any plan to have a RTM yet.
- Spec# is an addition to C#. However, there's now a lot more than C# in .NET, and I think that it would be problematic to add this feature to C# and not to vb.net for instance (which is, believe it or not, more used than C#). Actually, what happens if you build an assembly with Spec# and use it from C#/Vb.net? I don't have any clue but it would be interesting to know.
- It will be difficult for Spec# to enter mainstream, enterprise will be reluctant to migrate to it. Moving from .NET 2.0 to .NET 3.5 is absolutely painless and still, do you know many companies that are actively working with .NET 3.5?
- Spec# adds several new keywords which will be as many new concepts to understand before being able to work with it. With the recent additions to the framework, I'm starting to consider that there's already too much to learn for the average developer! Just an example: how many of your colleagues know what's the meaning of the "??" operator in C#? Or another one: I had to explain what was a Nullable only a few days ago :). If you add Linq, WCF, WPF, Entity Framework...
The bottom line is that I believe that we should focus our efforts on improving the way we do defensive programming with the framework as it is, and not hope for a white knight. Even if they are not perfect solutions, I think we can cover a lot of ground by systematically checking the inputs, checking the post conditions/side effects with unit testing, and checking that our object are satisfying invariants.
Filed in .NET | One response so far
The .Net Frog is also available in french at:
Greg Young May 17th 2008 at 01:45 am 1
I can’t speak for everyone but for myself I am not actually wanting spec# per se… I am much more interested in having Boogie and all of the contracts for the framework. Any language could feasibly allow instrumentation of IL to include contracts that a theorem prover could understand.
You are correct that migrations will take a long time (especially for the ultra buggy code sitting in the mainstream today). The best way to help move towards it is as you say to start writing better defensive code today. Not only will your code be better but it will be quite easy to refactor your pre/post conditions to a similar system.
One side note, everyone seems to test pre-conditions to be true but I rarely see people verifying their post conditions with an if statement in their code which is just as important.
Cheers,
Greg
*leaving another comment on invariants post*