[erlang-questions] style question - best way to test multiple non-guard conditions sequentially

ok@REDACTED ok@REDACTED
Mon Jul 8 00:04:02 CEST 2013


> I couldn't decide which error should be thrown when the cond test doesn't
> return a boolean but I have found some references to cond expressions in
> an old paper [2] (page 37) and decided to stick to their choices.

To be honest, I couldn't see any good reason to make
    cond E1 -> B1 ; ... ; En -> Bn end
any different from
    case E1 of true -> B1 ; false ->
    ...
    case En of true -> Bn
    end
    ...
    end
I see great virtue in there being *no* difference whatsoever
in the semantics of the two, so that the choice is *solely*
stylistic and rewriting one into the other (either way) *cannot*
break a working program.

Having looked at that reference, I do not see any advantage for
the more complicated version.  As long as you can find out
*where* the error was, it just isn't _useful_ to know 'it was a
cond' rather than 'it was a case'; a program catching errors
would never want to treat them differently, and a human who has
been told _where_ can instantly see _what_.






More information about the erlang-questions mailing list