Info-Tech

The Effort with Checked Exceptions (2003)

The Effort with Checked Exceptions

A Dialog with Anders Hejlsberg, Piece II

by Invoice Venners with Bruce Eckel

August 18, 2003


Summary

Anders Hejlsberg, the lead C# architect, talks with Bruce Eckel and Invoice Venners about versionability and scalability disorders with checked exceptions.


Anders Hejlsberg, a favorite engineer at Microsoft, led the crew that designed the C# (pronounced C Spicy) programming language. Hejlsberg first vaulted onto the instrument world stage in the early eighties by establishing a Pascal compiler for MS-DOS and CP/M. A actually young firm called Borland rapidly hired Hejlsberg and offered his compiler, which modified into as soon as thereafter marketed as Turbo Pascal. At Borland, Hejlsberg continued to create Turbo Pascal and at closing led the crew that designed Turbo Pascal’s change: Delphi. In 1996, after 13 years with Borland, Hejlsberg joined Microsoft, where he on the origin labored as an architect of Visual J++ and the Home windows Foundation Classes (WFC). Subsequently, Hejlsberg modified into as soon as chief style designer of C# and a key participant in the creation of the .NET framework. At this time, Anders Hejlsberg leads the ongoing constructing of the C# programming language.

On July 30, 2003, Bruce Eckel, creator of Pondering in C++ and Pondering in Java, and Invoice Venners, editor-in-chief of Artima.com, met with Anders Hejlsberg in his convey of work at Microsoft in Redmond, Washington. In this interview, which is in a dilemma to be printed in a pair of installments on Artima.com and on an audio CD-ROM to be released this drop by Bruce Eckel, Anders Hejlsberg discusses many extinguish choices of the C# language and the .NET framework.

  • In Piece I: The C# Originate Route of, Hejlsberg discusses the system aged by the crew that designed C#, and the relative deserves of usability studies and honest taste in language extinguish.
  • In this 2nd installment, Hejlsberg discusses versionability and scalability disorders with checked exceptions.

Bruce Eckel: C# would not believe checked exceptions. How did you in deciding whether or no longer or now to not attach checked exceptions into C#?

Anders Hejlsberg: I overview two gigantic disorders with checked exceptions: scalability and versionability. I do know you would also believe written some about checked exceptions too, and you have a tendency to believe our line of thinking.

Bruce Eckel: I aged to center of attention on that checked exceptions had been in actuality considerable.

Anders Hejlsberg: Exactly. Frankly, they discover in actuality considerable up front, and there’s nothing injurious with the concept that. I entirely agree that checked exceptions are a aesthetic characteristic. It be fair that explicit implementations would perchance be problematic. By enforcing checked exceptions the ability or no longer it is finished in Java, for example, I center of attention on you fair take one residence of problems and substitute them for one more residence of problems. In the pause or no longer it is no longer clear to me that you indubitably create life any more easy. You fair create it different.

Bruce Eckel: Used to be there a lot of contrast in the C# extinguish crew about checked excpetions?

Anders Hejlsberg: No, I center of attention on there modified into as soon as moderately sizable settlement in our extinguish community.

C# is de facto silent on the checked exceptions subject. Once a higher retort is identified—and belief me we continue to take into story it—we can slouch abet and if truth be told attach something in convey. I’m a stable believer that as soon as you mustn’t believe the relaxation finest to claim, or the relaxation that strikes the art forward, then you definately’d better fair be entirely silent and neutral, versus attempting to attach out a framework.

Can believe to you quiz starting programmers to jot down a calendar withhold an eye fixed on, they over and over center of attention on to themselves, “Oh, I slouch to jot down the arena’s very finest calendar withhold an eye fixed on! It be going to be polymorphic with recognize to the form of calendar. It is going to believe displayers, and mungers, and this, that, and the different.” They should always ship a calendar utility in two months. They attach all this infrastructure into convey in the withhold an eye fixed on, and then exercise two days writing a crappy calendar utility on top of it. They’ll center of attention on, “In the following version of the utility, I slouch to total lots more.”

After they birth brooding about how they’re in actuality going to put into effect all of these different concretizations of their summary extinguish, then again, it turns out that their extinguish is entirely injurious. And now they’ve painted themself valid into a nook, and they should always throw the entirety out. I believe seen that over and over. I’m a stable believer in being minimalistic. Unless you indubitably are going to resolve the general subject, don’t attempt and fix in convey a framework for fixing a explicit one, as a consequence of you do not know what that framework could silent discover fancy.

