←back to thread

317 points est | 1 comments | | HN request time: 0.208s | source
Show context
sametmax ◴[] No.17448716[source]
I will be happy to be able to do:

    while (bytes := io.get(x)): 
and:

    [bar(x) for z in stuff if (x := foo(z))] 
Every time Python adds an expression counterpart to an existing statement (lambdas, intensions, ternary...) there is a (legit) fear it will be abused.

But experience tells that the slow and gradual pace of the language evolution combined with the readability culture of the community don't lead that way.

While we will see code review breaking materials in the wild, I believe that the syntax will mostly be used sparingly, as other features, when the specific needs arise for it.

After all, it's been, as usual, designed with this in mind: "=" and ":=" are mutually exclusive. You don't use them in the same context.

The grammar makes sure of it most of the time, and for the rare ambiguities like:

    a = b
vs

    (a := b)
The parenthesis will discourage pointless usage.

My bet is that we will see essentially rare but useful and expressive use cases in productions, which is exactly the goal.

Given the month of debates around this, I think it's a fine compromise.

Like many, I would have preferred the use of the "as" keyword instead of a new operator, since it's already used to bind things to names in imports, context managers and try/except.

However, the new syntax has 2 advantages: it reads the same way than the original operator, and it supports type hints out of the box.

replies(6): >>17449142 #>>17449634 #>>17453453 #>>17453473 #>>17454371 #>>17456196 #
smcl ◴[] No.17449634[source]
> Every time Python adds an expression counterpart to an existing statement (lambdas, intensions, ternary...)

What do you mean by "intension"? I haven't seen this referred to in python and googling isn't turning out anything useful (also spelling it as "intention").

replies(1): >>17449683 #
sametmax ◴[] No.17449683[source]
Sorry, french word for "comprehension". It pops up automatically. I can't edit my post anymore though.

The worst for me is OOP. In french it's POO, which, for obvious reasons, does not inspire confidence in an english reader.

replies(2): >>17449697 #>>17453311 #
makapuf ◴[] No.17453311[source]
Did you mean intention (french spelling) is a translation for list comprehension ? First time I've seen it used ( https://fr.m.wikipedia.org/wiki/Liste_en_compr%C3%A9hension ) Sorry if I misunderstood.
replies(1): >>17456163 #
sametmax ◴[] No.17456163[source]
Not 'intention' (will/wish), but 'intension' (as the opposite of extension: see https://fr.wikipedia.org/wiki/Intension_et_extension).

"comprehension list" in french can be translated to "liste en intension"

replies(2): >>17457053 #>>17466890 #
1. makapuf ◴[] No.17466890[source]
TIL, thanks. It seems to be the kind of perfectly adapted idiom (that no one uses or understand).