To make the design issues in the balance of the book more clear, we need to look at some the problems that serve as motivation. One of these is using object-oriented programming (OOP) for simulation. Simulation was one of the early problem domains for OOP. This is an area where OOP works out particularly elegantly.
We've chosen a problem domain that's relatively simple: the strategies for playing the game of 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.
The first section of this chapter will review the rules of the game of Blackjack. After looking at the card game, the bulk of this chapter will provide some background in tools that are essential for writing complete Python programs and packages. We'll look at the following concepts:
- The Python runtime environment and how the special method names implement the language features
- Integrated Development Environments (IDEs)
- Using the pylint or black tools to create a uniform style
- Using type hints and the mypy tool to establish proper use of functions, classes, and variables
- Using timeit for performance testing
- Using unittest, doctest, and pytest for unit testing
- Using sphinx and RST-based markup to create usable documentation
While some of these tools are part of the Python standard library, most of them are outside the library. We'll discuss installation of tools when we talk about the Python runtime in general.
This book will try to avoid digressing into the foundations of Python OOP. We're assuming that you've already read Packt's Python3 Object-Oriented Programming. We don't want to repeat things that are nicely stated elsewhere. We will focus on Python 3.
We'll refer to a number of common object-oriented design patterns and will try to avoid repeating the presentation in Packt's Learning Python Design Patterns.
We'll cover the following topics in this chapter:
- About the Blackjack game
- The Python runtime and special methods
- Interaction, scripting and tools
- Selecting an IDE
- Consistency and style
- Type hints and the mypy program
- Performance – the timeit module
- Testing – unittest and doctest
- Documentation – sphinx and RST markup
- Installing components