4 ms·
The biggest upset is that they didn't go the extra bit and implement match assignments. Such an insanely powerful, very functional feature. Helps reduce bugs si
by kortex 5y ago
The biggest upset is that they didn't go the extra bit and implement match assignments. Such an insanely powerful, very functional feature. Helps reduce bugs simply by facilitating orthogonal branches of assignment that cannot interact, unlike if/else or for loops.
Oh well, maybe in a few years someone will put in a PEP to use walrus := with match/case to give match assignment and give the old Python guard something to _really_ clutch pearls about.
- benhoyt 5y agoDo you mean like this? x = match expr: case 'a': 1 case 'b': 2 case _: 0 I think mainly it doesn't work very well in Python due to indentation problems. Kind of like how lambda is restricted to single expressions, instead of blocks. Here's what they say in the rationale PEP (https://www.python.org/dev/peps/pep-0635/ https://www.python.org/dev/peps/pep-0635/): > Statement vs. Expression. Some suggestions centered around the idea of making match an expression rather than a statement. However, this would fit poorly with Python's statement-oriented nature and lead to unusually long and complex expressions and the need to invent new syntactic constructs or break well established syntactic rules. An obvious consequence of match as an expression would be that case clauses could no longer have arbitrary blocks of code attached, but only a single expression. Overall, the strong limitations could in no way offset the slight simplification in some special use cases.
- sullyj3 5y agoI think they're right that it would be too foreign to python to be a good addition, but this really just goes to show that expression oriented languages, as opposed to statement oriented ones, are the way to go.
- marmaduke 5y agoThe debugging and instrumentation in Python is line and statement oriented, so there’d be a lot more work behind the scenes.
- deleted 5y ago[deleted]
- BiteCode_dev 5y agoThat would be at odd with the language style which separate statements from expressions. You can dislike this language characteristic, but it's the right call to stay congruent.
- kortex 5y agoI agree it's the right call, but boy would it be nice.