Re:Copying data is wasteful, mutating data is dangerous
by cultureswitch on Friday January 10, 2020 @08:22AM
(#22010730)
It's not equivalent but honestly this gotcha with lists will only show up in bad code and interview quizzes (i.e. bad code).
Re:Copying data is wasteful, mutating data is dangerous
by im3w1l on Thursday January 09, 2020 @04:33PM
(#22006056)
They aren't equivalent in C++ either.
Re:Copying data is wasteful, mutating data is dangerous
by perfunctory on Thursday January 09, 2020 @04:40PM
(#22006154)
My C++ is a bit rusty. Does it manifest itself in the standard library as well? The problem with python (in my view) is that this behaviour is implemented in the standard library and therefor propagates to the 3rd-party libraries by convention.
Re:Copying data is wasteful, mutating data is dangerous
by zabzonk on Thursday January 09, 2020 @06:02PM
(#22006820)
> Does it manifest itself in the standard library as well?
Yes. For example for std::string `a = a + b;` will (at least notionally) create a temporary string and then use the assignment operator. `a += b;` will not do this.
edit: I might have misunderstood your question. If you meant "why it's not equivalent" please see the falkaer's answer.