Teaching Code by Typing It: Inside a 2015 Python Primer for Kids

The Book That Asked You to Type

When Brendan Scott wrote Python For Kids For Dummies in 2015, he made a bet: the way to learn programming is not by reading code, but by typing it. Character by character. Mistake by mistake. The book’s central thesis is that competence emerges from incremental, hands-on construction of working programs within a constrained, beginner-friendly environment – IDLE and Python 2.7.9. Each project refactors the previous one to introduce a single new concept while modeling professional habits such as docstrings, constants, and guarded main blocks. Scott called this “gaining wings” through typed repetition and debugged iteration.

The curriculum unfolds across four weekly modules. Week one covers the interpreter, literals, and basic arithmetic. Week two introduces functions, scope, and random numbers. Week three tackles strings, lists, dictionaries, and file I/O. Week four culminates in classes, magic methods like __init__ and __repr__, and pickle serialization. Two capstone projects anchor the middle weeks: “Cryptopy,” a Caesar cipher implementation, and an address book with binary persistence. A times-table math trainer occupies the final module.

Pedagogy of Manual Entry and Small Pieces

Scott asserts that typing code forces engagement with syntax and logic in a way that copy-pasting never does. He argues that professionals “manage daily mistakes by coding in small, testable pieces.” This drives the book’s structure: every project begins with a stub, adds one mechanism, tests it in the shell, then integrates it. The reader is encouraged to use IDLE’s shell for immediate feedback, to comment out code rather than delete it, and to trace execution with print statements. Debugging is taught as a first-class skill: rubber-duck explanation, IDLE’s breakpoint debugger, and the discipline of isolating a single change.

Why Python 2.7 in 2015?

The choice of Python 2.7.9 was deliberate and time-bounded. Scott cited three reasons: superior third-party library support at the time, the Minecraft Pi project’s dependency on Python 2, and macOS’s default inclusion of 2.7. He predicted the ecosystem “will change over the next couple years.” The text adopts Python 3’s print() parentheses for forward compatibility but retains 2.7 syntax elsewhere – raw_input, integer division truncating toward negative infinity, cPickle for speed, and range returning lists. For a modern reader, every syntax example, installation step, and library reference requires translation. The book now functions best as a historical artifact of Python pedagogy or a structured exercise set for porting to Python 3.

Core Concepts Taught Through Gotchas

Scope as Compile-Time Name Binding

Sections 12 and 13 present Python’s scope rules through a concrete bug: a function that prints a variable before assigning to it later raises UnboundLocalError. The reason? Any assignment in a function makes that name local for the entire body, determined at compile time. The author describes the lookup order as current function → global → built-in (LEGB without the Enclosing layer), noting that global/nonlocal and nested scopes are deferred. This turns a classic beginner trap into a teachable moment about when Python decides what a name refers to.

Mutability and In-Place Modification

The book treats list.reverse() and list.append() returning None while mutating the original as deliberate “gotchas.” So is random.shuffle() mutating in place. The goal is to prevent the common beginner pattern reversed_list = a_list.reverse(). By encountering the None return value early, learners internalize that some methods modify the object and return nothing – a distinction that bites even experienced developers in other languages.

Performance-Aware String Handling

The Caesar cipher project explicitly warns against string concatenation in loops, citing O(n²) copying in CPython due to immutable strings. It teaches list accumulation plus ”.join(list) as the idiomatic alternative. The author presents this as a CPython implementation detail, not a language guarantee – a nuance often lost in introductory texts. The cipher itself rotates a 95-character printable set by three positions, building encryption and decryption dictionaries via enumerate.

Serialization via pickle with Explicit Security Caveats

The address book project uses cPickle (aliased as pickle for speed) to dump the entire AddressBook instance. Scott warns twice that pickle.load() on untrusted data executes arbitrary code and that pickling requires hashable objects. He implements no mitigations. The warning is accurate – pickle docs confirm arbitrary code execution via __reduce__ – but the lack of a safer alternative (like JSON) reflects the book’s focus on core language mechanics over production hardening.

Monkey-Patching as a Teaching Tool

