2017-02-01

Book Review

First heard about The Hacker’s Guide To Python at Pycon - 2014. I brought the ebook version and converted it to my favourite format .dead_tree and read it.

Hacker's Guide To Python #python

A photo posted by Ankur Gupta (@originalankur) on Feb 1, 2017 at 3:49am PST

I mentally classify Self Published Python books in two category.

Category One

Written by Authors who have gained insights from shipping Python software in production / worked on complex software products for years. Then converted these learning into a book.

Category Two

Written by Authors with only background in Python Training / little experience of working on complex / large software that used by people. These books rely on covering APIs, modules, remixing and improvising content found on the internet, or have chapters with code on building toy examples.

There are very few books that belong to Category One and this book does.

Here is a quick review / tour of What I learned from the book.

Chapter Two gives you a listing of standard modules that matter most in day to day Python Programming with a single line description. Helpful for those who just learned Python. The chapter shared an interesting “tale from the trenches” on How and Why Openstack migrated from SQLAlchemy to Alembic?. The chapter then shares a checklist of sort when evaluating external libraries. Insight like these put the book in Category One.

Chapter Three is on Documentation. This chapter shows us how to get started with Sphinx and reST for your documentation.

Chapter Four and Five talk about Distributing Python software and virtual environments. The chapter starts with disutils and trivial example with setup.py showing How it’s used?, followed by pbr and how it allows you to write your setup.py. pbr is pretty cool since it allows for automatic dependency installation based on requirements.txt, documentation generation using Sphinx and more. The chapter also shows how to share your project on PyPI. If you are one of those looking to put an open source project out Chapter Four is for you. Chapter Five is a simple introduction to virtualenv.

Chapter Six is on Unit Testing and talks about unit testing best practices from a Python standpoint. It touches upon everything from Fixtures, Mocking. It was from this book I first learned about subunit for test aggregation, archiving and isolation.

Chapter Seven and Eight talk about Decorators and Functional Programming. These two chapters have a lot of short code snippets to explain every aspect of decorators and functional programming in Python.

Chapter Nine is on Abstract Syntax Tree and the ast module. While it’s highly unlikely a vast majority of us Python Programmer would need it to use it. But finding programmatically what the current grammar looks like is insightful.

Chapter Ten is on Performance and Optimizations. It starts of with showing how to use cProfile , pyprof2calltree, usage of dis module. It moves on to show utility of bisect module and mentions blist and bintree packages. I learned of these modules first from this book. Imagine if you had a function called millions of time during a week ( say some basic math function in a graphic library you are shipping) you want to learn about memoization usage of functools.lru_cache. The first I read it I was like “Ahh They got a name for it”. It funny how lot of programmer come up with algorithms and patterns in day to day programming that already existing and documented, only to learn later about it.

Chapter Eleven is on Scaling and Architecure. The title means different things to different people. Someone coming from hadoop or spark background may have a different point of view. This chapter talks about multi-threading vs Multiprocessing aka multiprocessing package vs multithreading module ( Ahh GIL ). The chapter also touched upon event driven programming. Coming from C++/Qt I have learned first hand the simplicity of event driven programming and it’s suprising How many programmers haven’t even used one or aren’t aware of.

ImportPython Newsletter and Blog Subscribers can avail a 20% Discount on the book by clicking here.



Interview with Julien ( Author )

Ankur - Hey Julien. Why don’t you tell us a bit about yourself ?.

Julien - Hey! Well, sure. I’m a 33 years old software engineer living in Paris,

France. I work for Red Hat. While being based in Paris, I work remotely,

as my team is spread all across the world! That allows me to travel from

time to time and enjoy working with different views.

Some people might know me for my open source contributions: I’ve started

to be interested by Free Software 15 years ago. Starting as a user, I

quickly became a contributor (Debian, Freedesktop, GNU Emacs, Python,

OpenStack…) and then a maintainer (the awesome window manager, some

Python modules…) of various open source software.

Besides talking to computers, I spend a lot of time cooking and learning

cuisine. It’s like hacking with food – I find it wonderful. These days

I’m also training for Paris half-marathon, which I already ran a couple

of times!



Ankur - How did you get started in Python and later Openstack ?.

Julien - I got hooked by Perl pretty young because it was the high-level language

most of my friends were you using. So they taught me it and I started

programming using that. But as I learned more about programming and the

object-oriented approach, I discovered Python 10 years ago and decided

to learn it.

It took me a while to find a itch to scratch with Python, but I finally

did and my first project was rebuildd, a daemon to rebuild

Debian packages. I learned Python with a book from O’Reilly back then

and it was pretty disappointing. The book talked about things I did not

care about such as installation (I just did apt-get install) and the

rest was just copy/paste from the official Python documentation – which

I could search and read online anyway.

I wrote a few small Python application, and 5 years ago got hired to

work on OpenStack, where I really started to solve big problems with

Python.

Ankur - I read the book when you self published the first edition.
How did it start?. Did the book come out of your personal notes?.

Julien - When I started to work on OpenStack, I started to review code a lot: it

is part of the process of contributing to OpenStack. After doing that

for 2 years, I started to notice all the things new and seasoned Python

developers did not know about the language. So I (mentally) took note of

them, and that gave me a pretty long list of pitfalls engineers would

often fall into.

Around that same time, I read a book about self-publishing (Authority by

Nathan Barry) and it just stroke me: I should write a book to enlighten

my fellow Python developers!

Ankur - Openstack where I come from ( India ) has had a substantial impact in 2014 - 2015 on the Python ecosystem in terms of hiring, training new developers on Python for Openstack development. However 2016 has seen interest wane?. Few of my openstack developer buddies suggest everything from the project being complex, to Python not being the right language for the job?, the whole private cloud bandwagon / party coming to an end. Is Openstack adoption on decline and if so why?.

Julien - There was a huge increase in recruiting and staffing people on

OpenStack. Five years ago, nobody had a clue what the project would

become, so everybody jumped into the wagon and tried to influence the

project. Five years later, some have succeeded, some have failed, and

the hype has declined. The project is getting mature and therefore:

boring. That does not influence the adoption which is, on the other

hand, increasing, as the project is getting more fully grown.

Python is definitely a right language for the job. Using another

programming language would not solve anything new: there are little

technical challenges that would not be solved by Python. If there is any

problem in OpenStack, it is projects that are still carrying technical

debt – it takes to reduce it – and social issues, as in any activity

involving human beings!

Ankur - The new book that you are working on i.e. Scaling Python. How much of your experience with Openstack is the reason behind wanting to write on Scaling Python code?

Julien - A lot. OpenStack is supposed to work on platforms with very large number

of servers – which is not what your typical Web application is capable

of, for example. So designing applications to achieve large scalability

using Python is quite interesting and makes you discover things that you

had no idea existed. Once again, I think it’s interesting to share that

knowledge with the world – and writing a book is a good way to do it.

Ankur - Thanks for answering the questions. Best of luck.

Disclaimer - The Author of the book will be sponsoring an upcoming issue of the ImportPython Newsletter. I choose to review and interview the author as this is a book I have read years ago and recommend. Note importpython don’t make any money directly/indirectly from sale of the book.

Show more