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 is surprisingly effective. It acknowledges that repeating the same thing without change will 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 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:
1. Mental Block? Use the Pomodoro Technique
One thing I practice is the Pomodoro technique:
- I set a timer for 25 minutes.
- While the timer is running, I try to concentrate on a single task.
- When the timer finishes, I physically step away from the computer for 5 minutes.
I emphasize the act of physically stepping away because it seems to do something for me. There’s a part of my brain with good ideas, but it’s usually quiet. I can’t hear it until halfway through a 15-minute walk around the block, when the noisy part of my brain shuts up.
…Get a Timer That Actually Interrupts Your Work
While you can use any timer, I discovered a problem:
- The timer displays a notification.
- Notification auto-dismisses.
- I am free to ignore it. Or I may have stepped away from my computer while the notification was showing.
- I continue to work without a break.
- This continues throughout the day. I come home exhausted. My evening is spent recovering.
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.
2. Mental Block? Work on Something Different
Stop working on the current problem. Pick a different task. Occupy your mind with something else for a while.
3. Mental Block? Sleep On It
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 take for some blog posts. I sketch out some ideas, then go to bed.)
4. Mental block? Try It in a Different Language
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 rather 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. Trying an implementation in a different language may open your mind to alternate approaches.
5. Mental Block? Grab a Buddy
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 to Ensemble Programming.
In fact, why not code as a team all the time?
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!
Problem-solving: Stop the car. Get out of the car. Walk around the car. Get back in the car.