News for hackers. Stuff that matters.
Re:Why switch is better than if-else by pmontra on Saturday June 29, 2019 @02:52PM (#20314119)
And languages with multiple function definitions for different arguments are even better

    def(arg = value_0) { ... }      
    def(arg = value_1) { ... }
    def(arg = value_2) { ... }
    def(arg) { ... }
Example: Elixir.
Re:Why switch is better than if-else by mortoray on Saturday June 29, 2019 @05:59PM (#20315056)
I agree. General purpose pattern matching in both expressions and function dispatch is a great feature.
Re:Why switch is better than if-else by willio58 on Saturday June 29, 2019 @08:29PM (#20315687)
Author says, regarding if-else, “We aren’t certain here whether we mean to cover all possible values, or only these values in particular”. I don’t really get what that means.

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?

Re:Why switch is better than if-else by s_m_t on Saturday June 29, 2019 @09:29PM (#20315844)
The proceeding lines make that clearer for me.

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.