Why switch is better than if-else
mortoray.com
mortoray.com
def(arg = value_0) { ... }
def(arg = value_1) { ... }
def(arg = value_2) { ... }
def(arg) { ... }
Example: Elixir.I never feel confused when looking at an if-else statement which values I’m targeting. Do they just give a bad example in this post?
In my mind a switch statement is like "here is an execution path for every state this enumeration can hold" (like the author says, compiler or ide may warn you about missing cases) while an if else is a bit more general than that. With an if else you might only be checking for a few specific conditions.