So we’re up to the second chapter of Tarek’s book. A short disclaimer before diving into it. I started this blog, basically one year after I had started programming with Python. The initial idea was to “convert” the Beginning Perl for Bioinformatics book to Python and see what were the advantages and disadvantages of both languages. I was far from being a advanced Python programmer, and the inception of the blog helped me getting close to that, even though I consider myself far from being an expert programmer in Python. I learned a lot working on converting the Perl and learned a lot from the comments and interaction with other programmers and visitors of the blog. As anything in life one’s path is long and tortuous and there’s nothing better than daily learning and exercise.

So, as I mentioned in the previous post, this book was tailored for someone like me. I needed a boost on advanced Python techniques and the second chapter just gave me that. Tarek writes in this chapter about good syntax practices below the class level, functions and methods that are common in daily usage. He starts with list comprehensions, that we have seen in this site. It’s a short and concise section and gives you exactly what you need about this functionality.

Next, iterators and generators. I had a little bit of background on iterators, and have used them here and there, but not a lot on generators. I learned a bit from this section, what you expect from a book like this, things like the close and throw. Although this was good first step on generators, I wished the section could be longer, but that maybe not the focus of the book.

Coroutines was a completely new subject for me. Maybe I haven’t been diving into Python as much as I needed to, but time is short these days and programming Python is not the first objective of my work. The example is complete and easy to understand, but again I wish it was a tad bit longer. Tarek then explains a bit of generator expressions (list comprehension for generators) and enters the itertools module. So far so good, it’s a nice summary (at least for me) of simple techniques that can be incorporated into daily coding. And then … Decorators.

I blame on my poor CS skills or maybe my whole background on programming, but I still cannot get decorators. In my short-sighted view of the programming world I cannot see a place, at least on the things I’m doing, where I can use a decorator. And here comes the first criticism of the book: I still cannot get after reading the section. One thing that would help a bit would be to have colours on the examples and maybe go over them explaining some code lines. But at the same time, I admit that this might be a personal problem, where the concept of decorators don’t fit into my brain, and maybe the focus of the book is to show this advanced technique to someone that has a better grasp of the concept.

Overall, it’s a very good chapter and a good pointer to some expert/advanced techniques in Python. Tomorrow, chapter 3, and we’re a going to see classes.

Reblog this post [with Zemanta]