4 ms·
oof. To me switch/case mentally implies constant time matching and routing, I wonder if that is the case (it could be if arrays have compile-time known length)
by throwawaymaths 1y ago
oof. To me switch/case mentally implies constant time matching and routing, I wonder if that is the case (it could be if arrays have compile-time known length).
- lerno 1y agoYou have both in C3: switch (x) { case 0: ... case 1 + 1: ... } This will behave in the normal way. But you can also have: switch { case foo() > 0: ... case bar() + baz() == s: ... } In which case it lowers to the corresponding if-else.
- deleted 1y ago[deleted]
- norir 1y agoI am not a fan of this design in a low level language. The first version of switch does exactly one thing and is very clear. The second now is forcing me to think both about branching logic and control flow. I understand the surface level appeal of the syntax, but if I encountered code written with this feature in the wild, I would think something must have gone wrong in the program design.
- throwawaymaths 1y agoi think hlls sometimes distinguish between these situations with a different keyword.
- lerno 1y agoIt's very simple, the latter describes an `if-else` chain. No more complicated than that. Can you explain what your concern is?