Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Strazdonis56yDamn, get some 10 hours of sleep...
Out of curiosity:
Why even use switches? For me theyre hard to read and serve no purpose. -
By design switch performance is O1. If-elif tree performance -- o(n). Switch calculates the exact jump spot and sets eip immediatelly while if-elif does that using sort of a bruteforce.
Also switch cases are quite often easier to read when used properly, because they rely on a constants.
[someone above asked why use switches over ifs] -
@Brosyl well, in checkboxes for example. Checked is true, unchecked is false, null is when no choice is made. You need a switch case to check those.
-
Strazdonis56y@netikras thanks a lot it is a lot clearer for me now! I've never seen a switch that was easy to read for me though :/
-
@Brosyl C#. But it appears to exist in Java as well, since version 8. In Typescript as well I think.
-
zshh38486yYou can do that in some languages (kinda), it’s called pattern matching. Check out Rust!
I think I am tired.
I almost did a switch-case on a boolean.
random