This post originated from an RSS feed registered with Python Buzz
by Aaron Brady.
Original Post: Review: Expert Python Programming
Feed Title: insom.me.uk
Feed URL: http://feeds2.feedburner.com/insommeuk
Feed Description: Posts related to using Python. Some tricks and tips, observations, hacks, and the Brand New Things.
Well, I'm waiting for a long overdue fsck of a very large LUN to complete, and I had an email off the person who sent me my review copy of 'Expert Python Programming', so now is as good a time as any to actually get around to it. I should explain that the book came in during one of my periods of inactivity on the blog, and I've only started posting again recently (excuses, excuses).
When I was contacted by Packt Publishing, they also sent over a sample chapter. I'm not going to link to that here, because in my opinion it gives you completely the wrong idea about the book. It was Chapter 8: Managing Code, which largely covers using a version control system and setting up BuildBot. In the context of the whole book (which is; using Python's advanced features to keep your code clean and compartmentalised, with the apex of this being packaging it all up in a library) it makes perfect sense, but it doesn't stand on its own.
So; to the book.
First things first, I want to say that I really think that this is a great book. It got me excited about Python again like I was when I first learned it, and I loaned it to a colleague who has learned Python properly off the back of it (it doesn't cover any basics, but he had already done the 'Learning Python' style tutorials, what he needed was some reason to chose Python over the other languages he already knows). I think a lot of this is down to my not keeping abreast of all the cool things that went into 2.5 and 2.6, and also exactly what impact their proper use could have on my code.
The book starts with getting Python and an IDE set up. I find this so utterly maddening in the day and age of Googling for HOWTO's. If you buy this book, you already need to know Python, so why wouldn't you know how to install it? I remember reading on Dive into Mark that Apress basically forced him to have a 'installing' chapter, so perhaps that's what's happened here.
Once you skip the fluff, however, it drops you straight into list comprehensions, iterators and generator expressions. Even though I've been using these in anger for a couple of years now, the clear explanations of what are actually quite abstract ideas provided additional insight into how they are meant to be used, and how they are implemented.
Decorators are up next. Personally there was nothing new here, but it's great to see a good text covering this subject, because it's probably the thing I miss the most from languages that don't have them. The amount of boilerplate setup and tear-down for simple functions that can be moved into decorators, and the accompanying clarity of the code, is really significant, yet I don't think you see it enough.
The next two chapters introduce the class resolution rules and syntax and style suggestions. Again, as I see the sweet spot for this book in winning advanced programmers over to Python, I think these chapters excel in that role. The experience of my colleague reading here helps, as he's a C++ fan, and needs to know the nuances of multiple inheritance for the way that he builds things. (I personally have quite tame class hierarchies, but it's still very interesting to see how properties and __getattr__ fit into the stack).
Chapters 5 through 10 detail building a module, packaging it with setuptools, storing it under version control and documenting it. As I said above, if the ideal of reusable code is to package it into a library for others, then these chapters give you a literal step by step to convert your code into a Python Egg.
The final chapters relate to testing, profiling and optimising. I think that there's already quite a lot of good coverage of these topics in other Python books, but for completeness, they fit in well in here. The book ends off with a chapter on design patterns, both Python specific and Pythonic versions of the classics.
Overall, the book is extremely well written and edited. Some mistakes have crept through, and other reviewers have picked up on this, but I didn't find anything so glaring that it interrupted the book for me.
If I have an overall criticism it's in the books title; I don't think that knowing more advanced ins and outs of a language make you an expert - that comes from the time you spend building real and practical things. More to the point, I don't think that it does the book justice - it could easily have a title like 'Software Engineering with Python', which to my mind would sell what it actually is to the working programmer.
Finally, and it's not a criticism per se, but now that 3.0 is out in the world, a little of the relevancy of the book is lost. Hopefully it sells well enough that a second edition covering the much larger set of changes in 3.0 is published.