3 ms·
IMHO switch is horrible construct i'd rather see ML style pattern matching
by fleetfox 10y ago
IMHO switch is horrible construct i'd rather see ML style pattern matching
- OskarS 10y agoSwitch makes sense in really low level languages like C where it becomes a branch table (and allows things like Duff's device), but it has no place in higher-level languages. Fallthrough, while very occasionally useful, is bug prone and weird (breaks the "principle of least surprise" in a major way). Python made the right call not including it.
- khedoros1 10y agoSo do it like "match" in Rust. Fallthrough certainly seems un-Pythonic. It seems worthwhile to ditch it in favor of pattern matching. It also seems un-Pythonic to have to implement something in a less-obvious way. Choosing an action based on a one item from a set of possible inputs means either a dict that maps to lambdas or function variables or a big chain of if-else. Neither of those options are optimal.
- dev360 10y agoPattern matching without TCO would leave me feeling deceived