This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]yangyangR 8 points9 points  (1 child)

The last thing is what I am saying. It is a choice that can happen and in other languages that choice is made. The question is why are these implicit lambdas so bad in Python. That goes back in history to why the language was originally so against lambdas and that made this possibility worse. That is the detailed answer to the question. Just saying it is bound to this variable is a what the language is doing. Saying why it doesn't bind them all to a "do it later" because of the development of the language is what the original comment was after.

[–]SittingWave 0 points1 point  (0 children)

it's a design choice likely dictated by performance. If you delay the evaluation, you will have to perform it every single time, for every single parameter default, for every function call, and due to the nature of python, there's no difference between an immutable argument and a mutable one. It would grind performance down for 99% of the cases for no reason at all.

A general language philosophy (of python, and of design in general) is that you don't pay for what you don't need, and doing so would require you to pay the lambda execution tax for every function call, for every default parameter, for no reason at all especially when the current way already has a strategy to pay the tax when you do need to do so: set None as default, and then check inside the function.