No it doesn't? JS has it's own dumbness, but this particular ridicularity is Python-only. e.g. function test(x=[]) { x.push(1); console.log(x) } does what you'd expect.
And this is not the only place where this happens, it also happens in the very-innocent looking.
class Foo:
x = []
a = Foo()
a.x.append('wat')
b = Foo()
print(b.x)
['wat']
It's the kind of thing that makes you think how could this possibly be a serious programming language if they didn't consider this basic code?
Python is supposed to be simple and intuitive. Nothing is intuitive about having to do def __init__(self): self.x = [] instead of the above.
you actually seem to be correct... I must have misremembered. I vividly remember we had a bug in our Node-JS backend (not my choice) which worked exactly the same as this, but then it was probably passed in or a const...
View all comments
Show parent comment
2
u/tehdog 27d ago edited 26d ago
No it doesn't? JS has it's own dumbness, but this particular ridicularity is Python-only. e.g.
function test(x=[]) { x.push(1); console.log(x) }does what you'd expect.And this is not the only place where this happens, it also happens in the very-innocent looking.
It's the kind of thing that makes you think how could this possibly be a serious programming language if they didn't consider this basic code?
Python is supposed to be simple and intuitive. Nothing is intuitive about having to do
def __init__(self): self.x = []instead of the above.