On 06/12/2021 23:13, Steven D'Aprano wrote:
On Mon, Dec 06, 2021 at 10:17:06AM +0000, Rob Cliffe via Python-ideas wrote:

If your language only has one, early binding is better.
That's your opinion.  It's not mine.  Witness the Stack Overflow
questions asking why `def f(arg=[])` "doesn't work".
Of course it works. It does *exactly* what it is designed to do. There's
no exception, no crash, the computer doesn't catch fire.

You might as well claim that "import doesn't work" because people have
trouble importing modules that aren't on the PYTHONPATH.

What they should be asking is "Why is my expectation different from what
Python does?"
I put "doesn't work" in *quotes*.  I am sure you know exactly what I meant.  Perhaps we should be asking "Why is Python's behaviour surprising to so many people?". We could design a language where `+` meant subtract and `-` meant add.  And it could work perfectly.  Doesn't mean that's a good design.


And if your language gives you late binding, it automatically gives you
early binding with no effort at all.  Simply make the default value
something that you never change.
It might never change, but it is still re-evaluated every time it is
needed. That's what late binding means.

As I said, an optimizing compiler might be smart enough to recognise
that some expressions are a constant, like `1`, but you can't count on
it. And if the constant expression is `[]` and you want to use the same
list each time, instead of a new list, then you have to store that list
away in a global variable that you have to manage.


True, late-binding has the overhead of evaluating the default value on
every call.  I concede that disadvantage.  I would think that in many
cases it is unimportant.  But if it matters - hey, use early binding
instead.  That's a reason to have both.
Indeed. But aren't we discussing what to use if we can only have one?


No, why?  We already have one.  We are discussing (re PEP 671) adding the other.  Nobody is proposing to remove early binding and replace it with late binding.
Steven, sometimes I think you argue solely because you like arguing.
Best wishes
Rob Cliffe
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/GHKXHPLPTTZTFNPQ3XCMNH3QLTGZOOWV/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to