You face a problem with your code. Maybe something is bugging you about the design approach. Or maybe you’re just plain stuck. What can you do to break through a mental block?
During one job interview, I remember asking how the candidate approached problem solving. That candidate’s answer has stuck with me over the years:
I stop the car. I get out of the car and walk around it. I get back in the car.
This really is “one weird trick,” and surprisingly effective. It acknowledges that repeating the same thing without change will probably yield the same result. So, stop.
Reminder: ‘Going for a walk’ is a pro debugging technique.
— Kris Jenkins (@krisajenkins) November 16, 2017
You see, once I’ve decided on a tentative approach, my mind digs in. It really wants to push through until that approach yields a solution. But if the approach doesn’t work, my mind keeps digging deeper — digging and digging until ruts form.
I need ways to dislodge my thinking out of that rut. I need to get access to different points of view. There’s one meta-trick, but here are 5 different ways to apply it:
One thing I practice is the Pomodoro technique:
I emphasize the act of physically stepping away, because it seems to do something for me.
While you can use any timer, I discovered a problem:
A notification that dismisses itself wasn’t enough to actually interrupt my work. I need a stronger reminder to keep me from having lousy evenings.
Thankfully, my friend Radek Pietruszewski has written an app that does exactly what I need! Check out Tadam on the Mac App Store.
Stop working on the current problem. Pick a different task. Occupy your mind with something else for a while.
Put down the problem for the day. Without a computer, briefly consider the problem before going to bed. Then go to sleep. Freed of the need to concentrate, your dreaming mind may explore other possibilities.
(This is actually the approach I took for this blog post. I wanted to write about my latest Swift coding on the Marvel Browser TDD sample app. I sketched out some ideas, and went to bed.)
I already TDD’d an Objective-C version of a class that authenticates calls to the Marvel API. There were things about it that bothered me, but not enough to go back and revisit. The important thing at the time was to make progress — any progress.
But my Swift version came out somewhat different. I still TDD’d the simplest things, starting with simple methods. And from my earlier effort, I was interested in using closures for injecting different algorithms.
Maybe because Swift closures are more uniform and less wordy than Objective-C blocks, something different emerged. Programming languages have different strengths and expressiveness, so trying an implementation in a different language may open your mind to alternate approaches.
(I’ll write about my Swift code in a separate post.)
No matter how much you rest your mind, it’s still your own mind. The quickest way to get a different point of view is to get input from a different person.
This is the strength of Pair Programming. Two people are much less likely to hit a mental block than one person. And when you do, switch roles. That is, the driver becomes the navigator, and the navigator becomes the driver.
What if two people, pairing together, hit a roadblock? Add another navigator. This moves us closer to Mob Programming.
When we’re stuck on problems, we need ways to see different possibilities, different points of view. This can come from doing some kind of “mind reset,” which is often physical. It can also come from getting more people on the problem.
Whatever you do, stop the car.
What are your favorite ways to jar your mind loose to see alternate approaches to a problem? What techniques and tools work for you? Please share in the comments below!
Jon is a consultant on Clean Code for iOS, focusing on Test Driven Development, unit testing, refactoring, and design. He's been practicing TDD since 2001. You can learn more about his background, or see what services he can bring to your organization.
Please log in again. The login page will open in a new window. After logging in you can close it and return to this page.