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 21

Tantrum

image

21.1 Constraints

  • Every single procedure and function checks the sanity of its arguments and refuses to continue when the arguments are unreasonable.
  • All code blocks check for all possible errors, possibly log context-specific messages when errors occur, and pass the errors up the function call chain.

21.2 A Program in this Style

  1 #!/usr/bin/env python
  2
  3 import sys, re, operator, string, traceback
  4
  5 #
  6 # The functions
  7 #
  8 def extract_words(path_to_file):
  9 assert(type(path_to_file) is str), "I need a string!"
 10 assert(path_to_file), "I need a non-empty string!"
 11
 12 try:
 13  with open(path_to_file) as f:
 14 str_data ...
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