[erlang-questions] The If expression

Fredrik Svahn fredrik.svahn@REDACTED
Fri Jan 2 13:54:56 CET 2009


> I do not fancy any of these two code examples as they promote a sloppy
> programming style. In my opinion, a boolean expression should be a
> boolean expression and nothing else. If a boolean expression evaluates
> to anything else than 'true' or 'false', the evaluation should fail in
> the normal case. Sometimes catch-all-clauses are useful, but in many
> cases they may delay detection of bugs.

You are right, of course. The catch-all should be replaced with a false-clause.

> I find the new proposed syntax to be very similar to the old
> if-statement. The old syntax may be a little bit uglier than the new
> syntax, but that is not the same as unintuitive.

The first unintuitive part about the current "if" (at least for
beginners) is that the true clause in my example is evaluated when the
Bool evaluates to false. This problem does not exist with an else
clause. The second unintuitive part is that exceptions are silently
swallowed.

  if length({}) == 0 -> its_empty; true -> its_not_empty end.


By the way, just found this: http://www.trapexit.org/If_Then

BR /Fredrik



More information about the erlang-questions mailing list