Live data from Hacker News

What's Coming in Python 3.8

lwn.net

111–120 of 558 posts

Re: What's Coming in Python 3.8

#111
>Debug support for f-strings.

F strings are pretty awesome. I’m coming from JavaScript and partially java background. JavaScript’s string concatenation can become too complex and I have difficulty with large strings.

>Python 3.8 programmers will be able to do: print(f'{foo=} {bar=}')

Pretty cool way to help with debugging. There are so many times, including today, I need to print or log some debug string.

“Debug var1 ” + var1 + “ debug var2” + var2...and so on. Forgot a space again.

Re: What's Coming in Python 3.8

#112
post #91

Earlier quoted context omitted.

I don't know how you read it - 'if x is assigned the value y'? Most other things in Python can just be read out loud.

You could read "if x := y()" as "if x gets a truthy value from y()." For what it's worth, "x = y()" is one of the harder things for new programmers to translate to English in the first place -- it reads most naturally as "x equals y," but leads to better intuitions as "x gets the value of y". I think that's what makes this clunky to verbalize, rather than the "if truthy" bit.

So := is 'gets a truthy value from'? That seems to work.

> For what it's worth, "x = y()" is one of the harder things for new programmers to translate to English in the first place

Right... so why have we added more complexity to something known to be very complicated?

Re: What's Coming in Python 3.8

#113

Speaking as someone who has written Python code almost every day for the last 16 years of my life: I'm not happy about this. Some of this stuff seems to me like it's opening the doors for some antipatterns that I'm consistently frustrated about when working with Perl code (that I didn't write myself). I had always been quite happy about the fact that Python didn't have language features to blur the lines between what…

Many languages don't distinguish between statements and expressions—in some languages, this is because everything is an expression! I'm most familiar with these kinds of languages. I'm not familiar much with Python, beyond a little I wrote in my linear algebra class. How much does the statement/literal distinction matter to readability? What does that do for the language?

The only reason I can imagine being opposed to it is fear that hordes of bad programmers will descend on the language and litter the ecosystem with unreadable golfed garbage.

I obviously don't want that. I don't think anybody wants that. But I also don't think that's going to happen as a result of the recent changes in the language. If anything, I feel like the average code quality in the wild has gone up.

Re: What's Coming in Python 3.8

#115

Earlier quoted context omitted.

Regular = can only be used in statements. Walrus := can only be used in expressions. There's no overlap there. However, := does simplify certain expressions (like those nested if-else statements and the common "while chunk := read()" loop), which I think does justify its existence.

This honestly makes it seem more confusing to me. The fact that there is now an operator that can only be used in certain statements just makes things more confusing. And if there really is no overlap, then why wasn't the "=" operator just extended to also work in expressions? "while chunk = read()" seems like it makes just as much sense without adding the confusion of another operator.

I expect the PEP authors want to avoid the "while chunk == read()" class of bugs

ninjaedit: indeed https://www.python.org/dev/peps/pep-0572/#why-not-just-turn-...

Re: What's Coming in Python 3.8

#116

I long for a language which has a basic featureset, and then "freezes", and no longer adds any more language features. You may continue working on the standard library, optimizing, etc. Just no new language features. In my opinion, someone should be able to learn all of a language in a few days, including every corner case and oddity, and then understand any code. If new language features get added over time, eventua…

someone should be able to learn all of a language in a few days, including every corner case and oddity, and then understand any code.

Why should this be true for every language? Certainly we should have languages like this. But not every language needs to be like this.

Re: What's Coming in Python 3.8

#117

Earlier quoted context omitted.

Read it "if y" - that's what's being tested. The walrus simultaneously names the value being tested so you can refer to it within the condition; it's sort of the inverse of Perl code using $_. So instead of if (do_something()) { act_on($_); } you have if placeholder := do_something(): act_on(placeholder) But when reading aloud, however you'd read the perl will flow as more natural english. "If the string contains z,…

>Read it "if y" - that's what's being tested. Once way to test if this works is to take the code, read it aloud, and then use the read-aloud version to rewrite the code. If you don't have a high degree of certainty that you end up with the same code, something has failed along the way. In this case, if I take "if x:= y()" and read it aloud as "if y", I think the vast majority of people would translate that to code as…

You will end up with the same code under two conditions:

1. You read more than one line of code.

2. Executing the code in the conditional more than once doesn't matter.

If you meet those two assumptions, then the reading I suggested will transform this

    if x := y():
        act_on(x)
into this

    if y():
        act_on(y())
which is, in fact, the same thing.

Re: What's Coming in Python 3.8

#118
Despite controversy, walrus operator is going to be like f-strings. Before: "Why do we need another way to..." After: "Hey this is great".

People are wtf-ing a bit about the positional-only parameters, but I view that as just a consistency change. It's a way to write in pure Python something that was previously only possible to say using the C api.

Re: What's Coming in Python 3.8

#119

I long for a language which has a basic featureset, and then "freezes", and no longer adds any more language features. You may continue working on the standard library, optimizing, etc. Just no new language features. In my opinion, someone should be able to learn all of a language in a few days, including every corner case and oddity, and then understand any code. If new language features get added over time, eventua…

Absolutely agree. How many times have you heard "that was true until Python 3.4 but now is no longer an issue" or "that expression is illegal for all Pythons below 3.3", and so on. Not to mention the (ongoing) Python 2->3 debacle.

Re: What's Coming in Python 3.8

#120

Very much looking forward to assignment expressions! It's something I've wanted to do every so often, only to realise that you can't. A worthy addition to the already intuitive Python language.

Seriously. I recently came from PHP, and this is one feature I've been missing quite often and a lot.
Post reply on HN