News for hackers. Stuff that matters.
Re:Understanding a Python Closure Oddity by BerislavLopac on Tuesday June 18, 2024 @03:10AM (#40714917)
> Everything in Python is evaluated at runtime

That is not correct. Python generally has two "runtimes": one is on import, when all of the module level code is evaluated; and the runtime, when the bodies of various functions and methods are evaluated. The two can be combined, e.g. by importing a module from within a function, but generally they are separate.

> Bytecode is just a form of caching

Not quite. It is perfectly possible to deploy just the bytecode and disable recompiling on import.

> Python doesn't have a standard

Of course it does -- CPython is the reference implementation, so its behaviour is "correct".

Re:Understanding a Python Closure Oddity by crabbone on Tuesday June 18, 2024 @10:27AM (#40718253)
You invent your rules as you go. It's not interesting to have a discussion when you don't have a point, but just trying to argue for the sake of an argument. To give you an example:

> > Bytecode is just a form of caching

> Not quite. It is perfectly possible to deploy just the bytecode and disable recompiling on import.

Yes! If you engineer your cache in such a way that it contains all the data that you may ever need, then you can just use the cache! Wow, what an amazing discover you just made! But seriously... you don't really see the irony of your writing?

> CPython is the reference implementation

Similarly, the reference implementation of what? What standard does it implement? None! The answer is none, because there isn't. It's a deliberate decision by the Python developers. Python isn't the only language like that. For instance, neither Rust, nor Go, nor Perl, nor Ruby, nor PHP, nor Java... a lot of popular languages chose not to have a standard. There are benefits and downsides of this decision, but I don't want to discuss these here. But it's a fact. Python doesn't have a standard, intentionally.