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
-
tahnik387588y
-
Huuugo25058ySwitch case is a common source of bugs, because of its cyclomatic complexity and non-obvious syntax. I always prefer if..else or a look-up table/dict/hashmap/list (depending on the language)
-
kraator4118yThe compilers I use warn about missing break/return and C++17 introduces [[fallthrough]] for the very rare cases they were intentionally left out.
-
tahnik387588y@bittersweet @Huuugo it's not big enough for a lookup table. Not too small for a if else either.
-
Just use if statements... Unless you have 100+ outcomes or something ridiculous, just use if
-
nicholai8578yIf statements and case switches? You guys are so last year.
let opts = {case1: 'result1', case2: 'result2'}
return opt in opts ? opts[opt] : opts[0]
(This one defaults to first case)
Related Rants
Looking at my code for 10 minutes. The switch case is always going to default. Almost about to break my head.
I FORGOT TO PUT FUCKING BREAK AFTER EACH CASE. WWWWWWWHHHHHHHHYYYYYYYYY
undefined
i cri
everytim
switch