In Section 25, a standalone __repr__ function is assigned to AddressEntry.__repr__ after class definition. The author acknowledges this is unconventional but simpler than editing the class body retroactively. It demonstrates dynamic method attachment – a powerful feature that also introduces the concept of monkey-patching without diving into the descriptor protocol or __slots__.

Configuration Flags Over Code Duplication

The cryptopy.py module uses a runtime constant ENCRYPT = True/False to toggle encryption and decryption without code changes. Scott likens this to DEBUG logging flags. It’s a small but professional pattern: configuration over duplication, introduced before the halfway point.

Terminal-Width Pragmatism

The math trainer’s horizontal table layout assumes a ~70-character terminal width, calculates that five 14-character formatted tables fit per line (70/14=5), and implements batch slicing. The author notes this breaks for upper > 12 and that os.get_terminal_size() (Python 3.3+) would be the dynamic solution. This constraint-driven design teaches learners to think about output formatting in a fixed environment – a skill that transfers to logging, CLI tools, and embedded displays.

IDLE-Centric Workflow as a Constraint

The book teaches IDLE-specific shortcuts: Alt+3/Alt+O for comment/uncomment, Ctrl+]/Ctrl+[ for indent/dedent, F5 to run, shell tab completion, history recall via arrows. It notes that the Editor lacks live completion for prior variables and that sys.exit() raises SystemExit inside IDLE due to shell integration but behaves normally externally – an experiential claim, not independently verified. For 2015 beginners on Windows, macOS, or Raspberry Pi, IDLE was a zero-configuration gateway. Today, the absence of virtual environments, pip, pytest, or modern editors like VS Code marks a clear boundary between then and now.

Practical Use and Legacy

Despite its obsolescence, the book models several professional habits early: docstrings (PEP 257), constants in ALL_CAPS, if __name__ == “__main__”: guards, configuration flags, and guarded sys.exit(). Its debugging toolkit – print tracing, rubber-duck explanation, IDLE debugger, “comment out, don’t delete” – is practiced repeatedly. The explicit Python 2/3 differences (raw_input/input, print statement/function, integer/true division, range list/iterator, cPickle/pickle) serve as a diff checklist for porting. Security literacy appears in the pickle warnings and the Caesar cipher’s “cryptographically trivial” label, introducing the idea that serialization and encryption require threat modeling.

Limitations That Became Liabilities

Python 2 reached end-of-life in January 2020; macOS removed system Python 2.7 in 2022 (macOS 12.3). Installation instructions reference Firefox/Internet Explorer and Python 2.7.9 installers; modern browsers and Python 3.10+ workflows differ. Syntax throughout uses raw_input, print statements, cPickle, % formatting, range returning lists. No f-strings, dataclasses, breakpoint(), pathlib, venv, or type hints. The environment is IDLE-only; no VS Code, PyCharm, virtual environments, pip, requirements.txt, or pytest. Tablet guidance reflects 2010s constraints; SL4A (Scripting Layer for Android) is unmaintained. Error handling for ValueError from int(‘abc’), KeyError for characters outside CHAR_SET, missing files, permissions, or encoding issues is absent. Pedagogical simplifications become misconceptions: “everything is an object with attributes and methods” plus dir() ≈70 names for a string in 2.7.9 presented as the object model; CPython’s object header mechanics reduced to “prototype data structure.” Monkey-patching __repr__ shown without context of descriptor protocol or __slots__. cPickle speed claim unquantified; pickle security warning repeated but unmitigated. Structural rigidity appears in hard-coded filenames (C:\Python27, “address_book.pickle”), fixed-width formatting (breaks for upper > 12), single-file monoliths. Random output in Silly Sentencer and math trainer hinders automated testing. No modules/packages beyond the single cryptopy.py; no import best practices. Unverified claims and subjective language blur the line between fact and enthusiasm: real-world deployments (ISS Robonaut 2, CERN, Spotify, Netflix, YouTube, Google) lack verification dates; author’s subjective assessments (“sublime and beautiful,” “totes awesome”) sit alongside factual claims without demarcation; learning outcome (“wings”) unverified; publisher disclaimer limits liability.

Leave a Reply