inaka/erlang_guidelines

Suggestion: no if recommendation examples are missing or missleading

Opened this issue · 1 comments


Examples in no_if erl have different conditions betwen bad/1 and better/1, good/1. It needs to correct and extend.

bad(Connection) ->
  {Transport, Version} = other_place:get_http_params(),
  if
    Transport =/= cowboy_spdy, Version =:= 'HTTP/1.1' ->
      [{<<"connection">>, utils:atom_to_connection(Connection)}];
    true ->
      []
  end.


better(Connection) ->
  {Transport, Version} = other_place:get_http_params(),
  case {Transport, Version} of
    {cowboy_spdy, 'HTTP/1.1'} ->
      [{<<"connection">>, utils:atom_to_connection(Connection)}];
    {_, _} ->
      []
end.

Altough bad/1 defines inequalty, the pattern matching in both of better/1 and good/1 defines equalty between Transport and cowboy_spdy. As this example has a logic to present the transformation, the better/1 and good/1 should be corrected while bad/1 still remains unchanged.

Furthermore arithmetic comparisons between more values (at least 3) and a variable, range checking examples should be even presented here to present the readability differences and to help the reasoning why do not use if's.

Great points, @profetasajt !! Would you mind creating a PR with your suggested changes?
And if you manage to remove cowboy from the examples and make them less verbose in general, that would be highly appreciated as well.