3 ms·
Forget about production, how did this make it into python? This is so unbelievably stupid it makes PHP look like a sensible language.
by ohgodplsno 3y ago
Forget about production, how did this make it into python? This is so unbelievably stupid it makes PHP look like a sensible language.
- quickthrower2 3y agoIt is perfectly sensible… if your language is guaranteed immutable everywhere
- faefox 3y agoThis is the question people should be asking rather than trying to identify which Digg employee should be retroactively thrown under the bus. Just a completely insane design decision.
- silvestrov 3y agoThis is one of those things that are so bad it warrants breaking backwards compability, possibly by releasing a python v4.
- faefox 3y agoIf they start today they could complete the migration by the mid-2040s!
- contravariant 3y agoIt's an interesting decision to be sure. Then again it's not really that arcane, the question is simply whether you calculate function defaults once or on every invocation. Python made the choice to run it once. What I don't get here is why they didn't simply use 'None' instead. If a parameter is optional then 'None' makes way more sense than an empty list.
- fantasizr 3y agoIt's one of the top python posts on S/O, every python developer finds their way to this discovery https://stackoverflow.com/questions/1132941/least-astonishment-and-the-mutable-default-argument https://stackoverflow.com/questions/1132941/least-astonishme...
- geenat 3y agoThis. Should have been taken out in Python 3, but nah, still present even today.
- paulddraper 3y agoI suspect because it's easier to implement defaults as values than as expressions. The scoping of list comprehensions in Python 2 was far less justifiable, IMO.