10 tried and true methods for breaking coder’s block

When veteran software developers have trouble writing code, they often turn to one (or more) of these sure-fire solutions to get it flowing again

A blank page in a notebook
Pink Sherbet Photography (CC BY 2.0)

We’ve all heard of writer’s block, but if you’re a programmer and been doing it long enough, chances are you’ve experienced a cousin of writer’s block, coder’s block.

Like writers, programmers can have hours or days (or longer) where they have trouble writing good code, or any code, for that matter. How do professional software developers break through coder’s block to ensure they can get the job done?

This is a topic that developers often discuss, sharing methods and tips for getting their brains back on track. Based on input they’ve shared in various online forums, blogs, and websites, here are 10 methods that veteran programmers swear by to help break through the logjam and get the code flowing again.

Get away from the computer

The first step in trying to break coder’s block, is to simply to get away from the computer for a while. “The computer is just a tool, after all, and sometimes one needs to put aside the tools to get a better look at the problem,” wrote user tuffy on Slashdot.

Getting your eyes away from the monitor and your brain engaged in something non-computer related can help it get out of whatever rut it’s stuck in. “If I'm buried in VBScript, taking a break and reading Vogue or Elle either refreshes me enough that I can jump back in, or it sparks something in the grey matter so that it comes up with a solution to whatever problem I was grinding away at.” Ars Technica user MonaLisaOverdrive recommended

Get some sleep

Sometimes to break coding block you need to do more than just get away from the computer screen; you need to let your brain (and body) relax completely. A quick nap will often do, as Dave Everitt found and noted on Joey Beninghove's blog. “If I've been in an unsuccessful ‘okay I need to push…’ mode for too long, I go to sleep for 20-60 minutes, thinking about the problem as I drift off,” he wrote. “When I get back, there's often a ‘why didn't I see that before’ moment.”

However, sometimes a longer spell of snoozing is required. “What usually works for me is getting lots of sleep,” recommended BoLean on Slashdot. Likewise, Slashdot user Electric Barbarella said, “Sleep for as many hours straight as you can.”

If the block gets really bad, you may need to take your rest up (or down) a notch. “On really bad blocks I take a mental health day or two, sleep in really late, (gotta rest that overworked mind)....” shared Slashdot user lostproc.

Get some exercise

If rest doesn’t get the code flowing again, you might need the opposite -- exercise. “Take care of the body and you're taking care of the mind,” wrote user Mr T on Slashdot.  

Particularly if the block is being caused by stress, exercise can help relieve that and get you back into a productive coding state of mind. “They've done lots of research showing heavy exercise can overcome some mental problems like ADD,” mkafka shared on Slashdot, “and that is the same mindset I end up in when I feel blocked... “

Of course, the form of exercise can vary greatly, depending on how much time, money and nerve you have. “My friends and I used to go to the park and swing to think,” user Momo wrote on NeoGAF. Slashdot user _14k4, on the other hand, had more extreme suggestions. “Skydiving and flying are great sports. They're relatively not that expensive ... and they get our bodies moving, and our brains thinking in a different way than we're used to,”

Just write some, or any, code

Just like for blocked writers, many programmers recommend just writing something to help break through the block. “One way out of writer’s block, which works for my programmer's block, is to write something, anything. Junk throw-away code,” wrote Brian Leahy on Stack Overflow. “Just explore something. Don't worry about solving some problem, just do.”

“The trick is just writing/coding,” Slashdot user Kostya advised. “The more you write and the more you code, the more good stuff you get out of your head and into source files. You might throw it all away and keep just one concept. But you will find the pressure has eased and suddenly the direction you need to take is clear.”

Slashdot’s mav[LAG] had an interesting suggestion. “What works for me ... is to take Sedgewick (or any classic text) and write one of the algorithms in there. Doesn't matter what it is.... The result is you realise you *can* program after all and you'll have probably learned something in the process...”

The idea is that even just going through the coding motions can help get your juices flowing again. As Steve Havelka put it on his blog, “As a professor of mine once said, ‘If you can’t write, write s@#t.  We have delete keys for a reason.’”

Talk it through out loud

If you’re blocked because you’re having trouble trying to code or solve a particular problem, developers often find it helpful to talk through the problem out loud. Sometimes discussing the problem with another programmer will do the trick. “Talk to another developer, ideally in front of a whiteboard,” Gregory Seidman wrote on Ruby-Forum.com. “Nothing makes things flow better than trying to explain them to someone else.”

Others, though, many find it more useful to describe the issue to a non-programmer, as another Ruby-Forum.com commenter, AndyV, did. “Often times trying to describe things to a non-developer can be much more illuminating,” he wrote.

Your sounding board could even be a pet or an inanimate object -- or nothing at all. Just verbalizing the issue in some way could help break the logjam. “Now this is going to sound silly, but I've even talked to my cat when working at home and sometimes had that ‘eureka’ moment,” Slashdot user LizardKing wrote. “I talk to my dog much more often than I probably should,“ said fellow Slashdot commenter chowda.

