Re: Mix of "functional" and "procedurial" programming
- From: seeWebInstead@xxxxxxxxxxxxxxxx (Robert Maas, http://tinyurl.com/uh3t)
- Date: Thu, 03 Sep 2009 05:02:23 -0700
How to handle errors?...
From: August Karlstrom <fusionf...@xxxxxxxxx>
Just pass a status variable which the procedure can set. In C we would
do something like
int done;
foo(&done);
if (done) {
...
}
Passing a raw machine address to a subroutine, then allowing that
subroutine to modify not just the one byte at that address but an
arbitrary amount of memory "near" that address (actually almost
*anywhere* whatsoever in RAM), is so grossly unsafe that you should
be ashamed of using that poor practice as an example.
You can have the *convention* that a specific amount of memory
relative to that given address will be available for modification,
and the subroutine is not supposed to modify any memory outside
that range, but would you really want to trust any important data
to some other human's *interpretation* of an informal convention
you mistakenly thought was so very well spelled out in a two
hundred page legal document that the other guy didn't have time to
fully read and couldn't remember the whole thing anyway even if he
spent a year reading it over and over and over, with no
programming-language enforcement to prevent his misunderstanding
from royally screwing your application? (Never mind trojans using
buffer overflow tricks!)
In Lisp, that kind of dangerous permission is not allowed. But a
reasonable alternative is to pass a mutable object, with initial
value NIL, to be replaced by an error message if some problem
occurred. The most obvious (to me anyway) choice is a CONS cell
where the CAR is the slot for the message and the CDR isn't used,
or the CAR is the software-understadable error code and the CDR is
the human-understandable explanation, etc., variations on that
basic idea. The next most obvious choice (to me again) is a CONS
cell whose CAR is a constant tag identifying this intentional
object as an error-return record, and the CDR is an association
list with an arbitrary number of separate tags having different
significance, such as :ERROR-CODE :TEXT-ERROR-EXPLANATION :CONTEXT
:CONTINUATION-CALLBACK etc. Of course a CLOS object with named
slots has similar capability, less flexible but more well defined.
I guess this shows an advantage of Lisp over C.
.
- Prev by Date: Re: Big O notation - Aho, Hocraft and Ullman
- Next by Date: Re: Big O notation - Aho, Hocraft and Ullman
- Previous by thread: How to limitate program usage with license key?
- Next by thread: Finding the structure of an alogorithm
- Index(es):
Relevant Pages
|