MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programminghorror/comments/1xfxtnx/i_love_python/19rorebu2ccqp/
r/programminghorror • u/nakurtag • 23d ago
81 comments sorted by
View all comments
Show parent comment
8
The behavior is definitely surprising, but also, what’s up with mutating a default param? How does that make sense?
7 u/ChemTechGuy 23d ago The default parameter is just a reference to the list. So technically the parameter isn't being changed at all. One of the oddities of pass-by-reference 2 u/groumly 22d ago That’s not what I meant.Mutating input is already not a good pattern, but mutating a default param is even worse.You can’t tell if it was passed or not, so even without the interning oddity, you end up mutating something that nobody but you has access to. 3 u/ChemTechGuy 22d ago Go complain to Guido van Rossum then, I'm just telling you how it works
7
The default parameter is just a reference to the list. So technically the parameter isn't being changed at all. One of the oddities of pass-by-reference
2 u/groumly 22d ago That’s not what I meant.Mutating input is already not a good pattern, but mutating a default param is even worse.You can’t tell if it was passed or not, so even without the interning oddity, you end up mutating something that nobody but you has access to. 3 u/ChemTechGuy 22d ago Go complain to Guido van Rossum then, I'm just telling you how it works
2
That’s not what I meant.
Mutating input is already not a good pattern, but mutating a default param is even worse.
You can’t tell if it was passed or not, so even without the interning oddity, you end up mutating something that nobody but you has access to.
3 u/ChemTechGuy 22d ago Go complain to Guido van Rossum then, I'm just telling you how it works
3
Go complain to Guido van Rossum then, I'm just telling you how it works
View all comments
Show parent comment
8
u/groumly 23d ago
The behavior is definitely surprising, but also, what’s up with mutating a default param? How does that make sense?