<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><span style="font-family:Arial,Helvetica,sans-serif">On Sat, Aug 14, 2021 at 11:45 PM Michael P. <<a href="mailto:empro2@web.de">empro2@web.de</a>> wrote:</span><br></div></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I once stumbled over someone's Erlang style guide,<br>
they wanted no `if`.<br><br></blockquote><div><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">There are uses for the if...end construct in Erlang. The reason you often shun it is because it occurs quite rarely in a language where you have a proper case...end matching construct. So to avoid newcomers to fall into a trap of using if all the time, you write it down in the style guide. In reality, style can be broken for improved readability, but it takes some knowledge to know exactly when.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">The deeper underlying problem is that of "boolean blindness". A value that is true/false doesn't tell you *why*. If you write a function such as</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">empty([]) -> true;</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">empty([_|_]) -> false.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">you know that the list is empty, but you don't get to know it's structure. Whereas with a match</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">case L of</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">  [] -> ...;</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">  [H|T] -> ...</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">end,</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">you *do* know the structure in each variant clause, and you also have convenient bindings for the head and tail. If-constructs will have you analyze the structure after you hit a branch, whereas pattern matching allows you to make that analysis up front. Erlang terms are ripe for scrutiny, so as a result, you'll find much more use of case than if.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">That said, and what Ulf alludes to: there are always exceptions to the rule.</div></div></div>