Re: Why do some people shun `if`?
"Michael P." <[email protected]>
| Newsgroups | gmane.comp.lang.erlang.general |
|---|---|
| Message-ID | <20210817162953.4945f8f0@aesop> |
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. ~M -- But who will test the tests?