The entire premise of the rant Larry O' Brien's rant seems flawed to me. He wrote
Billy Barrett writes:

I have come to the conclusion that writing a highly robust application with C# is nearly impossible because of [reasons such as...] you are catching the exceptions that are being thrown and then the person who wrote the component you are using adds a new exception. As you realize, they will more often than not forget to tell you and now you won't be handling it.

I can't think of a crisis scenario. <snip /> No code breaks that shouldn't
which mainly implies to me that he doesn't have a very active imagination. His mistake is assuming that if an API changes a method in a new release which results in a new exception being thrown then this scenario would be one that also would have thrown an exception in the earlier version or at least was unexpected. This is patently false. Here's a contrived example. Imagine the following V1 method
  
   //Converts an XHTML version of a Kuro5hin diary to an RSS feed.
   //Only supports versions 0.91 and 1.0 of RSS.
   //If an unknown version number supplied then it is ignored and an RSS 0.91 is generated.
   public static XmlDocument MakeRssFeed(XmlDocument k5diary, float version)

which is updated in V2 because too many users complained about the fact that an "incorrect" RSS feed was being generated to
  
  //Converts an XHTML version of a Kuro5hin diary to an RSS feed.
   //Only supports versions 0.91 and 1.0 of RSS.
   //If an unknown version number supplied then an UnknownRssVersionException is thrown
   public static XmlDocument MakeRssFeed(XmlDocument k5diary, float version)

Now most apps will probably never choke on the API because they only asked for a specific version of RSS like 0.91 or 1.0 on the other hand there would be apps that broke horribly after the update.

This isn't a good example and I could have spent more time coming up with a more realistic one but that isn't the point. The point is that simply assuming that the only way an API may add exceptions is in areas of new functionality is a faulty premise to build on.

However I don't agree with Billy Barrett that this means that C# can't be used to build robust applications because anyone who is building robust apps wouldn't upgrade the APIs their application was dependent upon without backwards-compatibility testing first. I believe it is highly unlikely that a backwards incompatible addition of an exception to an API method would go unnoticed by any development effort with sufficient resources dedicated to testing.

Note: The same problem can occur in Java if the dependent libraries are updated without recompiling the application which is a very likely scenario given the ease with which one can update JAR files in the CLASSPATH. This is because exception checking is done by the compiler not by the runtime [or at least that was the case in Java 1.3].
 

Categories:

Comments are closed.