Chapter 22
Passive Aggressive
22.1 Constraints
- Every single procedure and function checks the sanity of its arguments and refuses to continue when the arguments are unreasonable, jumping out of the function.
- When calling out other functions, program functions only check for errors if they are in a position to react meaningfully.
- Exception handling occurs at higher levels of function call chains, wherever it is meaningful to do so.
22.2 A Program in this Style
1 #!/usr/bin/env python
2 import sys, re, operator, string
3
4 #
5 # The functions
6 #
7 def extract_words(path_to_file):
8 assert(type(path_to_file) is str), "I need a string! I quit!" ...