Book Review: Modular Programming With Python
Book Review: Modular Programming With Python
Check out Mike Driscoll's book review for "Modular Programming With Python" and see if you might be interested in picking up a copy.
Join the DZone community and get the full member experience.Join For Free
Building real-time chat? Enroll in a Free Course on Mobile Chat Development.
Earlier this year or late 2015, Packt Publishing asked me to be a 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 two-three 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 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 straightforward 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 Pythonby Erik Westra
Published at DZone with permission of Mike Driscoll , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.