Bruce Eckel: The Shameful Programmers issue, “Enact the very finest thing that could perchance work.”

Anders Hejlsberg: Yeah, effectively, Einstein talked about that, “Enact the very finest thing that you would also mediate, but no more effective.” The explain I believe about checked exceptions is the handcuffs they attach on programmers. You overview programmers picking up unique APIs that believe all these throws clauses, and then you definately overview how convoluted their code will get, and you understand the checked exceptions are no longer helping them any. It is extinguish of these dictatorial API designers telling you pointers on how to total your exception handling. They could silent no longer be doing that.

Invoice Venners: You talked about scalability and versioning concerns with recognize to checked exceptions. Would possibly you make clear what you mean by these two disorders?

Anders Hejlsberg: Let’s birth up with versioning, for the explanation that disorders are wonderful easy to overview there. As an instance I invent a ability foo that announces it throws exceptions A, B, and C. In version two of foo, I want to add a bunch of functions, and now foo could throw exception D. It’s a breaking switch for me to add D to the throws clause of that implies, as a consequence of present caller of that implies will nearly with out a doubt no longer handle that exception.

Adding a singular exception to a throws clause in a singular version breaks consumer code. It be fancy together with a ability to an interface. After you post an interface, it is for all life like functions immutable, as a consequence of any implementation of it would possibly perchance perchance probably perchance need the suggestions that you should add in the following version. So that you would also believe obtained to invent a singular interface as a change. Equally with exceptions, that you must perchance both should always invent a total unique ability called foo2 that throws more exceptions, or that you must perchance should always method shut exception D in the unique foo, and change into the D into an A, B, or C.

Invoice Venners: However are no longer you breaking their code if so anyway, even in a language with out checked exceptions? If the unique version of foo is going to throw a singular exception that clients could silent take into story handling, is no longer in actuality their code broken fair by the truth that they did not quiz that exception when they wrote the code?

Anders Hejlsberg: No, as a consequence of in a lot of cases, folks don’t care. They are not going to handle any of these exceptions. There is a bottom stage exception handler around their message loop. That handler is completely going to raise up a dialog that says what went injurious and continue. The programmers offer protection to their code by writing attempt in the end’s throughout the convey, in impart that they’ll abet out precisely if an exception happens, but they’re no longer in actuality drawn to handling the exceptions.

The throws clause, at least the ability or no longer it is applied in Java, would not basically force you to handle the exceptions, but as soon as you do not handle them, it forces you to acknowledge precisely which exceptions could pass through. It requires you to both method shut declared exceptions or attach them to your believe throws clause. To work around this requirement, folks pause ridiculous issues. As an instance, they decorate every ability with, “throws Exception.” That fair entirely defeats the characteristic, and you fair made the programmer write more gobbledy gunk. That would not back anyone.

Invoice Venners: So that you center of attention on the more smartly-liked case is that callers don’t explicitly handle exceptions in deference to a general method shut clause additional up the resolution stack?

Anders Hejlsberg: It is silly how folks center of attention on that the well-known thing about exceptions is handling them. That is no longer the well-known thing about exceptions. In a effectively-written utility there is a ratio of ten to one, in my conception, of attempt in the end to take a discover at method shut. Or in C#, the utilization of statements, which would perchance be fancy attempt in the end.

Invoice Venners: What’s in the in the end?

Anders Hejlsberg: In the in the end, you guard yourself in opposition to the exceptions, but you do not in actuality handle them. Error handling you attach in other locations. Completely in any form of match-pushed utility fancy every form of smartly-liked UI, you steadily attach an exception handler around your well-known message pump, and you fair handle exceptions as they drop out that implies. However you create clear you guard yourself the total ability out by deallocating any sources you would also believe grabbed, and loads others. You neat up after yourself, so that you would also very effectively be continually in a relentless convey. You do not favor a program where in 100 different locations you handle exceptions and pa up error dialogs. What as soon as you should change the ability you attach up that dialog field? That is completely monstrous. The exception handling wants to be centralized, and that you must perchance also silent fair guard yourself as the exceptions propagate out to the handler.

Invoice Venners: What’s the scalability subject with checked exceptions?

