Computer Science I / State, Mutation, and Side Effects
Practice question · Sort into groups

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)

Hints
  1. Ask whether the statement would still hold after one of the lists is mutated.
  2. 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

Why

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.

Read the lesson: State, Mutation, and Side Effects →

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