Live data from Hacker News

What’s New in Python 3.8

docs.python.org

221–230 of 381 posts

Re: What’s New in Python 3.8

#221

The expansion of f-strings is a welcome addition. The more I use them, the happier I am that they exist https://docs.python.org/3/whatsnew/3.8.html#f-strings-suppor...

I saw that and was like "Oh, that'd be a handy feature for a lot of other programming languages too." But the more I think about it, the more I'd rather have a feature that takes a list of expressions and converts it into a dict where the keys are the expression text and the values are the values of those expressions. Basically, syntactic sugar for this: { k: eval(k) for k in ('theta', 'delta.days', 'cos(radians(thet…

Pretty trivial to do with proper macros in a language. Julia has macros for printing variables and values, like `@debug(var)`.

There's an Elixir library with macros to make a map (dictionary) using the variable names passed in [1]:

    iex> import ShorterMaps
    ...> name = "Chris"
    ...> id = 6
    ...> ~M{name, id}
       %{name: "Chris", id: 6}
Though wether its a good idea or not is another question. ;) If you want to do the type of programming you're talking about you should try Elixir/Julia/Clojure(/Rust?)... or any number of other languages with macros.

1: https://github.com/meyercm/shorter_maps

Re: What’s New in Python 3.8

#222
post #164

Earlier quoted context omitted.

As someone who has used Python for over 10 years and C, Perl, etc for over 20, I've been craving the walrus operator forever. I love the walrus operator with a love that is unholy.

I wonder what you think of "for else" loops. (although I think "else" should have been a different keyword)

Not OP, but I've probably used them 2 or 3 times in the past decade or so and each time it made for a nice solution to the problem I was facing.

Re: What’s New in Python 3.8

#223
post #30

def f(a, b, /, c, d, *, e, f): Wow: IMHO that is a very ugly syntax to define a fn with 6 parameters, although it looks to be a path dependency on previous decisions (*, and CPython ,/) and clearly there was much discussion of the need for the functionality and the compromises: https://www.python.org/dev/peps/pep-0570/ It amazes me to see how certain features make it into languages via community/committee (octal numb…

> which itself is a result of limiting ourselves to the ASCII symbols that can be typed I think we're ready for programming languages using some visually good Unicode characters, instead of overloading `[]{}!@#$%^&*()-_/` for everything!

> I think we're ready for programming languages using some visually good Unicode characters

Some already do: https://docs.julialang.org/en/v1/base/math/#Base.:!=

Re: What’s New in Python 3.8

#224
post #83

Earlier quoted context omitted.

The f-strings from 3.6 are a (relatively) recent feature that I have absolutely loved. I'd go so far as to say they are my favorite feature introduced by Python 3. I'm also looking forward to PEP-554 [0], which allows for "subinterpreters" for running concurrent code without removing the GIL or incurring the overhead of subprocesses. [0] https://www.python.org/dev/peps/pep-0554/

f-strings are great. Much nicer than ".format". I hope in a next iteration of the language all strings will be f-strings by default, avoiding the need to prefix them by a silly "f".

That would of course be an absolute disaster, given that any user input could easily leak internal state and/or break your program.

Re: What’s New in Python 3.8

#225

Earlier quoted context omitted.

Why not something like this: def f_iter(many, args): while True: m = f(many, args) if m: yield m else: raise StopIteration ... for m in f_iter(many, args): # do stuff with m This way you’re isolating all the initialization logic, error handling, etc. And you can focus on your domain logic in your client code.

so i should write a whole other function that iterates over a list instead of being happy that := exists?

Yes! No pain, no gain!

Re: What’s New in Python 3.8

#226
post #197
post #186

Earlier quoted context omitted.

I don't see the point of `final` without an optimizing compiler. Name mangling is sufficient for stashing references to avoid accidental side-effects of overriding.

You can guard yourself against overriding in the same module this way, too. For name mangling, I think you need to start your variable with underscores, and then it won't be accessible for reading outside the module either?

For modules you can access the variable just fine, but for classes you need to use the mangled name:

  $ cat >foo.py
  __FOO = 1
  class Foo:
      __FOO = 2
  $ cat >bar.py
  import foo
  print(foo.__FOO)
  print(foo.Foo()._Foo__FOO)
  $ python3 bar.py 
  1
  2

Re: What’s New in Python 3.8

#227
post #92

Earlier quoted context omitted.

Coming from Perl, I used to want this badly, but then I thought that there's absolutely nothing wrong with m = re.match(...) if m is not None: pass Now, I wonder what you meant saying that single-line version is less error-prone, because I don't think so. I believe they're exactly the same in this regard, except for a bizarre case when someone would bastardize the code by putting some irrelevant lines between the ass…

The issue, in my opinion, is when you want something like this: while m := f(many, args): # do stuff with m Now, if you're writing this in Python 3.7, you often end up with some code duplication: m = f(many, args) while m: # do stuff with m m = f(many, args) # duplicate Or something like this: while True: m = f(many, args) if not m: break # do stuff with m Personally, I consider the last version to be the most elegan…

The last version clearly exposes that you have an infinite loop. This is something hidden by the `while(evaluate)` expression.

Also if it comes to pure form I would have preferred `while (evaluate) as x:` out of establishing a parallel with existing syntax, but that's not very important.

Re: What’s New in Python 3.8

#228
post #22

As a developer who has primarily developed applications in Python for his entire professional career, I can't say I'm especially excited about any of the "headlining" features of 3.8. The "walrus operator" will occasionally be useful, but I doubt I will find many effective uses for it. Same with the forced positional/keyword arguments and the "self-documenting" f-string expressions. Even when they have a use, it's us…

IMHO walrus operator goes against the zen of python.

https://www.python.org/dev/peps/pep-0572/#differences-betwee...

https://www.python.org/dev/peps/pep-0572/#relative-precedenc...

Even examples of the spec shows how unintuitive and "unpythonic" this is. Explicit is better than implicit.

IMHO adding features to the language to save 1 line of code for 10% of cases when you need it (I agree that there's occasional case when walrus will save you more than 1 line) is just bloat.

I am not a big proponent of Go, because it has its own flaws, though language is indeed very simple and creators of the language try to leave it simple.

IMO Python was very readable, super simple, intuitive and should stay that way, though recent releases show that Python is giving in for the feature bloat.

EDIT:

> Try to limit use of the walrus operator to clean cases that reduce complexity and improve readability.

Facepalm.

Re: What’s New in Python 3.8

#229
post #98

Earlier quoted context omitted.

That's like visual puns, and is limited to whatever symbols seemed important to the developer at the time. How do you discover how to type ß, °, «, ‡ etc? Android's gboard uses phonetics (long press [s] key for ß), symbolic similarity (long press [*] key for ‡) and visual similarity (long press [<] key for «) which is guessable for some symbols, but isn't discoverable for others (you can search for emoji by name, but…

The Mac has had, as a standard feature for decades, an on-screen keyboard to allow you to explore the results of different key combinations. It’s a great tool.

Cool! Where do I find it?

Re: What’s New in Python 3.8

#230
post #72

Earlier quoted context omitted.

Perl devs have been using the walrus expression for decades, but we just called it "assigning a variable with local scope in an expression". $ perl $a = "foo"; if ( my $a = "bar" ) { print "$a\n" } print "$a\n" bar foo

The reason why assignment expressions initially were not allowed in Python and why they had to introduce "walrus" was because in languages that used single equal sign for assignment enable to easily make bugs by typing "=" instead of "==".

A partial solution was already introduced with `with x as y`.
Post reply on HN