26

Previous dev created a switch statement on a boolean flag. WTF

Comments
  • 5
    When 0 is particularly large, it's nearly as large as a little bit of 1.
  • 1
    Shiiiiiit
  • 4
    I do that as well sometimes. Instead of a bunch of if-else one could write:

    @highlight
    switch (true) {

    case thing1(): { ... }
    case thing2(): { ... }
    case thing3(): { ... }
    default: { ... }

    }
  • 5
  • 0
    @olback wth that's actually pretty nifty when I think about it. No way I'd accept it in a PR though.
  • 4
    @olback if-else is more efficient in this case. Also, most languages only support compile-time constants as case values.
  • 0
    Nullable boolean?
  • 2
    switch(Val){
    case true:
    Damn() ;
    default:
    ImAnIdiot();
    }
  • 0
    @s0LA By optimising it on hardware level. That's nearly as good as optimising the idle task of an operating system. :-)
  • 0
    COBOL has support for reverse switch-case. This can sometimes be useful if one three different variables can have one specific value.

    @highlight
    EVALUATE "Y"
    WHEN VARIABLE-1 ...
    WHEN VARIABLE-2 ...
    WHEN VARIABLE-3 ...
    WHEN OTHER ...
    END-EVALUATE
  • 0
  • 0
    It's OK, he just wrote future-proof content for when you port your software to a system that supports qubits.
Add Comment