Month: March 2017

An overview of the book "Effective Python"

For some time I have been working on moving from beginner to intermediate Python programmer. One step in that direction is reading the book “Effective Python – 59 Specific Ways to Write Better Python” by Brett Slatkin. Finally I have manged to finish the book during the holidays!

 

The book belongs to the “Effective” series of Addison-Wesley , which was started by Scott Meyers who is the author of “Effective C++” (1992). ¬†All books in the series is about different topics of a specific subject. The topics all have separate items (sub-chapters), which are numbered. In the case of “Effective Python”, there are 59 specific topics covered. I really like the concept since it is possible to read one or two topics each day. Each topic is independent, hence no risk of not remembering what it was all about if having a longer break like a week.

The book has 8 broader chapters:
  1. Pythonic Thinking
  2. Functions
  3. Classes and Inheritance
  4. Metaclasses and Attributes
  5. Concurency and Parallelism
  6. Built-In Modules
  7. Collaboration
  8. Production

If being experienced in programming but a python newbie, chapter 1,2 and 3 is a really good introduction. The concepts and patterns are the same as in others programming languages but the chapters show how to apply it in python. For all of you that have some experience of python, it is no surprise that the python examples are shorter and easier to read and understand compared to other languages. Good advice is given together with examples regarding slicing, list comprehensions, arguments, return values, and iterators. Reading them in this condensed format saves a lot of time compared to acquiring the knowledge by reading discussions at stackoverflow.

Once understanding and tried the concepts of chapter 1-3, the chapters 7 and 8 are the most important. The chapters deal with the issues that always appear when a program starts to scale up, the team grows, and installing in a production environment. In chapter 7 the items give advice in docstrings, how to arrange packages and modules, using a root exception, and isolate dependencies using virtualenv. Chapter 8 is more about unittesting and interactive debugging, and how to configure for multiple different environments. Experienced programmers will recognize many items in this last chapter.

If you have gained experienced and developed some programs in python, chapters 4, 5 and 6 fit very well. Chapter 6 is about processes and threads, and explains well-known concepts like use locks to prevent races, coordinate threads using queues, and how to put jobs on different processor cores in python. Chapter 7 gives a short introduction into some of most important builtin modules. The last chapter to mention is 4 which contains some specific python concepts like metaclasses and attributes. Meta-classes, attributes and decorators are interesting concepts which gives new dynamic possibilities to expand classes during runtime or enforce checks every time a method of a class is called. Might be interesting if writing generic frameworks (data-binding) or mockup during unit-testing.

This is definitely a book that will increase the knowledge of a beginner to intermediate python programmer! Many of the items are easy to absorb and start using right away in your daily work, other items (or chapters) are something you might return to once you have reached the level where they make sense. Keep a copy of the book on your desk to look into once in a while, or why not start each day by a new item?

Advertisements