If you are a regular reader of this weblog, you know that I have a high respect
for Anders Hejlsberg and his work (current and past). Overall, his stance
on various issues is very pragmatic and fairly well articulated. However,
I find myself disagreeing on two of the issues discussed in the latest parts of
these interviews, namely:
- Why C# methods are not virtual by default.
- Why C# doesn’t support checked exceptions.
What strikes me in Anders’ interviews is that while he gives numerous
technical reasons for these choices, he omits to mention what I think
is the principal motivation: the necessity for cross-language
C# runs on the CLR and has therefore to obey constraints that are sometimes
non negotiable. The CLR was built to be cross-language, and as such, it
also has to support C++ and Visual Basic, none of which support checked exceptions
and I don’t really understand why Anders never even mentioned that
these requirements weighed heavily on the design decisions involving these two
As for the age-old debate "checked exceptions versus runtime
exceptions", I refer you to the
current TheServerSide thread which contains a
lot of interesting articles (especially Mike Spille’s).
As for the question "should methods be virtual by default?",
it’s close to a religious issue but I’ll share a few thoughts.
The way I see it, code can be extensible in two ways: "by
design" and "technically".
Being "technically extensible" means that the language and tools
you are using give you the power to extend the code without any workaround.
Languages that are on the "virtual by default" side tend to produce code that is
more technically extensible than others.
If the code is extensible "by design", the extension points and
their contracts have been thoroughly tested and documented.
It’s very rare to find code that is extensible both technically
and by design, but in my experience, at least if it is technically extensible, I can
find ways to work around the absence of design. If you mark your method
private or final, I am left with no options at all.
As for James Gosling’s interview, I highly recommend it, it’s
filled with very sensible advice about why checked exceptions are a good thing.
My favorite part is:
It really is a culture thing. When you go through college and
you’re doing assignments, they just ask you to code up the one true path. I
certainly never experienced a college course where error handling was at all
James talks about the "creepy feeling" you should have when you
write code that downplays the importance of errors and argues that with checked
exceptions, you can’t escape that feeling: you have to face it.
And I think it’s a good thing.