[m-users.] When is nondeterminism appropriate?

Zoltan Somogyi zoltan.somogyi at runbox.com
Wed Feb 17 15:09:08 AEDT 2021


2021-02-17 13:18 GMT+11:00 "Volker Wysk" <post at volker-wysk.de>:
> You often have the situation that you have a beautiful algorithm and ugly
> exceptions/deviations from it. Those often arise in the realworld, say a
> full hard disk, or a permission problem, or a server being down. 

Yes, that is definitely true.

> In those cases, I think using exceptions makes the program clearer and
> easier to understand.

That is true for some people; for other people, not so much.

In a program that handles problems such as full disks or servers
being down using exceptions, the code between the place where
such problems are detected and the place where they are handled
contains no code that deals with such problems, whereas in a program
that handles such problems using explicit alternative error returns,
as with Philip's "return" type in his original email,  you do have to put
check for these alternate returns in a lot of places. One may prefer
the approach using exceptions for this reason, and many people do.

On the other hand, many other people *prefer* knowing that
they can see all the possible ways in which control can be transferred
from one part of the program to another. They view exceptions as having
the same flaw as self-modifying code: mechanisms that are so powerful
that they are hard to use *safely*. Just as with self-modifying code,
one cannot be sure that the code one is reading is the code that will be
executed at runtime, with exceptions, one cannot be sure that calls
will return in the usual, normal fashion.

> Such things may be less of a problem for guys who concern themselves with
> research in logic programming. ;-)
> 
> In the end, it might be a matter of taste if you use an exception or
> explicitly return an error.

Yes, this is a matter of taste, but that taste is *very* heavily influenced
by what languages one has used in the past. We all tend to view the
familiar as natural, and the unfamiliar as strange, and we develop
our "tastes" accordingly. One could also call religion a matter of taste,
but somehow, the tastes for the various world religions are not distributed
uniformly. I don't think I have met anyone yet who would argue that the
fact that westerners believe christianity is the natural religion, and indians
and arabs do the same with hinduism and islam respectively, is something
that is independent of the histories of these populations :-( In the same manner,
people who learnt programming using languages such as C++ and Java
tend to think of exceptions as natural, while people who learnt programming
using languages that either don't have or disemphasize exceptions, do not
do so. And as you imply, most LP researchers, including me, fall into the latter camp.

For this reason, "exceptions: yea or nay" tends to be as fruitless a topic of
discussion as "vim or emacs?". My previous email, and the paragraphs above,
are meant to inform; they are not intended to get anyone to change their religion :-)

Zoltan.


More information about the users mailing list