Skip to content

Instantly share code, notes, and snippets.

@elbrujohalcon
Created September 8, 2014 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elbrujohalcon/1002d8580eb8f8918a30 to your computer and use it in GitHub Desktop.
Save elbrujohalcon/1002d8580eb8f8918a30 to your computer and use it in GitHub Desktop.
case vs. if
%% I would argue that
HTTP11Headers = case {Transport, Version} of
{cowboy_spdy, 'HTTP/1.1'} ->
[{<<"connection">>, atom_to_connection(Connection)}];
{_, _} ->
[]
end
%% is clearer and more flexible for future improvement if needed than
HTTP11Headers = if
Transport =/= cowboy_spdy, Version =:= 'HTTP/1.1' ->
[{<<"connection">>, atom_to_connection(Connection)}];
true ->
[]
end
%% for instance, you may eventually like to abstract that into its own function, like…
HTTP11Headers = connection_headers(Transport, Version)
connection_headers(cowboy_spdy, 'HTTP/1.1') ->
[{<<"connection">>, atom_to_connection(Connection)}];
connection_headers(_, _) ->
[].
%% but then again, it might just be a matter of taste. If you like your ifs, then do not
%% add the rule to your elvis.config ;)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment