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?" > 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? -- Steve _______________________________________________ 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/ATEXSIOIIUS33II7HOGGREPNXP4JTFUJ/ Code of Conduct: http://python.org/psf/codeofconduct/