[m-users.] When is nondeterminism appropriate?

Volker Wysk post at volker-wysk.de
Wed Feb 17 23:08:23 AEDT 2021

Am Mittwoch, den 17.02.2021, 15:09 +1100 schrieb Zoltan Somogyi:
> 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.

That's true... With exceptions, it's less obvious which code will be
activated. You could retrace all the exceptions which a procedure can throw,
but then, you might not even know for sure which exceptions that are. C++
mitigates this problem by letting you specify a list of exceptions that may
be thrown, as part of the declaration of a procedure. When it throws
something that hasn't been specified, it (mostly) is a compile time error.
When it couldn't be detected at compile time, it is a runtime error. 

Of course, if you have to modify some code, and a function/procedure/method
has to throw an additional exception, you have the same problem again. In
theory, you would have to check all the places which call that procedure.
Then you are where you wanted to keep away from: check all the

Fortunately, I believe, it isn't always necessary in practice, to check all
the possibilities. And then exceptions are a good aid.

> > 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. 

I come from C++ and Haskell (and some Prolog).

> 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

Yuck, 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 :-)

I think it's not *all* religion. But that might be a religion, too...


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://lists.mercurylang.org/archives/users/attachments/20210217/346cae2a/attachment.sig>

More information about the users mailing list