Thom Lawrence

Entries tagged as ‘exceptions’

Design By Making Mistakes

April 15, 2005 · No Comments

Interesting thread over on the Joel on Software forum about Design by Contract. In his reply, Karel Thönissen says:

Make the software as brittle as possible so that bugs are discovered early instead of covered up by usually buggy and badly test-covered exception handling code. Let the code explode in your face, it makes you careful (-8. I estimate that we have fewer than 0.2 exception handlers per KLOC. This style of DbC reduces the number of execution paths enormously.

I think that’s an amazing statistic, and it brings to mind a post by Udi Dahan entitled Exceptionally speaking, that is, where he makes a breakthrough:

All of a sudden it hit me. Strongly typed exceptions aren’t meant to be caught ! I think that this trounces the linchpin argument of those who argue against using exceptions except in exceptional cases.

I think this is absolutely right. Your API, including exceptions, isn’t just a service you provide, it’s not just a courtesy you perform for your consumers - it’s the story you’re telling. It’s the accumulated knowledge of the programmer, warts and all: I’m throwing this exception because when we did this we fucked this up. Which is why you can’t write the contract first.

Categories: Programming
Tagged: ,