This module introduces copying behavior and transfer-style updates with mutable objects.
- Difficulty: Intermediate.
- Estimated Time: 35-50 minutes.
- Prerequisites:
03-advanced/structs-and-classes,03-advanced/constructors-and-invariants. - Cross-Language Lens: Use this module to contrast C++ ownership transfer with reference-heavy behavior in C#, Go, and Python.
python example/main.py- Assignment aliasing vs explicit shallow/deep copies.
- Transfer-style state handoff between objects.
- Clone helpers for predictable object independence.
- Avoiding accidental shared-mutable-state bugs.
- Assuming
=duplicates list contents. - Mutating data through one name and surprising another caller.
- Forgetting to clear source state after transfer operations.
- Python adapts the topic through aliasing, shallow copies, deep copies, and mutation boundaries rather than move semantics.
- Compared with C++ or Go, ownership is much less encoded in syntax and much more visible in object identity and shared state.
- The core comparison is accidental sharing versus deliberate copying.
- exercises/01.py: resource-like buffer with clone and transfer operations.
- exercises/02.py: insertion flow that contrasts aliasing and copied lists.
- exercises/01.py
- Input: buffer size and values.
- Output: logs showing clone and transfer behavior.
- Edge cases: zero-size buffer; repeated transfers.
- exercises/02.py
- Input: text values to store.
- Output: size and content checks after aliasing vs copying.
- Edge cases: empty strings; repeated insertions.
- I can explain aliasing vs copying for mutable objects.
- I can model safe transfer-style ownership changes.
- I can avoid unintentional shared-state mutations.
- I completed exercises/01.py.
- I completed exercises/02.py.