gnu-arch-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gnu-arch-users] Nit


From: Tom Lord
Subject: Re: [Gnu-arch-users] Nit
Date: Mon, 20 Oct 2003 19:27:17 -0700 (PDT)


    > From: Dustin Sallings <address@hidden>

    [Exceptions are wonderful.]



Eh.

As the part of thread between me and Walters illustrates, it takes a
lot of work to employ exceptions without screwing up abstraction
barriers.

As reams and reams of unix code, not to mention tla, illustrates:  you
can write quite useful tools without the hassle of exceptions.

We haven't talked about it but a big problem with exceptions is that
they tend to drive people towards wanting "exception classes" -- but
in general purpose libraries or complex applications there's (for deep
reasons) no one "class hierarchy" that Does The Right Thing. 

Exceptions are something to toss in your toolbox.   They're there when
you need them.


    >   I'm not talking about error recovery, I'm talking about error 
    > trapping.  printf() is a write() call as far as I'm concerned.  It can 
    > fail like any other write call.  Should your program continue running 
    > and writing to a file when each write is failing just because you ran 
    > out of disk space somewhere?


Have you noticed that calls in tla are to `safe_printfmt'?


    >   I think this is a good example of exceptions making it easier to write 
    > more reliable software.  If printf() would just fail if it couldn't do 
    > what you asked it to do, your code would stop running when you ran out 
    > of disk space (unless you trapped it and wanted to do something 
    > different).

Ok, so, we have (so far) two choices:  

1) Programs just fail when they run out of disk space.
2) Programs can decide to handle printfmt errors.

That's why libhackerlab gives you safe_printfmt (for (1)) and printfmt
(for (2)).

What are going to be options (3) and (4)?:

3) "Higher level code" catches an exception from a deeply nested call
   to printfmt and tries to Do The Right Thing.    Congratulations, 
   you have written spaghetti-code by violating abstraction violations 
   left and right.

4) Your program is tossed into the debugger.   You fix stuff and tell
   the debugger to continue.   Congratulations, you are using a good 
   lisp system.

    > Especially java?  All of the core java stuff throws exceptions when 
    > there's an error (I'm sure there's at least one exception
    > somewhere).  

*cough<talkingouthisass>cough cough*

As long as your _sure_ then we're all glad to hear what you have to
say :-)

Ok, I admit, that was potentially rude -- but please hear me out:

It's not like your interlocutors here are unfamiliar with exceptions.
It isn't like any of them wouldn't, at the drop of a hat, employ them
where they're a win.   It isn't like they haven't been exposed to
"exceptions religion" and even maybe tried to believe.   Me
personally?  I'm sure that there were periods of time when I felt the
same way you do about exceptions.

So why are we taking your bait and burbling on this topic?  Well, it's
a public service.   Boring and tedious as it sounds, the Big Picture
-- the Final Lesson -- is that exceptions (and gazillions of other
things we refute and toss about and argue about here) are just a tool
for the toolbox.   

Programming is a subtle art.  There's not even a single notion of
"good program" -- it's always circumstance-specific (like
architecture).   Sometimes exceptions win, often they don't.

I think where "we" (the people arguing against you) are really failing
here is that it seems that you're trying to argue about exceptions as
a practice that should be universal, and we _seem_ to be saying
exceptions are a practice never to be adopted -- but really what I
hope "we" are trying to do here is to say:

  1) No, exceptions aren't quite the panacea you may have heard.
  2) Here, let's try to pin down the narrow circumstances under which
     you'll want to reach for exceptions and describe how you'll want
     to use them.


Lemme try these questions, to maybe put you on a slippery slope:

  Goal: write mkdir(1)

  Question: Are exceptions going to help you?


and

  Goal: write a tiny client as per rfc959

  Question: Are exceptions going to help you?


After that, madam, we're just negotiating price.

-t





reply via email to

[Prev in Thread] Current Thread [Next in Thread]