Jump to ratings and reviews
Rate this book

Clean Python: Elegant Coding in Python

Rate this book
Discover the right way to code in Python. This book provides the tips and techniques you need to produce cleaner, error-free, and eloquent Python projects. Your journey to better code starts with understanding the importance of formatting and documenting your code for maximum readability, utilizing built-in data structures and Python dictionary for improved maintainability, and working with modules and meta-classes to effectively organize your code. You will then dive deep into the new features of the Python language and learn how to effectively utilize them. Next, you will decode key concepts such as asynchronous programming, Python data types, type hinting, and path handling. Learn tips to debug and conduct unit and integration tests in your Python code to ensure your code is ready for production. The final leg of your learning journey equips you with essential tools for version management, managing live code, and intelligent code completion. After reading and using this book, you will be proficient in writing clean Python code and successfully apply these principles to your own Python projects.
What You’ll Learn Who This Book Is For Readers with a basic Python programming knowledge who want to improve their Python programming skills by learning right way to code in Python.

282 pages, Paperback

Published May 22, 2019

6 people are currently reading
32 people want to read

About the author

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
3 (9%)
4 stars
7 (21%)
3 stars
7 (21%)
2 stars
9 (27%)
1 star
7 (21%)
Displaying 1 - 7 of 7 reviews
264 reviews4 followers
February 6, 2020
I was going to read this but was disappointed to find glaring errors in the book. The code examples are wrong. There are simple mistakes like a variable name being changed or the use of the wrong number of quotations/ parentheses. It is clear the author did actually compile/ run these. There are also serious mistakes like... the code is straight-up wrong and the explanations are wrong. How was this published? Did no one edit it?
Profile Image for Jascha.
151 reviews
January 24, 2020
Clean Python is one of those books that, according to me, tries to cover way too many topics at once. Not a bad read overall, let's be clear. But nothing great either.

Let's go step by step: We can split the book in three sections: up to chapter 5 it's pretty much a long version of the PEP8 and the zen of Python. Nothing wrong with that, but hey, the PEP8 is like ...free.

The second part of the book are chapter 5 and 6, which cover very advanced and important topics such as Decorators, Context Managers, async and Corutines. Well, I am kinda biased here because I already know all of them, but if it weren't for the fact that those topics are very familiar to me, I wouldn't have understood. The examples are not very useful and the concepts are not clearly explained.

Finally, until the end we see topics such as testing, debugging, and all that stuff. Fair enough, even if testing along deserves an entire book.

Final thoughs: while I was reading the book I felt a bit ...forced towards the PEP8. Follow the light or be damned forever! I think that linters and the PEP8 are great but should never be used to reject a commit. What is most important in a project is consistency, even if the style used is not PEP8 compliant, at the moment. There is nothing worse than a code base where every module has a different style. Be consistent. Far from PEP8? We can slowly adapt what it suggests. Moreover, the standard library itself, if it were for pylint, should be discarded since it scores poorly.

I still strongly suggest Effective Python: 59 Specific Ways to Write Better Python and Fluent Python to anyone interested in advanced Python features.
Profile Image for Joseph.
22 reviews2 followers
November 5, 2021
This book is a good idea with AWFUL execution.
As others have noted, the book is RIFE with mistakes. Not only are the code examples wrong (or inconsistent) most of the time, they sometimes emphasize the *opposite* point to what the author is trying to say. If you disregard the many errors in diction and grammar, there appears to be no coherent thought process driving the flow of the chapters. Ideas are repeated inconsistently and sometimes expressed incompletely. I'm positive this book has not been edited.
It feels like the author had a tech blog (think those many "The Top 10 Python Commands You Should Know" articles on Medium) and cobbled together a bunch of past entries on the blog to make a book with no thought to how it would read when put together.

Most topics are treated very superficially and whatever treatment there is will not provide an adequate explanation for someone who doesn't already have a good familiarity with the topic being discussed.

The only good thing I can mention about this book is that it made me aware of several cool features in Python that I will definitely look into more deeply. I just have to go elsewhere for a good explanation on how to use them.
271 reviews8 followers
January 23, 2022
W samej książce jest dużo błędów, zarówno merytorycznych, jak i w kodzie. Autor myli argumenty z parametrami funkcji. Wartość domyślną parametrów nazywa kluczem. Jednak czarę goryczy przelało częste tłumaczenie autora czemu podejście A jest lepsze od podejścia B z perspektywy wyroczni. Jak można wmawiać czytelnikowi, że stosowanie namedTuple jest bardziej czytelne niż użycie podstawowych struktur danych. Prawie rzuciłem książką przy “przykładzie” dziedziczenia klas fruit i apple. 

Przykłady programistyczne pisane są chyba na kolanie. Zawierają literówki, odnośniki do nieistniejących zmiennych i funkcji. Chyba sam autor nie sprawdził ich w polecanych przez siebie IDE. 
 
Chyba najbardziej irytowało mnie powtarzanie tych samych treści w odstępie kilku stron (polecane biblioteki - pylint, opis OrderDict). Po prostu wyglądało to, jak dodawanie treści, bo było to dla autora korzystne. 

Co dobrego z książki wyniosłem. Utrwaliłem sobie stosowanie konceptów takich jak __init__ oraz __str__. Same pokazanie dekoratorów, było całkiem dobrze napisane. Bardzo ciekawy przykład programowania aspektowego, którego jeszcze nie widziałem na produkcji w aplikacjach napisanych w pythonie (np: pisząc klasy z metodą __call__ można przetrzymywać stan i robić walidację). 

Warto pamiętać o stosowaniu menadżera kontekstu “with”, gdyż zaoszczędzimy na tworzeniu bloków try i catch i zamyka on otwarte uchwyty do zasobów (np plików) 
102 reviews
September 15, 2020
In the beginning, they point out, that there is no good "clean code" book for Python. I agree with this statement, and I think it still applies:
There were a lot of suggestions which I would never apply, but nothing too bad until they proposed to "always use namedtuples" as return values and method arguments. That was the point were I stopped and decided this book is not worth reading further - at least not for me.

33 reviews6 followers
April 8, 2022
Sloppy execution with trivially incorrect and inconsistent code and explanations. Different teams have different objectives in writing code style guides and defining what clean code looks like (a nuance that seems to be lost on the author). Code correctness is usually not even mentioned in style guides because it is assumed that any clean code would minimally be correct. Almost every example in this book is incorrect. This is not the book you are looking for.
227 reviews1 follower
November 4, 2020
Tak jak autor napisał, mało jest książek o poprawnym pisaniu w Pythonie. Ta książka wypełnia tę lukę. Jednak, żeby źle pisać, trzeba umieć, jako tako programować. Więc ta pozycja jest raczej dla tych, co znają ten język. Nawet w minimalnym stopniu. Polecam
Displaying 1 - 7 of 7 reviews

Can't find what you're looking for?

Get help and learn more about the design.