3 ms·
When teaching Python to beginners, I struggle with the concept of mutability -- e.g. `sorted(mylist) vs mylist.sort()` without being able to refer to the concep
by danso 8y ago
When teaching Python to beginners, I struggle with the concept of mutability -- e.g. `sorted(mylist) vs mylist.sort()` without being able to refer to the concepts of memory and references. But it's not a terrible obstacle if you drill in extra adherence to logic and testing and jumping into REPL. After enough trial-and-error with `x is y` `x == y` and `id(x)`, the abstract concept comes through without having to acknowledge the existence of reference count.
- alimw 8y agoHardly a beginner at programming, but I also struggled with this when I picked up Python recently. The documentation doesn't make it obvious when functions have this sort of side effect, so like your students I play with the REPL to establish exactly what a function will do. Even then an unexpected side effect was the source of the single most perplexing bug in my program. I imagine that in complex programs this philosophy of sometimes-mutability-sometimes-not must lie at the root of a huge amount of programming error.