News for hackers. Stuff that matters.
Re:Why Do Python Lists Multiply Oddly? Exploring the CPython... by dragonwriter on Tuesday April 09, 2024 @12:24PM (#39981057)
> That's a different statement and expected, but in a language like Python, it isn't always clear whether my_list is a value or a reference

It is always clear, and it is 100% always a reference, with a set of cases where that reference is to a singleton or immutable object, and a subset of those cases where, in particular Python implementations, that singleton may effectively be implemented as a special case value.

If you treat it as a reference, you will never, ever be wrong.

Re:Why Do Python Lists Multiply Oddly? Exploring the CPython... by bmitc on Tuesday April 09, 2024 @03:11PM (#39983054)
And again, that decision is the more complex one. Inverting that such that everything is immutable by default and mutable or a reference by choice is the more regular, consistent choice that removes a fairly big swath of common programming problems.

The critique here is that it's a badly designed language in that it's design decisions often get in the way of writing software that works as you expect. We're not discussing about whether you can learn such a system. The discussion is a lament on why it had to be this way.

Re:Why Do Python Lists Multiply Oddly? Exploring the CPython... by dragonwriter on Tuesday April 09, 2024 @07:16PM (#39985337)
> And again, that decision is the more complex one. Inverting that such that everything is immutable by default and mutable or a reference by choice is the more regular, consistent choice that removes a fairly big swath of common programming problems.

Maybe. But that's largely irrelevant since we are discussing the impact of a syntax choice regarding an operator on an explicitly-mutable container type, and specifically the behavior of it used when the container also contains a member of the same type.

And the alleged surprising thing is not the mutability of anything, but thar after the operation, all the members of the other container are the same instance of the inner mutable container type.

Python being designed ground up with immutability by default and explicitly opt-in mutability would not directly have any bearing on this issue, as long as it still had the capacity to express immutable lists and the capacity to apply something like the list-reptition operation to them. Except it would probably make all of the involved examples more verbose.

Re:Why Do Python Lists Multiply Oddly? Exploring the CPython... by hughesjj on Tuesday April 09, 2024 @12:34PM (#39981154)
Yup, same as Java if you only use boxed primitives