Most active commenters
  • sametmax(3)

←back to thread

2024 points randlet | 20 comments | | HN request time: 1.97s | source | bottom
1. sametmax ◴[] No.17516409[source]
It's going to be very interesting to see if things like:

- pattern matching

- inline exception catching

- path inclusion in the built in

- more functional tooling

- lazy keywors

That were BDFL-blocked, will go back to be debated in the mailing list in the next months.

And if yes, will the community stands by its root or create a new era ?

The consequences of which we will only really see in 10 years.

Guido as done an incredible job at being the boogie man, keeping the language simple and readable. It's a hard job.

Can we pull it off ?

replies(4): >>17516765 #>>17518674 #>>17519896 #>>17519907 #
2. bluecalm ◴[] No.17516765[source]
I think he made a right call blocking all of those. There are Pythonic ways to do all of those already and the mantra there should be one and preferably one way of doing things is important for the philosophy of the language.

With PEP 572 it wasn't like that. There wasn't a Pythonic way to do list comprehensions which used the same expensive to evaluate expression two times in it and it was I think the only glaring syntax weakness in comparison to languages which have a way to do that (like WHERE keyword in Haskell).

replies(4): >>17517691 #>>17517949 #>>17518030 #>>17518364 #
3. rthomas6 ◴[] No.17517691[source]
What's the Pythonic way of pattern matching?
replies(2): >>17517721 #>>17517956 #
4. sametmax ◴[] No.17517721{3}[source]
There is none in the language, and no proposal has gain much traction on python idea.
5. sametmax ◴[] No.17517949[source]
Since there is no metrics for that, your entire post, much like a lot of any part of the language design process, is very opinionated.

It's why it's hard.

6. owaislone ◴[] No.17517956{3}[source]
A dictionary of string: functions I guess? Don't think there is a decent one
replies(1): >>17518172 #
7. jondot ◴[] No.17518030[source]
Whats the pythonic way to do dependencies? pip? pipenv? virtualenv? pyproject? And how about Python 2 and 3?

</Sarcasm>

But seriously, I think there's no one way to do things anymore especially if it holds up productivity and effectiveness. Let the pattern matching begin.

replies(1): >>17520302 #
8. marcosdumay ◴[] No.17518172{4}[source]
That's parametrized jumping. Pattern matching is parsing a structure with variables and filling those variables from a single structured value.

Python does that with tuples:

    a, b = b, a
But it just stops there. To be fair, I don't know how much power it would gain by going further either. Never made that question.
replies(1): >>17518289 #
9. joshuamorton ◴[] No.17518289{5}[source]
That is more commonly known as destructuring. (in python and javascript at least, as well as a few others iirc)

Pattern matching is normally (in functional languages like Scala and Haskell anyway) defined as a way of taking a union type and handling each one safely. It's a sort of functional alternative to polymorphism.

That is, polymorphic code

    class Dog(Animal):
        def make_noise(self):
            return "bork bork"

    class Duck(Animal):
        def make_noise(self):
            return "quack"
would, with pattern matching be (in pseudo haskell I hope)

    make_noise :: Animal -> str
    make_noise Duck = "quack"
    make_noise Dog = "bork bork"
In other words, in an oop style you delegate to the object that it implements all methods. Whereas with pattern matching you can have a type delegate to each of the functions that can operate on it to handle it correctly. (This explanation is a disservice to functional styles, its a lot more elegant than what I describe if you do it correctly).
replies(2): >>17519064 #>>17520332 #
10. abecedarius ◴[] No.17518364[source]
You can in fact factor out expressions in list comprehensions, like:

    [foo(y, y) for x in xs for y in [f(x)]]
Is this Pythonic? Perhaps not, but mainly because multiline list comprehensions are frowned on in general. I think people tend to get too dogmatic about that.
11. gaius ◴[] No.17518674[source]
Multi-line lambdas, I hope!
12. ◴[] No.17519064{6}[source]
13. cutler ◴[] No.17519896[source]
Please can we have real lambdas? I'd then be tempted to prioritise Python over Ruby.
14. stormbeta ◴[] No.17519907[source]
The big one I want to see, because it's one of my biggest frustrations with Python, is to finally make lambdas work like every other contemporary language instead of being inexplicably limited to a single expression simply because Guido couldn't come up with a syntax that agreed with him.

There's so many cases (arguably including the problem this PEP was designed to solve!) where having a real inline closure is just far more readable than having to arbitrarily break every single thing that happens to need 2+ expressions out into named blocks out of sequence.

Other things in Python are either simply a result of the language's age and history, or have real technical pros and cons, but that one irks me because it's an artificial limitation chosen for no reason except aesthetics.

replies(2): >>17521396 #>>17521437 #
15. JacobHenner ◴[] No.17520302{3}[source]
pipenv for applications with module dependencies :)
16. idontpost ◴[] No.17520332{6}[source]
So basically Clojure protocols? As in, multimethods that dispatch on the type of their first argument?
replies(1): >>17520390 #
17. joshuamorton ◴[] No.17520390{7}[source]
Except that assuming Animal is a sum type (kind of like an enum), the computer will complain.

So a maybe type (equivalent to an Optional) is simply a sum over just and nothing (the two components). If you fall to handle nothing, the program won't compile.

Animal would work the same way. Add "Cow" as an animal, and your program won't compile until everything sanely handles Cow.

So more like a switch case over a set of options where the compiler prevents you from forgetting any.

18. mijamo ◴[] No.17521396[source]
Nononono

God please NO!

I would KILL not to make that happen. So many devs abuse those in every language that has that. Even lambas get sometimes abused in Python (and I have a few examples in our codebase unfortunately). Expanding lambdas' scope is the LAST thing I want in Python, this would just lead to worst codebases, with nearly 0 benefit.

If you want to do something that needs 2 expressions, just create a goddamn function and name it for god's sake.

Sorry but I had to say it, I think the lambda limitations is one of my favorite feature in Python.

replies(1): >>17522594 #
19. zimablue ◴[] No.17521437[source]
I read a long time ago and was convinced that no nice lambdas was one of the biggest problems in python, but that poster argued convincingly that it's an unavoidable consequence of the meaningful whitespace. Are you proposing a special syntax for multiple statements on one line for this?
20. gugagore ◴[] No.17522594{3}[source]
It's useful to be able to give names to things and it's also useful to not be able to give names to things.

It could and could also not be useful to give names to all the subexpressions in the following

w = a(b(c(x,y),z))

You could impose a limitation on how many function can be in a single expression, forcing you to give names. That's analogous to your favorite feature, no?