Hacker News new | ask | show | jobs
by enriquto 2264 days ago
> they're obsolete unless you just prefer their syntax.

This is a good point.

Sometimes I prefer the (ugly) syntax of switches than that of conditionals. The reason is that a chain of conditionals is non-symmetrical (there's no condition for the first "case"), while a switch is formally invariant to permutation of the cases. I have even seen shit like this:

    if (false) ;
    else if (c == 1) { first case ; }
    else if (c == 2) { second case; }
    ...
just to preserve the symmetry along the cases.
1 comments

Are you talking about the `else` being non-symmetric? You don't need it at all. I do this.

  if (c == 1) { first case ; }
  if (c == 2) { second case; }
...and hereby I give back my programming license and go back to civil life.
This might result in another fallthrough scenario though, wouldn't it?
No, because `c` can't be 1 and 2 at the same time.
In this specific example. But you cannot rule it out in general.