Second edition is here!

Clean code in Python, sec­ond edi­tion has been pub­lished, and here are the main high­light­s!


What’s new from the previous edition?

The main change is that the book has been up­dat­ed to Python 3.9. The pre­vi­ous edi­tion was start­ed when Python 3.6 was new, and by the time it got pub­lished, Python 3.7 was just re­cent­ly re­leased. Since then, a lot has changed in Python and the book ad­dress­es the new fea­tures.

In par­tic­u­lar, there’s been a lot of im­prove­ments in the area of asyn­chro­nous pro­gram­ming. More to the point, asyn­chro­nous pro­gram­ming is be­com­ing even more com­mon on all pro­ject­s, so the en­tire chap­ter 7 (o­rig­i­nal­ly ded­i­cat­ed to gen­er­a­tors and it­er­a­tion) has been re­vis­it­ed with a strong fo­cus on asyn­chro­nous pro­gram­ming, show­ing how to al­so write more suc­cinct code in this mod­el.

All chap­ters have been re­vis­it­ed, and the ex­am­ples up­dat­ed to take ad­van­tage of the lat­est de­vel­op­ments in Python. One ex­am­ple is the new as­sign­ment ex­pres­sion, in­tro­duced in Python 3.8. This new edi­tion shows how to take ad­van­tage of those fea­tures in or­der to write more com­pact code that’s eas­i­er to read and main­tain.

The tools and li­braries have been up­grad­ed as well, and more tools are in­tro­duced. For in­stance, im­por­tant con­cepts like de­pen­den­cy in­jec­tion are now sup­port­ed with a li­brary that makes things eas­i­er in Python.

What to expect from the book

You can ex­pect a new ver­sion that fol­lows the same pat­tern of pre­sent­ing an in­tro­duc­tion to the con­cepts be­ing learn­t, fol­lowed by ex­am­ples that il­lus­trate the idea. As al­ways, I try to keep the ex­am­ples con­cise as to avoid dis­trac­tion­s, and fo­cus on the top­ic at hand, whilst at the same time, make them rel­e­vant ex­am­ples. This mean­s, the code in the book rep­re­sents sit­u­a­tions that might very well hap­pen in a re­al pro­jec­t, as op­posed to made-up things like Fi­bonac­ci se­quences.

The chal­lenge here is try to make it rel­e­vant for dif­fer­ent au­di­ences: soft­ware de­vel­op­er­s, sys­tems ad­min­is­tra­tors, and da­ta sci­en­tist­s. Even though the book fo­cus­es on soft­ware con­struc­tion, the con­cepts (and their cor­re­spond­ing ex­am­ples), are al­so rel­e­vant for da­ta pro­cess­ing for ex­am­ple.

It’s still a book with a prag­mat­ic ap­proach. I dis­cuss the the­o­ry, but at the end of the day, the goal is that you’re pre­sent­ed with some­thing you can ef­fec­tive­ly im­ple­ment in your day-­to-­day tasks. In this re­gard, the ex­am­ples are clear enough that you could ex­trap­o­late from them to ap­ply the con­cept for your­self in your project­s.

What motivated me to write a new edition

You! Yes, the first edi­tion got a re­al­ly good re­cep­tion. Thank you for your feed­back and sup­port! I’m al­ways look­ing for ways to share my knowl­edge and teach oth­ers so they can de­vel­op their skill­s. I start­ed this with my cowork­er­s, then moved to meet-up­s, and then I start­ed speak­ing at con­fer­ences. I’ve al­ways be­lieved that this way I could share what I’ve learn­t, so writ­ing a book felt like the log­i­cal next step. But I nev­er re­al­ly got a grasp on how many peo­ple were learn­ing from the con­tent I pro­duced, un­til I got your feed­back from my first book, and that re­al­ly mo­ti­vat­ed me!

In ad­di­tion to that, tech­nol­o­gy changes all the time, evolves, and we (peo­ple) al­so im­prove over time. Over the past two years, since the first edi­tion a lot has changed in Python, and I’ve al­so growth a lot (per­son­al­ly and pro­fes­sion­al­ly). I em­barked in­to more chal­leng­ing pro­ject­s, and gained more ex­pe­ri­ence on good soft­ware en­gi­neer­ing prac­tices and run­ning projects at scale. At the same rate, Python was re­leas­ing new ver­sions with more fea­tures. The con­flu­ence of these two things, land­ed me in­to the re­al­iza­tion that was time for a new, im­proved ver­sion of the book.

I hope you en­joy this edi­tion as much as I did writ­ing it! :-)