Are conditions always appropriate?

General OpenLisp forum

Are conditions always appropriate?

Postby dbane » Thu Feb 24, 2005 12:14 pm

Sorry, I posted this to a presumably defunct Yahoo group before I saw this bulletin board.

I already know Scheme and C++. It's considered bad C++ style by some (e.g. see "The Pragmatic Programmer") to use exceptions to report all errors. Instead, a mixture of exceptions (for truly exceptional errors, likely caused by a program bug) and return codes (for errors which are expected in normal program execution, e.g. "file not found" if you're getting the filename from the user) is recommended.

This is largely because exceptions are a non-local transfer of control (like goto), so can make program comprehension difficult. There is also an efficiency argument, but in practice it rarely applies to anything other than real-time code. On the other hand, judicious use of exceptions can declutter the main control path.

I was wondering if there is the same divide in ISLISP. The language definition seems to hint that you should use conditions for every error. Is that considered good Lisp style (note I'm not concerned about efficiency, just maintainability)?
dbane
 
Posts: 8
Joined: Wed Feb 23, 2005 6:42 pm
Location: Limerick, Ireland

Re: Are conditions always appropriate?

Postby jullien » Mon Feb 28, 2005 9:28 pm

dbane wrote:... a mixture of exceptions (for truly exceptional errors, likely caused by a program bug) and return codes (for errors which are expected in normal program execution, e.g. "file not found" if you're getting the filename from the user) is recommended.


I fully agree. That's the way most Lisp programs work.

... This is largely because exceptions are a non-local transfer of control (like goto), so can make program comprehension difficult.


True again.

... There is also an efficiency argument, but in practice it rarely applies to anything other than real-time code. On the other hand, judicious use of exceptions can declutter the main control path.


When you set an exception it's slow even if you don't raise it. By slow, I mean
it is not adviced to put exception code in a recursive function that is intensively called for example. It is also a bad practice to use exceptions to return from a normal situation.

The language definition seems to hint that you should use conditions for every error.


It depends on what you want to do. If you write a HTTP server then, YES, you should catch any possible errors, report problem to end user and never break the server. You can set a high level loop that catch all errors and use a more relaxed code for the real server part.

Is that considered good Lisp style (note I'm not concerned about efficiency, just maintainability)?


It's alway a good style to report good error messages.
jullien
Site Admin
 
Posts: 30
Joined: Fri Nov 12, 2004 12:29 am


Return to General discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron