TDD and Mindfulness
Posted on October 12, 2022 by Michael Keane GallowayMeditation is not about feeling a certain way. It’s about feeling the way you feel. - Dan Harris, 10% Happier
Early in 2022 I read Dan Harris’s 10% Happier. I’ve had this book on my To Read list since 2018 after listening to an episode of Serious Inquiries Only about meditation. I’ve long been predisposed to think that meditation was bull shit, and hearing two skeptical people discuss the practice and how it’s impacted their lives helped dislodge my preconceptions. They mentioned both of Dan Harris’s books, and so I added them to my To Read list, and bought 10% Happier. Fast forward past many years, a pandemic, wedding, moves, and job stress; and I finally sat down and read the book.
In 10% Happier, Dan Harris chronicles how he went from being an attention and adrenaline seeking drug addict to having multiple panic attacks on national TV to finding some measure of happiness and calm through meditation. Like me, he started as very skeptical of the idea of meditation (and some of those who promote it like Deepak Chopra), but through a thorough journalistic investigation, as well as self experimentation, he found that mindful meditation really does work. I’m not going to lay out all of that here. I found the book rather compelling, and would encourage anyone and everyone to read it.
One thing that I found incredibly resonant was how similar mindfulness meditation and my practice towards Test Driven Development (TDD) seemed. In meditation, you focus on the breath, and when you’re distracted by a stray thought, you return your focus to your breath. When I try to engage with a red-green-refactor loop in TDD, I am focusing on my code. There may be distractions that pull me away from my red-green-refactor loop, but I often note them and return back to the code at hand much like returning to the breath. As something goes wrong, I can see the indicator of a test failing, and act. I’m not scrambling to figure out what’s going wrong. I’m focused.
Unfortunately, I can’t always engage with TDD in my current work environment. There’s often legacy code that might take too much time to wrap in appropriate tests (among other reasons). That often leads me to be a lot more reactionary. Something goes wrong and stress spikes. I’m jumping in to fight the newest fire, and then I’m jumping to the next priority to then jump to something else that needs my attention. I find it’s a lot harder to have a calm even approach to work without TDD, and there’s more context switching which adds overhead leading me to tire out quicker during my day.
There are trade offs of course. I’m slower when I use TDD. It’s undeniable that it takes longer to write the test and the business logic that the test exercises over just the test. It’s harder to get coverage on my changes when there are code bases without any tests. I just finally added a unit test project to a component that is multiple years old which had no tests, and required major refactoring to be able to test the business logic. Last but not least, it’s harder for me to engage with TDD without large chunks of focus time. With the return to the office, I’m finding that I have less focus in general being in middle of a bunch of cubicles instead of a dedicated room at home. As I’ve reached seven years at my current company, I also find that I have a lot of interruptions because of the tribal knowledge I possess. I often have to field questions on where certain logic resides, why a component was built, or what is the process for getting emergency changes into production. It’s certainly harder to focus on coding with TDD with all of these distractions. I still manage to do it where I can.
With some of the aforementioned interruptions as well as other stressors and thoughts on mindfulness, I’ve decided to add meditation to my day. I want to see if it helps my stress management, and to see if it helps me gain more insight into when I can get more TDD done. My company has a wellness room, and I’ve never used it before. I’m going to see if over the next month or so if I can take 5 minutes out of my day to meditate. Maybe I’ll have something interesting to report back on for another blog post.