
2 May
2007
2 May
'07
11:21 p.m.
G'day all.
Quoting Henning Thielemann
Why replacing the almost-function 'if' by a special syntactic construct?
In a sense, this is entirely stylistic. One works just as well as the other. But I think it's superior in this case (obviously not all cases) because this is at the top-level (i.e. on the RHS of a top-level function definition), and one "arm" of the if-then-else is a call to "error", that is, a precondition/domain/sanity check. These pre-checks are almost always different from the "real" business that the function performs. Using guards makes the separation that much more obvious. Cheers, Andrew Bromage