125
tahnik
7y

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

Comments
  • 3
    Too much js? Framework learning overload, get the basics?
  • 2
    @billgates it was JS tho. totally forgot about it :/

    yeah but you are right, too much js :P
  • 1
    In most cases I'd prefer a lookup table over a switch/case.
  • 3
    Switch 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)
  • 1
    The compilers I use warn about missing break/return and C++17 introduces [[fallthrough]] for the very rare cases they were intentionally left out.
  • 0
    @bittersweet @Huuugo it's not big enough for a lookup table. Not too small for a if else either.
  • 0
    @kraator I'm using JS and haven't enabled eslint for Vue files yet.
  • 0
    Just use if statements... Unless you have 100+ outcomes or something ridiculous, just use if
  • 0
    Been there, I feel your pain.
  • 3
    If 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)
  • 1
    @nicholai that is what has been mentioned before as "lookup table"
  • 0
    @Huuugo but "lookup table" =/= code example.
Add Comment