Why do some people shun `if`?

Michael P. empro2@REDACTED
Tue Aug 17 16:29:53 CEST 2021

So far, I have been using `if` to tell other
programmers (and myself) that the following decision

a) is not of general use (=> module function);

b) not repeated or required by some other function (=> fun);

c) is made without patterns (=> case);

d) depends only on pure functions.

And because it is a bit more readable than `(fun () ...)()`.

Every function is a decision table,
from trivial to complex.
The pattern-matcher in my brain made me perceive
both `if` and `case` as mere subsets of `fun`.
Especially some larger `case` looks just like a `fun`,
except at the top and bottom.

Yesterday, or so, I discovered that they also, both,
lack the "(let ...)"-y nature of `fun`.

(I could have realised that half a year ago,
when Craig told me that patterns in `case`
do not introduce a new scope. But my head was
fully enganged in trying to see any sapiens in
calling an annotation an operator.)

Now, all my `if` and `case` code shifts into
the surrounding scope.

Could that be some cause of the apparent
contradiction in this thread:
'try to avoid `if`' <=/=> 'try to use `if`'?

Or is this caused by two, each good and well,
but mutually exclusive "approaches"?

I need to watch that "if = harmful" video again
that Ben pointed to, and digest it.
I need to try again to understand Jespers
excellent explanation
(I can see from tone and structure that it is,
one cannot demand one-read-no-think explanations).
And, no less, I need to reconsider all the other
hints and then stitch it all together.



But who will test the tests?

More information about the erlang-questions mailing list