[erlang-questions] Any wisdom to offer on "tagged return values"

Christian <>
Sat May 2 00:50:00 CEST 2009

I think the lesson to take home from the programming rule you refered
to is to Crash Early. Find a failure in its infancy and crash then
rather than letting program execution proceed causing more mess. It
can be done both by using tagged tuples or throwing exceptions.

When to use tagged tuples and when to use exceptions does not have any
strong concensus. Everlyone only agree that you should program for the
successful case and crash early when something was not successful.

On Sat, May 2, 2009 at 00:37, Kevin <> wrote:
> Kostis Sagonas kostis-at-cs.ntua.gr |erlang| wrote:
>> Kevin wrote:
>>> ...
>>> Ironically in the lists man page it says keysearch is deprecated in
>>> favor of keyfind, which does exactly what the programming rules
>>> cautions against.
>>> keyfind(Key, N, TupleList) -> Tuple | false
>> There is nothing ironic or wrong here.  Tuple is a tuple, not an atom
>> so the two cases cannot be confused.
>> Kostis
> Maybe thats not the best example since the keysearch in the programming
> guide is slightly different from the lists one, but I can still find
> plenty of examples of functions that dont return tagged values, even
> when they fail
> 84> lists:nth(4, [1,2,3]).
> ** exception error: no function clause matching lists:nth(1,[])
> 90> lists:min([]).
> ** exception error: no function clause matching lists:min([])
> Following the programming guide those could have been written
> nth(N, List) -> {value, Elem} | error
> min(List) -> {value, Min} | error
> _______________________________________________
> erlang-questions mailing list
> http://www.erlang.org/mailman/listinfo/erlang-questions

More information about the erlang-questions mailing list