Post

@PythonPr i’ve no idea. I use switch cases for anything non-trivial and enumerable.
A switch statement means the compiler will tell you if you missed one. It’s a far better pattern for any kind of finite state conditional.
.
English

@PythonPr Not allways. If the options are too many switch case is allways the best.
English

@PythonPr i guess they love throwing away bogged down spaghetti code
English

I started old school on the C64 with the IF/THEN/ELSE and BNE/BEQ in 6502 Assembly.
Personal rules I follow to not get caught in if/else and switch/case hell:
1. A 'if' or individual 'cases' logic should never exceed more than five lines in length ,not including the break or return.
2. 'If/else' is always looking at a boolean test result, treat it as such.
3. Get the result and hand-off to a function or return/transform the data itself if it doesn't violate rule #1.
4. use 'switch(match)/case' if a quick check on an object and its value is needed and if the objects value can be more than 2 values. Then hand off to a function following rule #1.
As always keep it SOLID :)
English

@PythonPr kotlin so autistic that needed to use 'when' instead of 'switch'
English

@PythonPr Because there is no pattern matching in python...
English

@PythonPr `switch-case` is much faster, while `if-else` is highly flexible. I usually use both, sometimes even together in complex decision making scenarios.
English

@PythonPr If it can be handled through reflection and you have a lot of cases please avoid switch cases. Tnx
English

@PythonPr "If you have four or more else if statements, consider using a switch statement and defining the literals as constants to improve readability."
English

@PythonPr If else is more appropriate for most cases than switch case.
Switch case is truly efficient but all depends on how and where its used for.
English






