Anders Hejlsberg: The scalability subject is a tiny bit connected to the versionability subject. In the tiny, checked exceptions are very horny. With a tiny bit example, you would also uncover that you would also believe in actuality checked that you caught the FileNotFoundException, and is no longer in actuality that considerable? Effectively, that’s vivid as soon as you would also very effectively be fair calling one API. The trouble begins as soon as you birth up constructing gigantic systems where you would also very effectively be talking to four or five different subsystems. Each subsystem throws four to 10 exceptions. Now, each time you chase up the ladder of aggregation, you would also believe this exponential hierarchy underneath you of exceptions or no longer it is well-known to take care of. You pause up having to present an clarification for 40 exceptions that that you must perchance throw. And as soon as you combination that with another subsystem you would also believe obtained 80 exceptions to your throws clause. It fair balloons out of withhold an eye fixed on.

In the considerable, checked exceptions became such an irritation that folk entirely circumvent the characteristic. They both issue, “throws Exception,” throughout the convey; or—and I cannot repeat you the map persistently I’ve seen this—they issue, “attempt, da da da da da, method shut curly curly.” They center of attention on, “Oh I will reach abet and take care of these empty method shut clauses later,” and then clearly they underneath no conditions pause. In these scenarios, checked exceptions believe in actuality degraded the usual of the system in the considerable.

And so, as soon as you’re taking all of these disorders, to me it fair appears to be like more thinking is well-known sooner than we attach some form of checked exceptions mechanism in convey for C#. However that talked about, there’s with out a doubt considerable value in gripping what exceptions can get thrown, and having some extinguish of instrument that assessments. I don’t center of attention on we can create difficult and snappy guidelines down to, it is both a compiler error or no longer. However I center of attention on we can with out a doubt pause lots with prognosis tools that detect suspicious code, together with uncaught exceptions, and functions out these potential holes to you.

Arrive abet Monday, September 1 for segment VII of a conversation with Elliotte Rusty Harold referring to the extinguish of the XOM API. I am now staggering the newsletter of lots of interviews at as soon as, to offer the reader diversity. The next installment of this interview with Anders Hejlsberg will seem on Monday, September 8. Can believe to you would fancy to receive a short weekly email asserting unique articles at Artima.com, please subscribe to the Artima E-newsletter.

Deep Inner C#: An Interview with Microsoft Chief Architect Anders Hejlsberg:

http://windows.oreilly.com/news/hejlsberg_0800.html

A Comparative Overview of C#:

http://genamics.com/developer/csharp_comparative.htm

Microsoft Visual C#:

http://msdn.microsoft.com/vcsharp/

Anders Hejlsberg modified into as soon as no longer the predominant Artima interviewee to present taste. Jim Waldo made nearly the same commentary about constructing a crew of tasteful programmers in his interview:

http://www.artima.com/intv/waldo10.html

And a total part of Ken Arnold’s interview modified into as soon as devoted to extinguish taste – Style and Aesthetics:

http://www.artima.com/intv/taste.html

Talk abet!

Have an notion? Readers believe already posted 45 comments about this article. Why no longer add yours?

Relating to the authors

Bruce Eckel (www.BruceEckel.com) affords constructing support in Python
with user interfaces in Flex. He’s the creator of Pondering in Java
(Prentice-Hall, 1998, 2nd Edition, 2000, third Edition, 2003, 4th Edition, 2005),
the Palms-On Java Seminar CD ROM (on hand on the Web dilemma), Pondering in C++
(PH 1995; 2nd version 2000, Quantity 2 with Chuck Allison, 2003), C++ Inner & Out
(Osborne/McGraw-Hill 1993), among others. He’s given a total bunch of displays
at some level of the arena, printed over 150 articles in a lot of magazines, modified into as soon as a
founding member of the ANSI/ISO C++ committee and speaks regularly at conferences.

Invoice Venners is president of Artima Instrument, Inc. and
editor-in-chief of Artima.com. He’s creator of the book,
Contained in the Java Digital Machine, a programmer-oriented
see of the Java platform’s architecture and internals. His
smartly-liked columns in JavaWorld magazine covered Java internals,
object-oriented extinguish, and Jini. Invoice has been appealing in the
Jini Neighborhood since its inception. He led the Jini Neighborhood’s
ServiceUI mission that produced the ServiceUI API. The ServiceUI
grew to became the de facto fashioned ability to affiliate user interfaces to
Jini services, and modified into as soon as the predominant Jini community fashioned accredited
throughout the Jini Determination Route of. Invoice also serves as an elected
member of the Jini Neighborhood’s initial Technical Oversight
Committee (TOC), and in this role helped to define the governance
course of for the community. He currently devotes most of his
energy to constructing Artima.com into an ever more priceless resource
for developers.

Content Protection by DMCA.com

Back to top button