Earlier this year or late 2015, Packt Publishing asked me to be technical reviewer for a book called “Modular Programming with Python” by Erik Westra. It sounded really interesting and it ended up being one of the best books I’ve read from Packt. Note that I am the sole technical reviewer of the book. I’m not sure why Packt went that route for this book as they normally have 2-3 reviewers, but perhaps they are trying to accelerate their writing process.
- Why I picked it up: Primarily because Packt asked me to. However it really is an interesting book
- Why I finished it: Because the book is short and very well written
- I’d give it to: An intermediate developer who needs to brush up on their code organizational skills
You can get an eBook (PDF, EPUB or MOBI) version or a softcover.
This book only has 9 chapters and is 228 pages long.
Modular Programming with Python is actually quite fun to read. It is designed to help you learn how to make your code more modular and gives some really good examples. The first chapter begins by going over the way Python itself organizes its modules and packages. It goes on to explain why modular programming can be important and it has a neat example of creating your very own module, which happens to be a caching module.
The second chapter is all about creating your first modular program. It takes you through the steps you might go through to design a program in a modular fashion and then actually implements it. During the design phase, the author just stubs out the interface. Then in the implementation phase we get to actually add the code.
For chapter three, we learn how modules and packages are initialized. The author also goes over Python’s importing system. We learn how imports work, what relative imports are, controlling what gets imported, circular imports and more.
Chapter four is about creating a modular charting package. We learn how to chart using the pillow package, which is a fork of the Python Imaging Library (PIL). Then the author talks about how requirements for a projects change and how we must respond to them. In this example, we need a way to do vector images which pillow doesn’t support. So the author shows how to add the ability to create charts using Reportlab or pillow. This is also a really great chapter.
Chapter five looks at modular patterns, like encapsulation, wrappers, etc. I think the part I found most interesting was the portion of the chapter that covered dynamic imports, plugins and hooks.
In Chapter six, we learn about reusable modules. The author first describes what a reusable module is and then gives some examples. The rest of the chapter is devoted to creating a reusable module which happens to be a unit conversion module.
Chapter seven digs even more into Python’s importing system. It covers such items as optional imports, local imports, adding packages to sys.path, various import “gotchas”, dealing with globals and more. This was actually one of my favorite chapters.
For chapter eight, we get a change of pace. It’s all about testing our modules and deploying them. The chapter only gives the basics on unit tests, code coverage and test driven development. The bulk of the chapter is about getting a module ready for publication to Github or the Python Package Index.
The final chapter is supposed to demonstrate how modular programming techniques can make the process of programming itself more effective. It gives a pretty short example and wraps up the book.
Overall I found this book conveyed its message very well. The code examples are straight-forward and easy to understand. The writing is very good. Much better than what I normally see in Packt publications. I love reading neat or just interesting code and this book has several great examples. I did feel like the book ended a bit abruptly. While I don’t know what should have been added, I just felt like it could have had another chapter or two. Regardless, I do recommend this book to anyone who is having trouble organizing their code.
Modular Programming with Python
by Erik Westra
Other Book Reviews
- Python Playground – Geeky Projects for the Curious Programmer by Mahesh Venkitachalam
- IPython Notebook Essentials by L. Felipe Martins
- Creating Apps in Kivy by Dusty Phillips
- Kivy – Interactive Applications in Python by Roberto Ulloa
- Instant Flask Web Development by Ron DuPlain
- Real Python by Fletcher Heisler
- Python 3 Object Oriented Programming by Dusty Phillips