5 ms·
Yes, and this is incredibly disappointing. Couldn't we achieve the same functionality with a little less ambiguity using the following syntax?: not_found
by airstrike 6y ago
Yes, and this is incredibly disappointing.
Couldn't we achieve the same functionality with a little less ambiguity using the following syntax?:
not_found = 404
match status:
case not_found:
return "Not found"
case _ as foo:
do_something(foo)
return "Match anything"
it even works for the example in PEP 365
match json_pet:
case {"type": "cat", "name": _ as name, "pattern": _ as pattern}:
return Cat(name, pattern)
case {"type": "dog", "name": _ as name, "breed": _ as breed}:
return Dog(name, breed)
case _:
raise ValueError("Not a suitable pet")
- baby 6y agoThis would be really confusing to anyone who is used with match statements in other languages
- coldtea 6y agoFor 2 seconds until they learn what it means. If anything, it's more explicit what exactly it does. There are 100s of things in Python who would be confusing to people used to other languages, this is not one of them.
- reikonomusha 6y agoThe general tripping up of binding vs mutation vs assignment vs initialization is a pervasive Python issue. This just continues to double down on exacerbating the problem.
- hnlmorg 6y agoComparing garbage syntax to worse syntax and saying “it’s not as bad as that” isn’t the way one improves upon a language.
- coldtea 6y agoWhich is neither here, nor there. This syntax is clearly an improvemen to the PEP syntax. And parent said it's "confusing". Well, it's less confusing than the PEP syntax. Nobody compared it to not adding it at all, or was concerned with improving the language aside from the pattern matching case here.
- hnlmorg 6y agoAlmost everyone in this discussion is making exactly those comparisons. Including yourself. When you're discussing usability issues due to changes to the syntax, the perspective of non-exclusive developers vs full time Python devs doesn't change the underlying context of the discussion regarding the change in usability. And I stand by my position that defending a bad decision because of the existence of worse decisions is a really piss poor counterargument. Disclaimer: I'm a language designer myself so I know first hand how hard it is to get these things right.
- coldtea 6y ago>And I stand by my position that defending a bad decision because of the existence of worse decisions is a really piss poor counterargument. This thread was just about the two alternatives (the PEP and explicit capture), not about the PEP in general, or about defending the PEP or even saying that the better alternative is "good". We just say it's better than the PEP. Not sure how you read that into what we wrote. >Disclaimer: I'm a language designer myself so I know first hand how hard it is to get these things right. Then go make that argument in some thread in this post discussing the PEP proposal in general?
- hnlmorg 6y ago> This thread was just about the two alternatives (the PEP and explicit capture), not about the PEP in general, or about defending the PEP or even saying that the better alternative is "good". We just say it's better than the PEP. Not sure how you read that into what we wrote. Bullshit. You said, and I quote, "There are 100s of things in Python who would be confusing". That's what I was responding to. And my point stands: just because there are other pain points in Python doesn't mean we should accept more pain points into it. > Then go make that argument in some thread in this post discussing the PEP proposal in general? I’d prefer to make that argument in the thread where I was already talking you about the PEP proposal in general. ;)
- lolinder 6y agoBut the existing semantics are very confusing to anyone who is used to Python, which seems like a bigger problem.
- baby 6y agoI don't agree, I'm used to Python and this is not confusing to me because I have learned to use match statements, you will do too.
- kortex 6y agoI dig it. 'as' primes my brain to something going into a scoped context.
- Spivak 6y agoIt’s fine. Python just introduced expression assignment. Why not use that? match subject case [first := _, rest := _] return [rest, first]
- collyw 6y agoWell get to Perl eventually
- pfalcon 6y agoNote that the original PEP622 relied on ":=" initially, but they found some corner case with it (apparently, operator precedence related) and switched to "as" in PEP634.
- kortex 6y agoThat works too but I guess I am still getting used to the walrus operator. What really bugs me about this PEP is they are going through all this effort to introduce match but they don't have match assignments, which is personally one of my favorite things about match.
- ziml77 6y agoI'm still wary about this change making it in to Python, but I like this suggestion. It makes the assignment clear. The way it's currently specified would definitely trip me at some point.
- neillyons 6y agoI like your proposal. The `as` keyword is very readable to me. I would have preferred `as` instead of the walrus operator too.