Write unit tests

When programmers feel unable to write code, a common recommendation for breaking through the block is to break the task in front of him or her into a number of smaller tasks. A great way to do that is start by writing unit tests. Breaking things down into unit tests also helps to provide focus and structure which might be just what the developer needs to get the code flowing again. “I usually start with unit tests,” shared Nic Wise on Stack Overflow, “and use that as a test runner/harness, which has a nice side effect of being tests, and small blocks of work.“

The avoidance or elimination of coder’s block is considered to be one of the benefits of development methodologies that advocate writing tests first. “It virtually eliminates coder’s block.” wrote Tim King on his blog.“For me, getting over coder’s block has been one of the most important unexpected benefits of unit testing and test driven development,“ shared Stack Overflow user reefnet_alex.

Drink more -- or less -- caffeine

Programmers (and techies in general) have, of course, a reputation for drinking lots of caffeine. It’s natural, then, that when faced with a coding block, some coders advocate increasing the caffeine intake. “The only way to cure programmers block is a direct infusion of Skittles and Mountain Dew intravenously, keeping the brain in an alert and creative state,” TheReverand advised on Slashdot.

Coffee, of course, is usually the top choice for a dose of caffeine when your brain seems stuck in neutral. “‘Coffee gives me the serenity to think and the vitality to act’ -- attributed by my own admittedly faulty memory to Kurt Vonnegut in a coffee commercial.” wrote Slashdot’s snoopdave.

Surprisingly, there’s a bit of a divide in the programmer community over whether coffee and caffeinated drinks, in general, help or harm developer productivity. While some developers strongly advocate increasing the caffeine intake when blocked, others just as strongly argue for decreasing or eliminating its consumption completely. “... look at eliminating caffeine,” advised RunFatBoy.net on Joel Spolsky’s blog. “I'm less jittery, and the adrenaline doesn't seem to fire off every time something goes wrong.”

gwicks on Slashdot also recommended that getting off of caffeine was the way to get unblocked. “In my experience, coming off the caffeine for a few days restores my creative thinking when I'm stumped,” he wrote.

“... caffeine is the fruit of the devil,” agreed fellow Slashdotter MrResistor. “Sometimes I find it necessary. . . but it won't help you solve a problem.”

Meditate

Sometimes a block is particularly stubborn and you may have to work a little harder at clearing your head. Some developers say that meditation is a great way to achieve some clarity, reset your brain, and hopefully clear the coding blockage. “Learn meditation,” advised user torcail on Slashdot.”I don't mean meditate on the problem, I mean totally clear your mind. Works best for me at night. If I can get the conscious mind to ‘shut up for a while’, it often jump starts my creative process. I've often dreamt the answer to problems after doing this.“

Slashdot user master2b put it in terms developers might better understand. “I like to make an analogy to meditation as being like defragging the hard drive, flushing memory cache, and throwing out temporary files.”

Listen to or play some music

Music not only has charms to soothe a savage beast, but, some say, can also help to soothe a blocked coder’s brain. “I have a set of ‘programming CDs’ that I find help me a lot when I'm lacking focus,” said catseye_95051 on Slashdot. “They give me a kind of ‘artificial energy’ that keeps me going.”

The genre or type of music that can you get you going, of course, will differ from developer to developer. Slashdotter phee recommended, ““Turn on some really loud, energetic music (I find trance/techno works wonders),” while TheOutlawTorn said “I can honestly say I have never had a mental block that a Miles Davis album could not cure. Either that, or some Slayer!”

Other developers take it one step further, and advocate for actually picking up an instrument and playing to break through the coding blockage. “Whenever I get ‘coder's block’ I play guitar and it refreshes me. Fantastic way to get back in the groove,” John Papa wrote on Twitter.

The act of playing an instrument engages both the brain and the body, but in different ways from programming, which can help break the block. “Forcing yourself to focus your brain on something completely different and as intense as playing music, you might just find that when you sit back down to code, you have a renewed outlook on the problem at hand with a fresh set of ideas,“ wrote Joey Beninghove on his blog.

Find a new job

Finally, if all of these methods fail to resolve your coder’s block, it might be time to consider a more drastic solution: Finding a new job. “Though often easier said than done, finding another job is sometimes the only way to remedy coder’s block,” blogged Bill Patrianakos. “Only you know if it’s your job itself that’s causing your issue or if it’s simply a case of bad habits and long hours. I think this is a last-resort option.”

Your blockage, ultimately, may really be a reflection of bigger issues with your employment situation, which will only, ultimately, be resolved by moving on. “... if it's not just burn-out consider getting out of the job,” advised LizardKing on Slashdot.

This story, "10 tried and true methods for breaking coder’s block" was originally published by ITworld.

Copyright © 2015 IDG Communications, Inc.

7 inconvenient truths about the hybrid work trend
Shop Tech Products at Amazon