Skip to Main Content
Exercises in Programming Style
book

Exercises in Programming Style

by Cristina Videira Lopes
November 2015
Intermediate to advanced content levelIntermediate to advanced
304 pages
5h 23m
English
Chapman and Hall/CRC
Content preview from Exercises in Programming Style

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Exercises for Programmers

Exercises for Programmers

Brian P. Hogan
Street Coder

Street Coder

Sedat Kapanoglu
Handbook of Constraint Programming

Handbook of Constraint Programming

Francesca Rossi, Peter van Beek, Toby Walsh

Publisher Resources

ISBN: 9781482227376