by uryga · 6y ago · 0 comments
> "We propose the match syntax to be a statement, not an expression. Although in many languages it is an expression, being a statement better suits the general logic of Python syntax."
no matching in lambdas unless those get overhauled too :(
instead, let's get excited for a whole bunch of this:
match x
case A:
result = 'foo'
case B:
result = 'bar'
(i guess i'm a little salty...) match shape:
case Square(l):
area = l * l
case Rectangle(l, w):
area = l * w
case Circle(r):
area = (PI * r) ** 2
when I want to just write this: area = match shape:
case Square(l):
l * l
case Rectangle(l, w):
l * w
case Circle(r):
(PI * r) ** 2
I'm almost guaranteed to forget (or mistype) the `area = ` at least once in any match clause of length.Ideally as a next version of Python. But I think Julia and Nim come to mind as related to these concepts.
> no matching in lambdas unless those get overhauled too :(
Hate it or like it, but it's congruent with the rest of Python design.
Guido has been hostile with introducing too much FP in Python.
While I find it frustrating from time to time, espacially when I come back from another language to Python, on the long run, I must say I understand.
I don't like to work with FP languages, because unless your team is really good, the code ends up hard to read and debug. It's possible to make very beautiful code in FP, but it makes it so easy to create huge chains of abstract things.
And devs are not reasonable creatures. Give them a gun with 6 bullets, they'll shoot them all, and throw some stones once it's empty.
To me, the average dev is not responsible enought with code quality, and should not be trusted. I'm all for tooling enforcing as much as you can. Linters and formatters help a lot. But sometimes, language design limiting them is a god send.
I've seen the result with Python: you can put a math teacher, a biologist and frontend dev on their first backend project, and they will make something I can stand reading.
x if cond else y
IMO match-expressions have basically the same benefits/trade-offs.But I do wish they would have not set aside generalized unpacking.
idk... you can write a huge ugly if-elif-else like this:
a if foo else b if bar else c if quux else d
but most people just don't.That single comment from Guido 15 years ago, which was largely backtracked on—map and filter remain in the core library and reduce moved to a library in stdlib, lambda remains—is not really an example of something accurately described as “increasingly” now. In fact, given the backtracking, it's arguably decreasingly true from the high point of that post.
let x = foo in expr
can be [expr for x in (foo,)][0]
(kinda reads like a Haskell `where` clause!) or: (lambda x = foo: expr)()
useful in a pre-walrus-operator REPL :)You would not get through code review with that in any shop that has discipline.
> "[...] making it an expression would be inconsistent with other syntactic choices in Python. All decision making logic is expressed almost exclusively in statements, so we decided to not deviate from this."
so it's just keeping in line with Python's general imperativess.
> FP constructs are increasingly discouraged in Python [...] Not that this is necessarily a bad thing, per sé
i, on the other hand, do think it's a bad thing :) but what can you do...
Hy[1] I guess? It looks pretty lively although I'm not sure how seriously people take it these days.
Abstractly, I'd rather have match expressions, too, but this does fit the rest of Python better.