Book Review: Python Distilled
This article provides an overview of "Python Distilled" by David M. Beazley, a book that focuses on the essential core of the Python language.
Join the DZone community and get the full member experience.
Join For FreePython Distilled by David M. Beazley is a pragmatic book that presents some of the most important topics about the Python programming language in a concise form, designed to make it easier to find out the most relevant information bits in a context where resources abound and frequently are just too overwhelming.
Book Structure and Contents
The book is organized into 10 chapters. It starts off with the basics, such as variables, data types, operators, expressions, control flow, and looping. Compared to other books I have read recently, it uses a smaller font size, which is quite readable to me, but it may be less comfortable for some readers. On the other hand, it contributes to making it a lighter and less thick book, compared with other programming manuals. The book uses no syntax highlighting, but code samples are short enough that actually this does not become a problem at all.
The text is always short, simple, and as direct as possible, without long explanations or examples. It does not present step-by-step tutorials: this is not that kind of book. Think of it more like a reference guide that contains a summary of the most important language features. Need a quick refresh on how to use mapping? You got it. There is a section for that, and a small table that lists the most common operations, methods, and functions. The same goes for other similar features. It's like someone was attending the Python classes and then compiled a nice set of notes for you with the stuff you need to know, but without the extra fluff.
If you're just starting with Python, you may find this approach a bit too dry, and you may feel more inclined to read another book first. However, don't discard this one just yet. You may want to get back to it in a couple of weeks, as it works as a summary that helps to highlight a set of topics that are important.
If you have programmed a bit in Python, or have experience in other programming languages, this book may be especially useful, as its concise style provides a shortcut for the transition. You will probably be able to start writing some Python code quickly after the first three or four chapters, and then you can start digging into more advanced topics in the remaining ones. You will read about classes and objects, generator expressions, and context managers, and you will probably be able to understand how those features relate to the concepts you already have learned in C# or Java, for instance.
The author provides an interesting summary of protocols (you would probably call them interfaces in other programming languages), and how you may use them to make your code more Pythonic. Everyone talks about writing "Pythonic code," but this is something that frequently is overlooked. Chapter 4 describes number, comparison, conversion, container, iteration, attribute, function, and context manager protocols. Knowing about them and implementing them when appropriate can make a huge difference in the quality of a module of a package.
Chapter 5 covers functions, including variadic arguments, keyword arguments, positional-only arguments, recursion, lambda expressions, higher-order functions, and callback functions. It also covers several other features, including asynchronous functions and await
. Taking a hint from that, chapter 6 talks about several aspects related to generators.
In chapter 7, you get an overview of Python's object-oriented programming model and ways to avoid inheritance via composition or functions. The reader is shown how Python deals with class variables, static methods, properties and mixins, abstract classes, and more. This is a denser chapter, which speaks to the relevance of the topic. Object-oriented programming can be very powerful, but it also may be used in some confusing ways that are error-prone and have poor maintainability. Therefore, it is a chapter that can make you think more deeply and make you reconsider some earlier notions about OOP.
After such a dense chapter, the reader is presented with a much shorter one that describes modules and packages, how they help to organize a project's code and how the import
statement works.
No programming language is complete without input and output methods, so chapter 9 covers these topics, including data encoding, command-line options, environment variables, file I/O, and data serialization. Together with chapter 10, they also present some useful modules and functions from the Standard Library. It is not an extensive description, since the detailed documentation can easily be found online, nowadays. It's more like a roadmap where you can find a brief description of some useful tools, that you can then go investigate more if you need them.
Throughout, the book tends to present small examples and short code samples as it tries to explain the Python programming language itself. It does not cover the techniques and design or architectural patterns that are usually required in larger-scale projects. Once again, however, there are other (some of them much longer) books for that purpose.
Conclusion
Writing a concise reference book can be very challenging, especially when it covers a programming language that has matured over more than two decades, includes an extensive standard library and an enormous ecosystem of third-party packages, and quite a lot of established opinionated traditions on how code should be written. It requires a lot of choices and some compromises.
Python Distilled offers a good selection of information that will be useful for Python programmers that are in different stages of the learning path. I would recommend it particularly for those who have been using other programming languages and need a quick reference on Python, but also for those who have basic to medium knowledge of the language since the book also explores some advanced features of Python that may not be very obvious.
Disclosure Notice: For this review, I received a free copy of the book from the publisher (minus customs expenses). I do not personally know the author or the publishers, and did not receive any other compensation. The link to the author/publisher is provided as a reference only. I am not endorsing the company or making any profit from it.
Published at DZone with permission of Victor Domingos. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments