Correct syntax of a case clause
Mon Jun 15 19:29:07 CEST 2009
On Mon, Jun 15, 2009 at 1:02 PM, mats cronqvist<masse@REDACTED> wrote:
> If Expr is modified so it can be bound to values other than a, b or c,
> it will work (i.e. produce the correct result) only by accident. But
> it will not fail (i.e. throw an exception). This is what I consider
> the worst kind of broken.
> Given that the original problem statement considered itself with a, b
> and c, we must assume we have no idea what to do if we get a
> d. Otherwise the spec should have read; "all values except c should be
> treated the same." This is different from when we write a polymorphic
> function, when we know up front that some value should be ignored.
Completely agreed! Fail as fast as possible if the luxury of
conforming strictly to a spec is available.
I've been spending too much time supporting either legacy,
non-changeable systems, or very new, speculative systems where I may
start out with the strict case clause, but then be forced into a
fairly generous 'default' action through an incomplete or wildly
in-flux implementation of a spec in the party connecting to my code.
It may not be the code I *want* to write for the problem, but it does
lower some of the cost of overhead related to constant refactoring,
when applied carefully. (Even at that, I do usually try to make the
default action complain loudly, so I don't get confused when new input
tickles it.) As such, I read John's "spec" a little differently.
More information about the erlang-questions