Arno's Data Expertise

Data Engineering in a click

Powerful Python – review

This will be a blog post reviewing the technical book I’ve read named ‘Powerful Python’. I will address the topics it discusses, why I chose it, and why I think it’s a good or bad book.

Intro

Having a more experienced engineer in your team is a blessing to have. If you’re unsure of a certain python best practice you can just go ask that person. Usually he will be able to guide you. he can explain why one should use concept A or avoid concept B. The engineer can provide constructive criticism to help you grow. However sometimes you don’t have that more experienced person to turn to.

At my current client, I’m working in a team in which I’m the most senior python developer. Here I don’t have the luxury of a more senior team member. Even though I now have 5-ish years of experience, there are still plenty of topics on which I have questions. Are there better approaches, are their other techniques, is something a bad idea?

So to stay up to date and find answers to my questions, I tend to read a lot of technical books. The last book I covered was ‘Powerful Python’ by Aaron Maxwell. It was a pleasure to read and I received a lot of valuable information from it. The books covers a lot of intermediate to advanced techniques that, when applied on a regular basis can make a big difference. Let’s have a small overview of what I learned:

Logging and automated testing

    These were 2 chapters of which I was already very familiar. The author dedicates about 25 pages to these two topics which are nice for people who haven’t heard of these concepts yet. For me these concepts are a daily reality when developing and maintaining a Data Platform.

    Comprehensions, advanced functions, exceptions, classes & objects & module organization

      About half the book discussed features that are nice to understand well in python., but not essential in a day-to-day practice. For example is the use of comprehensions. The list comprehension is probably a concept that people get to know very easily. Copilot will suggest it as code very easily as well. Finding out that the comprehensions are not limited to lists only but also to sets, tuples and dicts widened my understanding.

      The book also dedicates a small section to the most diabolical python anti pattern or TMDPAP. This pattern discusses a coding habbit that programmers sometimes add:

      try:
      	# dirty code that could raise an obscure error
      except Exception as e:
      	pass

      This bad habbit obscures the valuable information of a stacktrace and just continues with the rest of the code. It means that a mistake could be made but there will be no way to figure out where it was caused. The better solution is to either log that the error had happened with enough information to be able to retrace the issue later, or execute some code that handles this exception. A combination of both is preferred. Also using more precise exceptions are advised.

      I’ll admit that after having read this chapter that I ran through my codebase to see if I had added this pattern by accident. Luckily I usually logged all the important information, but for 2 methods I was able to save myself from a headache down the line.

      Generators and decorators

        Finally, there were 2 chapters that I enjoyed because they were new to me. I had seen the use of decorators in unit testing before. But now thanks to the authors clear examples the usage and inner working has become clear to me. Generators will become my new go to method for objects that are prone for scaling. I will need to find some time to actually implement these into the codebase as an exercise. Otherwise I’ll probably stay to my old habits without reaping the benefits of these new concepts.

        Conclusion

        Is the book worth it?

        The book costs around 70€ which is a lot. The are probably better priced books out there that can teach you the same lessons. Also the internet can provide you with a lot of answers freely.

        But is it worth it?

        Yes, I do think reading this book will help you understand key concepts better. It will make you a greater engineer and help you deliver more value in the long run. The book addressed many key questions I had written down. While the internet is often a hot mess of outdated, contradicting messages, this book was the more senior engineer that I needed to guide me to become a greater python developer.


        Comments

        Leave a Reply

        Your email address will not be published. Required fields are marked *