logoalt Hacker News

mattclarkdotnettoday at 3:31 AM9 repliesview on HN

Python really needs to take the Typescript approach of "all valid Python4 is valid Python3". And then add value types so we can have int64 etc. And allow object refs to be frozen after instantiation to avoid the indirection tax.

Sensible type-annotated python code could be so much faster if it didn't have to assume everything could change at any time. Most things don't change, and if they do they change on startup (e.g. ORM bindings).


Replies

mattclarkdotnettoday at 4:11 AM

To clarify, it is nuts that in an object method, there is a performance enhancement through caching a member value.

  class SomeClass
    def init(self)
      self.x = 0
    def SomeMethod(self)
      q = self.x
      ## do stuff with q, because otherwise you're dereferencing self.x all the damn time
show 2 replies
stabblestoday at 8:00 AM

That was how the Mojo language started. And then soon after the hype they said that being a superset of Python was no longer the goal. Probably because being a superset of Python is not a guarantee for performance either.

wolvesechoestoday at 8:39 AM

> Python really needs to take the Typescript approach of "all valid Python4 is valid Python3"

It is called type hints, and is already there. TS typing doesn't bring any perf benefits over plain JS.

show 1 reply
BiteCode_devtoday at 10:12 AM

There will be not Python 4, and 3.X policy requires forward compat, so we are already there.

bloppetoday at 4:25 AM

But that's just not what python is for. Move your performance-critical logic into a native module.

show 1 reply
panzitoday at 3:47 AM

Isn't rpython doing that, allowing changes on startup and then it's basically statically typed? Does it still exist? Was it ever production ready? I only once read a paper about it decades ago.

show 1 reply
rich_sashatoday at 4:30 AM

I think sadly a lot of Python in the wild relies heavily, somewhere, on the crazy unoptimisable stuff. For example pytest monkey patches everything everywhere all the time.

You could make this clean break and call it Python 4 but frankly I fear it won't be Python anymore.

show 2 replies
mattclarkdotnettoday at 4:20 AM

Oh, and while we're at it, fix the "empty array is instantiated at parse time so all your functions with a default empty array argument share the same object" bullshit.

show 2 replies
musicaletoday at 5:36 AM

> Python really needs to take the Typescript approach of "all valid Python4 is valid Python3

Great idea, though I don't think they learned anything from the Python 2 to 3 transition so I wouldn't hold my breath.