Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Everyone keeps telling me to use switch statements (twitter.com/phantom_thegame)
3 points by tentacleuno on Dec 30, 2023 | hide | past | favorite | 3 comments


Switches are really only for enumerated/integral types, where a single variable can take on a small number of interesting values. Some if-else situations don't translate to switch-case at all, though. One such is when you're faced with decision tree logic, involving multiple variables. Another occurs when you need to (or are stuck with) matching various strings.


Depends on the language, looks like this one can't do pattern matching? Makes you appreciate languages like Zig, Rust or Odin a lot more


Well played! "Something beyond anything he could possibly imagine", indeed.




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

Search: