Chapter 4

Cookbook

image

4.1 Constraints

  • No long jumps.
  • Complexity of control flow tamed by dividing the large problem into smaller units using procedural abstraction. Procedures are pieces of functionality that may take input, but that don't necessarily produce output that is relevant for the problem.
  • Procedures may share state in the form of global variables.
  • The larger problem is solved by applying the procedures, one after the other, that change, or add to, the shared state.

4.2 A Program in this Style

  1 #!/usr/bin/env python
  2 import sys, string
  3
  4 # The shared mutable data
  5 data = []
  6 words = []
  7 word_freqs = []
  8
  9 #
 10 # The procedures ...

Get Exercises in Programming Style now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.