Sort each statement by whether it concerns the identity of an object or merely its value.
Groups: About identity (same object) · About value (equal contents)
- The two lists compare as equal right now but are stored separately
- Both lists currently hold 1, 2 and 3
- Mutating through one name is visible through the other
- Rebinding one name leaves the other pointing at the old object
- There is only one list in memory, reached by two names
Hints
- Ask whether the statement would still hold after one of the lists is mutated.
- Equal contents can stop being equal; being the same object cannot stop being true by mutation alone.
Show the answer
About identity (same object): Mutating through one name is visible through the other, There is only one list in memory, reached by two names, Rebinding one name leaves the other pointing at the old object
About value (equal contents): Both lists currently hold 1, 2 and 3, The two lists compare as equal right now but are stored separately
Identity is about how many objects exist; value is about what they contain at this moment. Two separate lists can be equal today and different after one append, whereas two names for one list can never disagree. Treating equality as if it implied identity is the aliasing trap the lesson names.
Practise State, Mutation, and Side Effects
The app has 7 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.
More questions on State, Mutation, and Side Effects
- A function that writes to a global variable is as easy to test as one that only returns a value, provided…
- Order these events so that every stated outcome is true at the moment it is written.
- A function is called twice with identical arguments and returns a different answer the second time. Select…
- A function sorts the list it is given rather than returning a sorted copy. Why is that worth documenting…