Created
September 8, 2014 19:28
-
-
Save elbrujohalcon/1002d8580eb8f8918a30 to your computer and use it in GitHub Desktop.
case vs. if
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% 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