
Download the free Kindle app and start reading Kindle books instantly on your smartphone, tablet, or computer - no Kindle device required. Learn more
Read instantly on your browser with Kindle for Web.
Using your mobile phone camera - scan the code below and download the Kindle app.

Python Programming Patterns
Thomas W. Christopher (Author) Find all the books, read about the author, and more. See search results for this author |
- ISBN-100130409561
- ISBN-13978-0130409560
- PublisherPrentice Hall
- Publication dateJanuary 1, 2001
- LanguageEnglish
- Dimensions6.75 x 1.75 x 9 inches
- Print length538 pages
Editorial Reviews
From the Back Cover
The real-world guide to enterprise-class Python development!
- Enterprise development with Python!
- 20+ object-oriented patterns for large-scale Python development
- Maximizing scalability, robustness, and reuse
- Leveraging modularization, toolkits, frameworks, metaprogramming, and more
Python isn't just a tool for creating short Web scripts and simple prototypes: its advantages are equally compelling in large-scale development. In Python Programming Patterns, Thomas Christopher shows developers the best ways to write large programs with Python, introducing powerful design patterns that deliver unprecedented levels of robustness, scalability, and reuse. Christopher teaches both the Python programming language and how to "program in the large" with Python, using objects, modularization, toolkits, frameworks, and other powerful tools and techniques.
- 20+ proven object-oriented patterns for large-scale Python development: creational, structural, and behavioral
- Leverage the skills you've mastered in other object-oriented languages
- Design Python systems for maximum reuse
- Create cleaner, more comprehensible software systems
- Make the most of persistence, concurrent programming, functional programming, and metaprogramming
- Includes extensive working code and meaningful examples
If you've ever thought it would be great to use Python in real enterprise development, you're about to learn howwith Python Programming Patterns!
About the Author
THOMAS CHRISTOPHER is a principal in Tools of Computing LLC, a Chicago-area consultancy specializing in high-performance computing and object-oriented languages. With George K. Thiruvathukal, he co-authored High Performance Java Platform Computing (Prentice Hall PTR/Sun Microsystems Press) and Web Programming in Python (Prentice Hall PTR). Christopher is former professor at Illinois Institute of Technology.
Excerpt. © Reprinted by permission. All rights reserved.
Introduction
The major purpose of this book is to teach the Python programming language and, in doing so, to concentrate on facilities that make it easier to write moderately large programs, say 5,000 lines or so. Programming in the large is more difficult than writing short scripts. Writing a 5,000-line program is not just 100 times as much work as writing a 50-line program. The way you write a 50-line script does not work for 5,000-line programs.
The secret for successfully writing larger programs is modularization, breaking them into understandable, manageable components. Your goal will not only be to make the software comprehensible, writable, debuggable, and maintainable, but to make it reusable. The best way to write a 5,000-line program is not to have to write all 5,000 lines right then. If somebody else has written code you need and it is available, use it. The library of modules available with Python is large and full of useful code.
When you do write code, it is best to make it reusable. There is no reason to implement the same kind of thing over again. This means you typically will need to over-design the code, to make it more general than you need the first time. The object-oriented design patterns, that we will look at in Chapter 5, are useful ways to think about the design. They are stylized ways of using things which make the design clean and help you remember how to use the objects.
When you are implementing your designs, of course, there are numerous patterns available to reuse: data structures, algorithms, mathematics, concurrent and object-oriented patterns. Where there are well known ways of doing things, it is not cost effective to be creative.
Design and Programming Techniques
We will be looking at several kinds of software designs, components, and techniques. The fundamental way to organize software is the module. At a higher level, modules can be grouped into packages. Python's handling of modules and packages are the subject of Chapter 3.
Defining classes of objects is fundamental to many techniques. Objects and classes are the subject of Chapter 4 and object-oriented design techniques are the subject of Chapter 5.
Python has some built-in functions that are useful for functional programming. We discuss these in "Functional Programming" in Chapter 6.
Data types are not just sets of values. They include the operators, functions, and methods of manipulating those values. Abstract Data Types, ADTs, are data types implemented in software as opposed to the "concrete" data types built in to the language. Python has excellent facilities for implementing ADTs. You can define with "special methods" how your data type will respond to operators such as addition, x + y, or subscripting, xi. We devote Chapter 14 to looking at most the special methods. Chapter 15 is devoted to the subscripting and "slicing" special methods used to implement abstract container data types. Chapter 16 and Chapter 17 give examples of abstract container data types: priority queues and sets.
Concurrency involves allowing several threads of control (mini-programs) to run interleaved over the same period of time interacting with each other. They improve performance by allowing one part of the program to execute while another is waiting information to arrive. They also aid in program design, since it is often easier to design and understand the smaller programs than it is to design and understand a program that tries to do all their functions together. We discuss concurrency in Chapter 18, including the facilities available in Python's threading module, the monitor pattern (used to protect data from getting scrambled by concurrent access), and the dangers of deadlock and how to avoid it. Chapter 19 is devoted to an example monitor, Shareddb, that protects a shared data base from being mangled by concurrent updates and protects the transactions using it from deadlock. Chapter 20 presents another monitor, RunQueue, that allows thread objects to be reused. TransactionQueue is a variant of RunQueue to be used with SharedDB which automatically reschedules transactions that need to be tried again when they were unable to commit their changes to a data base.
Chapter 21 is devoted to regular expressions and Python's re module. Regular expressions are widely used to extract significant parts of text strings. The chapter includes an example scanner used by the parser presented in the next chapter. Chapter 22 shows how to use the TCLLk parser to recognize and execute simple statements. The behavior of the parser is specified by a context-free grammar augmented with "action symbols." Parsers are the next level up from regular expressions, facilitating the processing of text with nested subexpressions. The parser is an example of a framework: the parser is in control and you must write code that plugs into it.
Software
This book comes with software available through the author's web site, toolsofcomputing.com. Some of the software is described in this book; some is not because it would not demonstrate any new principles. There are three varieties of software:
Abstract Data Types
This book contains and describes the abstract container data types:
- DEQueue: a doubly ended queue,
- prioque and prioqueunique: priority queues,
- DisjointUnion: implementing the union-find algorithm,
- Set and PureSet: a set.
Also included is a prototype ADT implementation of rational numbers. Not discussed in the book, but available through the web site are multi-maps, directed graphs, undirected graphs, and bit sets.
Concurrent Programming
This book contains implementations of objects to aid in writing concurrent programs:
- Future: an assign-once variable,
- Latch: a single element buffer,
- SharedDB: a transaction-oriented monitor to share Python's dictionary-like data bases.
- RunQueue: a queue to allow reuse of threads,
- TransactionQueue: a version or RunQueue for transactions accessing a SharedDB object.
Included with the software, but not described in the book, are the translation of classes from the Tools of Computing thread package in Java, described in our book High-Performance Java Platform Computing. This includes the SharedTableOfQueues data structure that resembles JavaSpaces and the Linda system.
Parsing Framework
Chapter 22 shows the use of a parser generator and parser, the TCLLk system. TCLLk is available at the web site. The parser generator takes context-free grammars and generates parsing tables for them, if possible. The tables can be translated for use in a number of programming languages including Python, Java, and Icon. All the ports are available, not just the Python.
Included with TCLLk is a class StringScanner that provides an alternative to regular expressions for extracting usable parts of strings.
What the Book Is Not
Because of the space that must be devoted to presenting the Python language, this book cannot be a hard-core object-oriented design patterns book. Chapter 5 describes most of the usual design patterns and they are demonstrated throughout the book in the implementations of software, but they are not the exclusive interest.
Product details
- Publisher : Prentice Hall (January 1, 2001)
- Language : English
- Paperback : 538 pages
- ISBN-10 : 0130409561
- ISBN-13 : 978-0130409560
- Item Weight : 2.3 pounds
- Dimensions : 6.75 x 1.75 x 9 inches
- Best Sellers Rank: #7,313,089 in Books (See Top 100 in Books)
- #931 in Object-Oriented Software Design
- #3,533 in Object-Oriented Design
- #5,186 in Python Programming
- Customer Reviews:
About the author

