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

Richard O'Keefe ok@REDACTED
Wed May 6 04:13:36 CEST 2009


On 6 May 2009, at 4:27 am, Ulf Wiger wrote:
> Also, functions that return tagged values don't compose well.
> I've found that I don't use composition that much in my code,
> and I think it's something that one can certainly go overboard
> with. The problem that frequent case matching clutters up the
> code is a bigger issue, IMHO.

When you are writing code for a specific use,
there's a rule of thumb that I use.
I think it makes sense for library code too.

Basically, it's "let it crash".

Spelling it out,

  - if the immediate caller of a function will know what to
    do with the "exceptional" result, return a tagged value
  - if it won't, so that the code would be cluttered up with
    stuff that just passes the buck, throw an exception.

For library code, you have to make (informed) guesses about
whether the caller is _likely_ to have anything useful it
can do with the "exceptional" result.

People can run amuck with exceptions too:  there really isn't
anything the least bit unusual about an iteration coming to
an end, yet Javascript relies on exception handling to end
iterations.

I'm not disagreeing with Ulf Wiger here, just wrapping more
words around what I think is the same idea.




More information about the erlang-questions mailing list