Book Review: The Hacker's Guide to Python a.k.a Serious Python

Posted on 31 Jan 2019 in Python • 4 min read


The Hacker's Guide to Python Serious Python

Last year, I had a need to boost up my Python knowledge. Reading blog articles and searching for a solution in Stackoverflow have helped me solving particular issues. However, most of the solution that I found will not last long in my head. Thus, I was searching a book for advanced Python developer which provide me more deep understanding, practical example and tips.

Then, I found out The Hacker's Guide to Python* by Julien Danjou in the third edition. Meanwhile, on January 17th, 2019 he has published a new revision of this book which is called Serious Python. Based on Julien's site, he has developed Python code for more than 10 years and wrote blog articles and Python books. Moreover, the book's website provides a lot of information about the content, such as the feedback of the readers and the content.

For me the 5 top topics are:

The Python Modules, Libraries, and Frameworks

I can read this chapter quite easy and it allows me to do repetition and refresh my Python knowledge about the modules, libraries and especially the frameworks. Since Python has a huge active community, there are plenty of new good frameworks. For me, the most important sections are the section The External Libraries Safety Checklist and Using and Choosing Frameworks. Both sections give me a checklist on how to choose an external library and a framework.

We’ve already established that replacing an external library after you’ve already written code that makes use of it is a pain, but replacing a framework is a thousand times worse, usually requiring a complete rewrite of your program from the ground up. ~ Julien Danjou

Unit testing

The chapter Unit Testing depicts quite many techniques to prepare, build and manage unit test for a software project. This chapter covers mostly the theory, from the basics, mock objects until testing policy. Julien didn't compare and write the pros and cons from the available Python modules for unit test, such as nose, pytest, and testify.

Python Documentation using Sphinx

In the chapter Documentation, Julien describes how to write a Python software and API documentation using Sphinx. However, to test and do the getting started with a small test project, I recommend following the quick start instruction in the official website.

Functional Programming

I learned the programming language Lisp in my first semester at the university. So this chapter has brought me back to my student time :). The interesting sections in this chapter for me are the generators, yield statement, and itertools. The generators is a significant part of an advanced Python developer. I can remember how these topics play an important role to process big data during my Udacity Nanodegrees.

To be admitted, until now I almost never use the itertools module. We need this module to manipulate an iterator. The practical example of the itertools in the book are quite short and clear to understand. These are some of the itertools' functions: accumulate(iterable[, func]) chain(*iterables) count(start, step) cycle(iterable) repeat(elem[, n]) permutations(iterable[, r])

I did then read the complete documentation in the official documentation about itertools.

Performace optimization

I'm glad to read this chapter due to a lot of new knowledge and tips. First, I've never known and used about the cProfile, dis, and memory_profiler tools. The bisect module and memoization was also a new module for me.

Optimization should never be done prematurely, that is, without first performing proper profiling. It is too easy to waste time rewriting some barely used code with a faster variant while missing central pain points. Don’t miss the big picture. ~ Julien Danjou

Things that are not in the book

Things that are not included in the third edition are:

  • the virtual environment topic shall be updated since I use Pipenv now. So a comparison between virtualenv, virtualenv-wrapper, and Pipenv would be very useful for other readers.

  • I miss the Python framework details comparison if I want to build a simple and fast web application, no Django, Pyramid or Flask tutorial, and tips. Of course, this topic may bloat this book content and web application topic is not a hacker guide :).

  • Some useful beginner scripts for a daily programmer life may not covered in this book. For such a case, I can recommend this book Automate the Boring Stuff

Conclusion

Even though there are some topics that I missed, I would recommend the book to improve someone's Python knowledge and the software development process. I read much interesting stuff which I didn't know before, such as the optimization tools, itertools module, and the checklist hint to choose an external library and a framework.

In my opinion, the book may be suitable for data scientists and intermediate Python developer who lacks some Python system tool or for intermediate Python developer. The book provides a deep inside of the Python world and the history of some modules and libraries in the past years. There are also six interviews with some experts which share their interesting experience.

If you want to buy the book or another book called Scaling Python from Julien, you can use this affiliate link*. I'll get a small amount of commission from Julien without changing the book price.

Happy reading!