Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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).


You 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.


I 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.


It's very simple, the latter describes an `if-else` chain. No more complicated than that. Can you explain what your concern is?


i think hlls sometimes distinguish between these situations with a different keyword.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: