Building reliable programs

Organize, test, reproduce, and revise small Python programs

Programs become easier to check and share when their data, code, dependencies, and changes are organized clearly. Building on the collections and files in the previous part, you compare how data structures affect runtime, memory use, and the behavior of copied values.

You then divide a program into modules and packages, and use a virtual environment to record and recreate its dependencies. Automated tests check expected behavior and help you repair defects. Git records changes so that you can compare implementations, recover earlier work, and collaborate.

Learning objectives

By the end of this part, you will be able to:

  • compare familiar collections through their supported operations, runtime growth, and memory use;
  • explain how references, mutation, equality, identity, and copying affect a program's data;
  • split a small program into modules with clear responsibilities and explicit inputs and outputs, and distinguish standard-library and external packages;
  • create a virtual environment, install dependencies, select its interpreter, and recreate the environment from a requirements file;
  • write and run pytest checks, interpret failures, repair defects, and retain regression tests; and
  • inspect changes with Git, make meaningful commits, compare versions, recover an earlier implementation, and use ignore rules and a shared repository.