[darcs-devel] [patch1980] split off D.R.Pristine and D.R.Traverse ... (and 4 more)

Ben Franksen bugs at darcs.net
Wed Feb 26 07:57:12 UTC 2020


Ben Franksen <ben.franksen at online.de> added the comment:

> I should have also commented that I also find using exceptions instead
> of normal control flow a bit strange, although I don't know of any
> concrete problems with doing it in Haskell so it's just a matter of a
> style preference.

I beg to differ. This is not about style preference, but about reliability.

There are two independent questions here.

One is whether it is a good idea to use exceptions to handle (or not
handle) failures of IO actions, or whether it is better to indicate
failure via return value. There is considerable debate on that. However,
this one was decided for us by the people designing Haskell & the
standard libraries. I agree that the choice is questionable.

A completely different question is whether it is a good idea to first
check for suitable conditions before running an action to avoid possible
failures, or whether it is better to let the action fail and then handle
that. There is (astonishingly) an almost universal consensus that the
latter is to be preferred. This is because the former method always
involves a race condition with outside agents: another process may
interfere between the check and the action and invalidate the result of
the check before the action is run. This is generally referred to as
TOCOU (time of check, time of use). It impedes reliability and can lead
to bugs that are very hard to reproduce.

We should /always/ let IO actions fail and then handle the failure and
/never/ first check for suitable conditions.

__________________________________
Darcs bug tracker <bugs at darcs.net>
<http://bugs.darcs.net/patch1980>
__________________________________
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pEpkey.asc
Type: application/pgp-keys
Size: 4211 bytes
Desc: not available
URL: <http://lists.osuosl.org/pipermail/darcs-devel/attachments/20200226/aabf0310/attachment.key>


More information about the darcs-devel mailing list