Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Events
Videos
Audiobooks
Packt Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds

Free eBook - Clean Code in Python - Second Edition

4.6 (34 reviews total)
By Mariano Anaya
  • A new free eBook every day on the latest in tech
  • 30 permanently free eBooks from our core tech library
  1. Introduction, Code Formatting, and Tools
About this book
Experienced professionals in every field face several instances of disorganization, poor readability, and testability due to unstructured code. This second edition has been updated to reflect new best practices in Python 3.9, helping developers write professional, scalable, and maintainable code. It introduces advanced object-oriented design, decorators, descriptors, and refactoring strategies using SOLID principles. Whether modernizing legacy projects or building new applications, this book provides practical techniques to write cleaner and more efficient Python code using the Python standard library and manage your projects successfully. The book begins by describing the basic elements of writing clean code and how it plays a key role in Python programming. The book discusses object-oriented programming in Python and show you the design principles of software testing and how to resolve problems by implementing software design patterns in your code. In the concluding chapter, we break down a monolithic application into a microservices-based one starting from the code as the basis for a solid platform. By the end of this clean code book, you will be proficient in applying industry-approved coding practices to design clean, sustainable, and readable real-world Python code.
Publication date:
January 2021
Publisher
Packt
Pages
422
ISBN
9781800560215

About the Author
  • Mariano Anaya

    Mariano Anaya is a software engineer who spends most of his time creating software with Python and mentoring fellow programmers. Mariano's principal areas of interest besides Python are software architecture, functional programming, distributed systems, and speaking at conferences. He was a speaker at Euro Python 2016 and 2017. To know more about him, you can refer to his GitHub account with the username rmariano. His speakerdeck username is rmariano.

    Browse publications by this author
Latest Reviews (34 reviews total)
Clean Code in Python - Second Edition has helped me begin to fill some of the gaps in my code education. My sincere thanks to Packt Publishing for giving me the opportunity to review it!PROS:- It's great for an inexperienced developer. The author clearly knows his stuff. I would be hard-pressed to name another Python book that goes into this level of detail.- This is an excellent technical reference for Python. I can envision a time when, thanks to this book, I won't have to visit StackOverflow half as much.CONS:This book is DENSE. It truly is a reference text wherein the author gets down to business and doesn't tiptoe around the point. Some authors are horrible about that and fill their work with unnecessary anecdotes or ridiculous metaphors. This author did none of that. To me however, the lack of anecdotes detracts somewhat from the readability.BOTTOM LINE:The best thing about this book is the real-world use cases highlighted by the author. I typically work alone when I code but could see how his development team-oriented approach would apply. It's a good reminder to make your code readable to other humans since, as he put it, the code is for us, not for the machine.In conclusion, I would definitely recommend this book to anyone looking to clean up their act: one-person or small development teams, rogue analysts, or hobbyists looking to take the plunge into production coding.
As someone who is getting back into Python after many years, this book is a Godsend. This is an extremely valuable and rigorous work which covers the best practices for writing clean code. As a developer I can't express how important clean code is when working in a team or when simply publishing code. This book thoroughly goes through every aspect you need to know about; formatting, documentation and tooling. Later topics such as Pythonic code and the best traits of good code are covered. This book fills me with confidence when approaching writing Python code and has really helped me. Also and vitally important; testing and design patterns are covered in detail. This book is really exceptional and highly recommended.
Full disclosure. I was provided a copy of the book by Packt for free and in return, I promised that I would create a review on Amazon. Please note that the publisher did not put any stipulations on the review. In other words, I did not have to provide a positive review.The book is a tour deforce as to what one needs to consider when it comes to writing clean code. It begins by stating that there is no sole or strict definition for clean code. It goes on to say that tools like linters help but that there is no way to create a formal measurement for clean code.It explains that this is because programming is not about communicating with machines but that it is about communicating ideas to other developers. In other words, clean code is like pornography, you know it when you see it.The tour de force covers standard topics like inheritance in detail. The discussion of inheritance begins with the standard warning that each time that a sub-class is manifested, tight coupling is also created. Remember that coupling is a yucky thing.The book provides two questions to help determine whether or not the inheritance design is appropriate. The first question asks whether or not all inherited methods are used? The second question asks how many methods are overridden? If you are not using all the methods and are overriding many methods, it is probably a design mistake.After you have determined that you probably have a design mistake, it talks about some of the potential causes. For example, a superclass may be vaguely defined and contain too much responsibility. This in turn enables corrective action.The preceding generalities are then concretized by using http.server from the Python Standard Library as an example of when to use inheritance. Afterward, the book provides anti-patterns.It doesn't stop there, it then goes on to cover multiple inheritance. It begins by explaining why Python does not have the diamond problem. The diamond problem is the usual standard reason for not using multiple inheritance.Mixins are the last topic related to inheritance that is covered. Mixins are demonstrated using a parser that takes a string and provides iteration over it by values separated with hyphens. This functionality is implemented via a BaseTokenizer. The next level of complexity is that want values to be in the upper case. One solution is to just create a new class. In this case, you can't do that because a lot of classes are already extending BaseTokenizer and don't want to impact them. The solution is to create UpperIterableMixin and then use multiple inheritance to create Tokenizer(UpperIterable, BaseTokenizer).Other topics related to clean code are covered in just as much depth. That is why the book is 423 pages long.Like anything in real life, the book is not perfect. The goal of the book is clean code. However, it spends time in minutia like an entire section titled "Delegating into smaller coroutines – the 'yield from' syntax". The other side of this is that it ignores topics in Python like multiprocessing and subprocess. However, these are just minor warts because nothing is ever perfect.The bottom line is that the cost of the book will pay itself the first time that you apply any of its concepts. A book, with editors and tech reviewers, ensures high-quality content. When you look at blogs on the internet, you never know what you will get.The other advantage of a book is its table of contents. It will quickly limit the number of items that have to look at as well as providing a structure for those items. When you Google, how many blogs will you have to look at before finding what you need and determining its quality?Again, let me emphasize that the investment in the book is well worth it.faThe Bit Plumber
Recommended For You
Expert Python Programming - Fourth Edition

Attain a deep understanding of building, maintaining, packaging, and shipping robust Python applications

By Michał Jaworski and 1 more
Python Data Cleaning Cookbook

Discover how to describe your data in detail, identify data issues, and find out how to solve them using commonly used techniques and tips and tricks

By Michael Walker
Data Engineering with Python

Build, monitor, and manage real-time data pipelines to create data engineering infrastructure efficiently using open-source Apache projects

By Paul Crickard
Mastering Python for Networking and Security - Second Edition

Tackle security and networking issues using Python libraries such as Nmap, requests, asyncio, and scapy

By José Manuel Ortega