Live data from Hacker News

What's Coming in Python 3.8

lwn.net

191–200 of 558 posts

Re: What's Coming in Python 3.8

#191
post #166

How come they are using a new := operator instead of using equals?

Which equals? = (existing) is statement assignment == (existing) is expression equality := (new) is expression assignment

Just 1 equals. It could assign a statement to a variable, and return that value/variable to the if statement to check for truthyness

   a=42
   if b = a:
     print(b)
   else:
     print("no")
Would print "42". It works in C

  int a,b;
  a=42;
  if(b=a){
    printf("%d\n",b);
  } else {
    printf("no\n");
  }

Re: What's Coming in Python 3.8

#192
post #145

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…

Elixir? From the v1.9 release just a few weeks ago: https://elixir-lang.org/blog/2019/06/24/elixir-v1-9-0-releas... > As mentioned earlier, releases was the last planned feature for Elixir. We don’t have any major user-facing feature in the works nor planned. I know for certain some will consider this fact the most excing part of this announcement! > Of course, it does not mean that v1.9 is the last Elixir version. W…

Interesting!

I imagine churn will still happen, except it will be in the library/framework ecosystem around the language (think JavaScript fatigue).

Re: What's Coming in Python 3.8

#193

Earlier quoted context omitted.

> Even the less controversial type hints are here on maybe 10 percent of the code out there. I think this metric is grossly overestimated. Or your scope for "out there" is considering some smaller subset of python code than what I'm imagining. I think the evolution of the language is a great thing and I like the idea of the type hints too. But I don't think most folks capitalize on this yet.

I mean 10% of new code for which type hints are a proper use case, so mostly libs, and targeting Python 3.5+. Of course, in a world of Python 2.7 still being a large code base and Python being used a lot for scripting, this will far from the truth for the entire ecosystem.

The idea that types are hostile to scripting sounds really weird to me. Turtle[0] in Haskell is absolutely amazing for scripting -- especially if you pair it with Stack (with its shebang support) -- and it is as strongly typed as Haskell.

There is a bit of learning curve (because, well, it's not shell which is what most people are used to), and you do have to please the compiler before being able to run your script, but OTOH, you'll basically never have that "oops, I just deleted my working directory because I used a bad $VARIABLE" experience.

[0] http://hackage.haskell.org/package/turtle

Re: What's Coming in Python 3.8

#194
post #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.

Was the controversy really about the need for the feature? I thought most people agreed it was a great feature to have, and most of the arguments were about `:=` vs re-using `as` for the operator.

Re: What's Coming in Python 3.8

#195

Earlier quoted context omitted.

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.

> The fact that there is now an operator that can only be used in certain statements just makes things more confusing The new operator (like many Python operators) can only be used in expressions (statements can contain expressions, but expressions are not a subset of statements.) > The fact that there is now an operator that can only be used in certain statements just makes things more confusing Because the “=” oper…

>it would be create potential readability difficulties for human reading

I think the major argument (at least, the one I see most frequently) is that the walrus operator does create readability difficulties for humans, which is exactly why many people view it as non-pythonic. This is one of the few times I've seen someone argue that ":=" makes things more readable.

Re: What's Coming in Python 3.8

#196
post #58
post #8

Python looks more and more foreign with each release. I'm not sure what happened after 3.3 but it seems like the whole philosophy of "pythonic", emphasizing simplicity, readability and "only one straightforward way to do it" is rapidly disappearing.

i've been hearing this since 1.5 => 2.0 (list comprehensions), then 2.2 (new object model), 2.4 (decorators)... happy python programmer since 1.5, currently maintaining a code base in 3.7, happy about 3.8.

That's especially funny given how everybody screams "that's not pythonic!!1!" nowadays when somebody does _not_ use a list comprehension...

Re: What's Coming in Python 3.8

#197
post #145

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…

Elixir? From the v1.9 release just a few weeks ago: https://elixir-lang.org/blog/2019/06/24/elixir-v1-9-0-releas... > As mentioned earlier, releases was the last planned feature for Elixir. We don’t have any major user-facing feature in the works nor planned. I know for certain some will consider this fact the most excing part of this announcement! > Of course, it does not mean that v1.9 is the last Elixir version. W…

That's just an announcement that they reached the end of the list of user-facing syntax changes on their roadmap.

Re: What's Coming in Python 3.8

#198
post #166

How come they are using a new := operator instead of using equals?

They address this briefly in the PEP[0], and it's largely because they want to be very clear about when it's happening. The distance between

    if x = y:
and

    if x == y:
is very small, and easy to ignore, so insisting on

    if x := y:
makes it very clear that what's happening won't be mistaken for comparison at a quick glance.

[0]: https://www.python.org/dev/peps/pep-0572/#why-not-just-turn-...

Re: What's Coming in Python 3.8

#199
post #91

Earlier quoted context omitted.

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?

> So := is 'gets a truthy value from'?

No, “if ” expands to “if has a truthy value”.

“ := ” is itself an expression, which can be best (IMO) read in English as “ (which is )”

Re: What's Coming in Python 3.8

#200
post #18
post #5

Walrus operator looks like a great addition, not too much syntax sugar for a common pattern. Why were folks arguing about it?

I write a good deal of python and I can't think of a line of code that I would use it for besides the while loop on a non-iterable data source, which is such a once in a blue moon case. As mentioned by others, the operator invites more ways to do the same thing, which is not what Python has been viewed as being about.

Victor Stinner made a demonstration pull request using the walrus operator in the standard library where it makes sense. On balance it removes several hundred lines and often makes the code much clearer, e.g. https://github.com/python/cpython/pull/8122/files#diff-78e8e...
Post reply on HN