Re: Why do some people shun `if`?
"Richard O'Keefe" <[email protected]>
| Newsgroups | gmane.comp.lang.erlang.general |
|---|---|
| Message-ID | <CABcYAdLN4cvnT4WfyrMCyr3UtDSH0zELD8d_5huU8pEiG33tzQ@mail.gmail.com> |
My reason for avoiding "if" in Erlang is that it doesn't do what I expect, so I am likely to get it wrong. From using many many other programming languages, I expect 'if <expression>', but in Erlang it's 'if <guard>'. To add to the confusion, instead of separating guards and expressions even more clearly, Erlang has blurred them further. So sometimes making that mistake will have no consequences, and other times it will make me sorry. It's one of those things like writing <constant> == <variable> instead of <variable> == <constant> in C, to avoid the error of writing = instead of ==. On Sun, 15 Aug 2021 at 09:45, Michael P. <[email protected]> wrote: > > I once stumbled over someone's Erlang style guide, > they wanted no `if`. > It was not very well explained why, > and there was no obvious e-mail address, > or I wanted to first do > some thorough thinking about it. > Now I have no more than this: > > Is if not merely "syntactic sugar" for > a fun/0 with guarded clauses? > ``` > Now_this_is = (fun If() when Guard_seq_1 -> Expr_seq_1 > %% On and on and on > ; If() when Guard_seq_N -> Expr_seq_N > end)(), > % or: > Worst = case true > of true when Guard_seq_1 -> Expr_seq_1 > ; true when Guard_seq_2 -> Expr_seq_2 > end. > ``` > What could be perceived as wrong with `if`? > > ~M > > -- > > But who will test the tests? > > > > > >