If it ain’t broken don’t fix it

Yet another worthless blog… by Uberto Barbini

Posts Tagged ‘exceptions’

Which school of programming fits you best?

Posted by Uberto Barbini on April 13, 2008

As usual, latest Martin Fowler’s post is a quite interesting reading.

As Programming Techniques are becoming more and more mature, we should consider to enter in a new arena: instead of bragging each others about what’s the correct way to program, we can jump on the brand new “School of Software Developing” concept.

I already have done the next step and borrowed some ideas from old jap movies. Let me clarifies with an simple example.

How do you place yourself on the eternal question about exceptions? Should they be checked or unchecked?

Speaking for myself (and whoever else?) I like the way Java let you to create an exception that *MUST* be explicitly handled by your class users. But I don’t like the way checked exceptions are used by Java libraries. That is 99.9% checked exception and 0.1% of unchecked.

I think that one should be very vary to pose such a burden on other programmers. 99% of exceptions are really cases in which something did spectacularly wrong (OutOfMemory) or some nasty bug in your code makes impossible to continue (DivByZero, TypeCastError).

Being forced to manage and exception, should be an extremely rare event. When a casual programmer would encounter one of them, there ought to be a very good reason. And he should feel ice-cold drops of sweat run down the spine while considering how to check the exception.

It’s only logical to assume that everything that can goes wrong will do it, eventually. So connection problems, allocation of spare resources, etc. should be always be protected by try..finally blocks.

Generally speaking using exception for completely predictable failures, like a files that doesn’t exist or wrong values from users, is a bad practice to begin with.
OK, stop blabbering. Now the funny part. Maybe you’re agreeing with me, maybe you’re thinking I’m nuts, or maybe you’re not knowing what I’m speaking of. No problem!

I’ll declare that this is the CleanWater School of handling exception, kiyomizu 清水 in Japanese. Because certainly you want a super-cool name for your school.

You don’t like it? Create your own school about handling exception and we can duel each other at dawn next to the waterfall. Or maybe we can meet for breakfast at Starbucks.

Posted in programming | Tagged: , , , , | 2 Comments »