Tidy First?, reflect next: chapter 1
Kent Beck's Tidy First? applications in my software development
I was fortunate to work directly with Kent Beck at Gusto. It’s poetic that Extreme Programming began with a payroll project, and we met over payroll. Being a child of software engineers, I grew up hearing about Agile’s effect on the industry. Where it made things better, and how it could go wrong. Then I experienced it myself over nearly 15 years in industry. I was excited to talk with Kent directly: and woo, but did I Have Questions ✨
I could summarize the Answers by saying nothing saves us from having to think. Womp, womp. Indeed there are so many questions he went and wrote a book about the question of tidying, and continues to write on his substack. The book’s title is a spoiler: Tidy First question mark.
It’s a great read. Short, simple, and thought-provoking. I found myself nodding along in agreement, sometimes raising a Questioning Eyebrow, and always seeing direct applications in my work & method. I appreciate how Kent grounds software design in real-world constraints such as the space-time continuum.
I decided to study Kent’s book by applying it to my own work. Unlike most of my career, a lot of my work is open-source these days [GitHub]. So I get to learn, and share my real-world process. Win win! Do note: not all my tidyings are themselves tidy. There’s a metaphor in there somewhere.
Chapter 1: Guard Clauses
Software has this way of going from:
if this:
that
to something like,
if !(this && (that || those))
|| (!those && something > whatsit)
|| (its_tuesday && weekdayConditions)
|| (its_wednesday && !weekDayConditions && specialWedsRules)
Oof. 😮💨 Simplifying conditions isn’t just good for engineering, but also for the heart.
I had coded my way into this delight of a condition:
if ((
not footprint[linear_coord]
and not at_center
) or (
oob
)):
pass
else:
# interesting work
It got that way through a series of behavior changes debugging test failures. I knew there’d be wet paint for a while so deferred making it “nice” until I understood better what “it” even was.
Here’s the tidying: commit e99617d Clean up get_neighborhood_peak. It’s about halfway through a series of refactors for PR 181: Generalize Fast-Hybrid to n-dimensional arrays. It was an inside-out refactoring of a 2d algorithm until the top-level function worked on n-dimensional arrays.
if not oob and (not out_of_footprint or at_center):
# interesting work
The overall result is still not a simple conditional. And I couldn’t guard a simple return/continue because there’s a non-trivial loop increment to handle in all cases.
But hey: progress, not perfection.
Chapter 2 up next.
This is the first in a series of posts reflecting on the book Tidy First? by Kent Beck. Follow his ongoing work here:
About Binary Alchemy
Binary Alchemy is the art of software engineering: part programming, part philosophy. Software melds the elegance of mathematics with the unyielding realities of zeroes and ones. Software is ethereal, less constrained than materials in its ability to metamorphose (or metastasize).
I wrote my first line of code in 1989. I have decades of experience building, operating, and re-building software spanning from MS-DOS to GCP, AWS, and Azure. ️⚙️ I’ve worked with startups and large enterprises, including Google, Microsoft, Square aka Block, Gusto, and others.
I provide software & cloud architecture consulting services. Learn more: RedwoodConsulting.io