Discover more of the author’s books, see similar authors, read author blogs and more
Customer reviews
Customer Reviews, including Product Star Ratings help customers to learn more about the product and decide whether it is the right product for them.
To calculate the overall star rating and percentage breakdown by star, we don’t use a simple average. Instead, our system considers things like how recent a review is and if the reviewer bought the item on Amazon. It also analyzed reviews to verify trustworthiness.
Learn more how customers reviews work on Amazon-
Top reviews
Top reviews from the United States
There was a problem filtering reviews right now. Please try again later.
First of all, I think the title of the book is misleading. This book is mostly an introduction to the Python language, not an introduction to design patterns in Python. It really doesn't have much discussion about design patterns outside of Chapter 5, which is devoted to the topic. And frankly, as an introduction to Python, it doesn't look that impressive.
Second, I think the writing is just poor. The author simply doesn't explain things very clearly. I tried to read chapter 5 on design patterns and came away with the impression that I was just reading gobbledy-gook.
So take this as one person's opinion, and nothing more. My background may be different from yours, and what looked like gobbledy-gook to me may be crystal-clear to you. But my advice is this: Do NOT buy this book sight unseen. If you're thinking of purchasing it, find a copy somewhere and look at it carefully before you buy it.
If you're looking for books to learn Python from, I recommend "The Quick Python Book" by Harms & McDonald, and "Python Essential Reference" by David Beazley. The best introductory book on design patterns is "Design Patterns Explained" by Shalloway & Trott. The best URL for information about design patterns and Python is:
* [...]
especially the links for:
* Design Patterns in Python
* Design Patterns mit Python (German, but the code is Python)
Gordon Macmillan, one of the technical editors of the book, gives a good description of the book in a thread on comp.lang.python:
[...]%40199.171.54.215&prev=/groups%3Fhl%3Den%26group%3Dcomp.lang.python
What I think this book does well is cover alot of ground on writing python with some pretty good examples that go beyond the usual intro book stuff. There is talk of threads, regular expressions, abstract data types, modules etc... stuff you need to do real work but that usually gets left out. To me this is really a kind of python for programmers type book with some very good examples. If that's what you're looking for then check out the table of contents. I liked it.
The goal of PPP is to teach you the Python language emphasizing the facilities that you will use to build larger programs, i.e. programs of several thousand lines.
Of particular interest is the section on abstract data types. I use ADT's, especially container ADTs, all the time. ADTs are new data types implemented in the language itself. To implement an ADT, you create a class, use other data structures for the "encapsulated" representation of the data, and write methods to provide operations on these types. You use "special methods" to implement unary operators, binary operators, subscripting, slicing, and attribute access, but these special methods have intricacies that you will need to know to use them. PPP explains them.
The section on concurrency are also noteworthy: it provides what I consider the best explanation of Python's threading module of all I have seen published. As an author of "High-Performance Java Platform[TM] Computing," I am an expert on threading.
PPP takes a broad definition of "patterns," including more than object-oriented design patterns. It presents concurrent programming patterns such as monitors, deadlock, producer-consumer and transactions, and it considers higher-level approaches to programming such as structured programming, modular programming, and functional programming.
Someone who knows object-oriented programming in another language will find useful information on how dynamically typed Python differs from statically typed languages such as Java or C++. Object-oriented design patterns (OODPs) are presented from a data-structures point of view, a "here's how the objects are linked together and what they do" presentation. The OODPs are used in examples throughout, but OODPs are only a part of the book.
I hope you like it as much as I do.
Top reviews from other countries
