Some Preliminaries
To make the design issues in the rest of the book clearer, we need to look at some of our motivational problems. One of these is the game of Blackjack. Specifically, we're interested in simulating strategies for playing Blackjack. We don't want to endorse gambling. Indeed, a bit of study will show that the game is stacked heavily against the player. This should reveal that most casino gambling is little more than a tax on the innumerate.
Simulation, however, was one of the early problem domains for object-oriented programming. This is an area where object-oriented programming works out particularly elegantly. For more information, see http://en.wikipedia.org/wiki/Simula. Also see An Introduction to Programming in Simula by Rob Pooley.
This chapter will provide some background in tools that are essential for writing complete Python programs and packages. We'll use these tools in later chapters.
We'll make use of the timeit
module to compare various object-oriented designs to see which has better performance. It's important to weigh objective evidence along with the more subjective consideration of how well the code seems to reflect the problem domain.
We'll look at the object-oriented use of the unittest
and doctest
modules. These are essential ingredients in writing software that are known to actually work.
A good object-oriented design should be clear and understandable. In order to assure that it is understood and used as well as maintained properly, writing Pythonic documentation is essential. Docstrings in modules, classes, and methods are very important. We'll touch on RST markup here and cover it in depth in Chapter 18, Quality and Documentation.
Apart from this, we'll address the Integrated Development Environment (IDE) question. A common question regards the best IDE for Python development.
Finally, we'll introduce the concepts behind Python's special method names. The subject of special methods fills the first seven chapters. Here, we'll provide some background that may be of help in understanding Part 1, Pythonic Classes via Special Methods.
We will try to avoid digressing into the foundations of Python object-oriented programming. We're assuming that you've already read the Python 3 Object Oriented Programming book by Packt Publishing. We don't want to repeat things that have been thoroughly stated elsewhere. In this book, we will focus solely on Python 3.
We'll refer to a number of common, object-oriented design patterns. We'll try to avoid repeating the presentation in Packt's Learning Python Design Patterns.