Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: "David Allsopp" <dra-news@metastack.com>
To: "'Mark Shinwell'" <mshinwell@janestreet.com>,
	"'David Allsopp'" <dra-news@metastack.com>
Cc: "'Florent Ouchet'" <florent.ouchet@imag.fr>, <caml-list@yquem.inria.fr>
Subject: RE: [Caml-list] Static exception analysis or alternative to using	exceptions
Date: Thu, 27 May 2010 10:29:20 +0100	[thread overview]
Message-ID: <001901cafd7f$19d7afc0$4d870f40$@romulus.metastack.com> (raw)
In-Reply-To: <20100527091110.GD18772@janestreet.com>

Mark Shinwell wrote:
> On Thu, May 27, 2010 at 09:54:29AM +0100, David Allsopp wrote:
> > Florent Ouchet wrote:
> > > Same here, specially to avoid the Not_found exception.
> > > The optional return values gives the oportunity to have a clear view
> > > of what is being done if the result is not available.
> >
> > Agreed - though [find] is one of the examples where you do need find
> > and find_exc - because often there are occasions where before calling
> > {Map,Set,Hashtbl}.find you already know that the key exists and so
> > won't fail at which point the 'a option boxing is a waste of time and
> > space and Not_found would be a truly exceptional situation so passes
> > the previously mentioned test.
> 
> I don't think I agree with this.  I would argue that for the majority of
> programs it is likely that the extra overhead is in fact negligible.  In
> the cases where it should be impossible to get the None return value, I
> think that should probably be annotated as such in the code with "assert
> false", which would seem to be more appropriate than a random Not_found
> popping up at some much higher level.

assert false is just a way of renaming the exception and relies on the
rather dirty (but necessary) hack in the compiler that, as a special case,
assert false is not optimised out of a program compiled without debugging
checks.

<snip>

> Whilst I agree that there are arguments relating to verbosity of the use
> of option types, I think the strongest argument for keeping the *_exn
> variants may actually be that they're just a lot more convenient for quick
> hacks.

Unnecessary verbosity = unreadable IMHO, that's one of the reasons we use
clear, functional languages in the first place. That overhead also isn't
negligible as soon as you've got a Hashtbl/Set/Map which is queried a lot
(i.e. just about any form of data processing). Code where you know a priori
that the keys exist becomes unnecessarily peppered with pointless match
clauses (or calls like ExtLib's Option.get which... would raise an exception
if faced with None!). The interest to me is not that the overhead is
negligible, but that it can be trivially removed by using a *better*
function in that instance. Obviously, in the perfect world, your call to the
_exc version would in reality carry a proof that the key will be found (and
so no exception would be necessary). I simply don't see that the overarching
reason to have the _exc version of the function would be simply for hacking
a quick solution to a problem where you can't be bothered to handle the
Not_found case.


David


  reply	other threads:[~2010-05-27  9:30 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-26 17:30 Dario Teixeira
2010-05-26 21:10 ` Hans Ole Rafaelsen
2010-05-27  3:37   ` Jacques Le Normand
2010-05-27  8:08     ` Florent Ouchet
2010-05-27  8:50       ` Eray Ozkural
2010-05-27 11:10         ` Florent Ouchet
2010-05-27  8:54       ` David Allsopp
2010-05-27  9:11         ` Mark Shinwell
2010-05-27  9:29           ` David Allsopp [this message]
2010-05-27  9:12         ` Daniel Bünzli
2010-05-27  9:19           ` David Allsopp
2010-05-27  9:15       ` David Rajchenbach-Teller
2010-05-27 13:56     ` Hezekiah M. Carty
  -- strict thread matches above, loose matches on Subject: below --
2010-06-01 19:08 Peter Ronnquist
2010-05-26 16:15 Hans Ole Rafaelsen
2010-05-27  9:34 ` [Caml-list] " Alain Frisch
2010-05-27 17:01 ` Richard Jones
2010-05-27 21:13   ` Dario Teixeira
2010-05-31 14:36   ` Goswin von Brederlow
2010-05-31 15:00     ` Florent Ouchet
2010-05-31 17:24     ` David Allsopp
2010-05-31 20:51       ` Török Edwin
2010-06-08  9:16       ` Goswin von Brederlow
2010-05-31 19:30     ` Nicolas Pouillard
2010-05-31 20:57       ` Lukasz Stafiniak
2010-05-31 21:42         ` blue storm
2010-05-31 19:36     ` Christophe Raffalli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='001901cafd7f$19d7afc0$4d870f40$@romulus.metastack.com' \
    --to=dra-news@metastack.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=florent.ouchet@imag.fr \
    --cc=mshinwell@janestreet.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox