O'Reilly logo

Exercises in Programming Style by Cristina Videira Lopes

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required