Image source
I like Python a lot. But this fcking design decision is so annoying. I cannot tell you how many times I have tumbled over this now by accident.
pull down to refresh
Image source
I like Python a lot. But this fcking design decision is so annoying. I cannot tell you how many times I have tumbled over this now by accident.
Using mutable objects as default values is a bad idea. I think that's the premise, but yea... "default value" is odd.
I didn't know this. I thought method params are newly instantiated and destroyed each function call.
Learn new things everyday.
Python is a great language but I don't like the aesthetics (of the language and the community). I like working with beautiful things. Ruby is much better in this respect
aesthetics of the language?
aesthetics and the community?
I would agree. Python is kind of like helvetica and Ruby is more like caligraphy. Meaning, there's something about Ruby's aesthetics that make it feel more like art.
Interesting, I thought all this time this isn't limited to Python but a general reference vs value problem. However, Javascript doesn't express this behavior:
function surprise(myList = []) { console.log(myList) myList.push(1) } surprise() // prints [] surprise() // prints []I definitely just assumed argument default values were instantiated on each function call. Python’s behavior would be like defining an array outside the scope of the function and using its reference as the default parameter value. I guess it’s clear in JavaScript because
[]constructs a new array?Why did they do this? I assume it's useful in some respect or maybe it's just easier for the interpreter.
I can't tell you for sure why this decision was made but this concept is only strange to us coming from modern programming languages that have a strong separation between what is code and what is data .
An example of this is e.g. the let-over-lamda paradigm where you can change what a function does by calling it.
This is not possible in rust.
There should be lint rules warning about this, what a trap
https://xcancel.com/hot_girl_spring/status/1859642773059797181