Version française
Home     About     Download     Resources     Contact us    
Browse thread
[OSR] Exceptionless error management
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Michael Ekstrand <michael+ocaml@e...>
Subject: Re: [Caml-list] [OSR] Exceptionless error management
Andrej Bauer <Andrej.Bauer@fmf.uni-lj.si> writes:
> Bünzli Daniel wrote:
>> let find map k = match Map.find map k with Some v -> v | None ->
>> assert false
>
> I have become to prefer option types as return values (as opposed to
> exceptions), but I admit it can be annoying to always consider both
> possibilities, especially if you know that "None" won't happen. If the
> library only provides "find" that returns an option type, the above
> solution gets around constant checking. But how much runtime overhead
> does it cause? Has anyone measured that?
>
> What is wrong with having two functions? With a bit of imagination, we
> can give them reasonable names, e.g., get and search. Everybody can
> guess which one returns the option type and which one throws an
> exception, right?

While `get' and `search' are probably OK (I presume that `get' raises
an exception, and `search' returns an option type), we must be
careful.  If multiple functions is the standard, I would prefer that a
naming/variant system be recommended (such as get and get_exn).  If we
come up with clever names for our various functions, I fear the Java
Queue API syndrome (where you can get a value with any of 4 different
functions, and add with another 4, that mostly differ in how they
handle error and thread blocking conditions and the names have little
correlation to the differences).

- Michael

-- 
mouse, n: A device for pointing at the xterm in which you want to type.
Confused by the strange files?  I cryptographically sign my messages.
For more information see <http://www.elehack.net/resources/gpg>.