Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

This question already has an answer here:

There's a workflow I'm working on. It's so far been web forms filling databases with occasional writing configuration scripts for analysis instruments instruments, and I've written it all, in Perl, Javascript, HTML, Javascript, MySQL.

And right now, the task in front of me is generating a post-instrument analysis Bash script. Or, rather, a Perl-written post-instrument analysis script generator. And it is taking forever.

I have had this as the front-burner task for a while now, and progress has been horribly, embarrassingly slow. In fact, last Friday, I sat, looking at the screen, trying to find my way into the next step of the project, and the first sign of ... inspiration? Of capability? Of knowing and attacking any aspect of the task and being able to code it? Well, it started at 4:30pm, and I rode it until 8:20.

I am looking for and hoping for ideas and techniques to get into that mental space consistently and on my schedule. Any pointers?

share|improve this question

marked as duplicate by gnat, GlenH7, MichaelT, Martijn Pieters, maple_shaft Jun 20 '13 at 1:59

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
So looking back on this... boredom? –  Erik Reppen Jun 14 '13 at 3:55
    
Avoid distractions (e.g. useless meetings and other interruptions) and you have solved 50% of your problems. –  Giorgio Jun 19 '13 at 23:10

11 Answers 11

First, if you're looking for pointers, you're using the wrong language, try C... waits for pun...

But in reality, sometimes the best way to get into a certain frame of mind or to get past an impasse in programming is to either work on something different for a while, or to try and attack the same problem from a different angle.

share|improve this answer
3  
0x74A3842B, 0x8012CF83, ... –  jsternberg Mar 28 '11 at 3:25

Here is a roundup of the best posts on the psychology of 'flow' from Programmers.SE. How to achieve it, how to break it, books to read and videos to watch.

Warning: don't click these links if you're trying to achieve a flow state.

share|improve this answer

If you are procrastinating

If you remove all the more interesting things from your life, the most interesting thing that remains will be your work.

If you are genuinely stuck

I find getting out an old-fashioned pad of paper and asking "What am I trying to do here?" And after I have answered that, "How do I get from A to B?". If I can put it into steps, I'll then do the first step. If not, maybe ask someone else? (But google first.)

share|improve this answer

" Of knowing and attacking any aspect of the task and being able to code it? Well, it started at 4:30pm..."

You need to define what you are building before it can be built. This is what stopped you in your own words.

share|improve this answer
    
That's a big part of it, sure. –  VarLogRant Mar 28 '11 at 17:48

If you're sure that the problem is nor burnout, and that some planned and honest rest won't fix it, then placing my mind on something else for a while works for me:

  • Meditation.
  • Playing music.
  • A sport.
  • The I Ching. The whole process.
  • To study something technical but (apparently) completely unrelated to the task at hand. It promotes lateral thinking.
share|improve this answer

Here are some of things I do when I get stuck:

  • Specify (opposite of generalize). Solve a more specific version of the problem.
  • Break down the problem into component parts and solve one part.
  • Re-characterize the problem. What am I actually trying to do.
  • Take a break.
  • Get someone else involved who is fresher.
share|improve this answer

Get a pad of a paper and a comfortable pen and physically write it out. Write down exactly what you are trying to do. Sketch, doodle, scribble, just draw/write. Mspaint wont work. Any program on your computer that is supposed to help, won't work. The act of typing the words of whatever language you're using into whatever editor you're using doesn't make a program. It's made in your brain.

Want to write some code? Get away from your computer!

I built a mysql database for a friends photography website recently. I was having a very hard time wrapping my head around exactly how it needed to work, and how to lay out the table structure. I tried mspaint first, then various database design apps. They all help a little, but I was still stuck. As soon as I got a real pen and real paper and really wrote it down, it just clicked.

This may sound "new-agey", but I honestly think it has something to do with having to actually use your brain to physically move your arm to move the pen to draw what you're thinking of.

share|improve this answer
2  
I know that when I have to really think through a problem, it helps to print out source code and sit away from the computer to work it out, because doing it at the computer encourages hacking. But good advice on this one. –  VarLogRant Mar 30 '11 at 14:34

Several people have said get away from the computer, and a walk around the block can do wonders. But for really hard problems I think about it as I'm going to sleep. Preferably a nap in the afternoon where you're not going to be out for 8 hours, but at night with a pen and pad of paper by your head can work.

share|improve this answer

Flow is the ultimate answer. To do that, you need clear objectives. That encapsulates some of the items others have mentioned. Sometimes, the route to those objectives isn't so clear, so you need some kind of "mental refresh."

Many people who code for a living also juggle. I'm not talking about juggling a long task list, I'm talking about juggling objects. The thing about juggling is that it doesn't require significant cognitive abilities but it DOES require focus and full attention. If you can pull your mind completely off the task which is bothering you and COMPLETELY FOCUS on something else, you frequently get a "Eureka!" moment and then you can get back to coding.

I don't have the coordination to juggle. I get on a treadmill, in front of a window, put some white noise in my earbuds, put my e-reader in front of me and walk for about 30 minutes. The physical exertion (not intense, but steady) gets the "juices flowing." Others have suggested a walk around the building. The weather, around here, gets downright nasty; the treadmill is usable, regardless of what the weather is like. The e-reader, with an engaging book, is usually enough to mentally distract me. Natural light, especially during the day, helps clear the mind (fluorescent lights tend to do the opposite).

After that, I'm usually mentally refreshed enough that I can tackle whatever problem was bothering me. And I stand a better chance of finding clear objectives and a path to them, inproving the odds of hitting a "flow" state.

share|improve this answer

I like to perform a TDD Kata (Some Katas) that help me solve a simple problem and perform some deliberate practice. I use this as a warm up or as a distraction if I am solving a particularly frustrating problem.

share|improve this answer

I've found that if I'm having trouble figuring out how to proceed on something then I haven't grasped the problem domain completely yet.

I think one thing which holds me back is feeling pressure to produce something. What I like to do is freely explore the problem domain without attempting to design or implement. Once I've been exploring a while, I can see the components and what needs to be done. Then I can design the objects and flow, figuring out what I want to do and how, and then I can implement it. But if I try to push either of the latter into the exploration phase, I get brain freeze.

I often find that my mind feels the freedom to explore when I'm away from the computer and can write things down -- as others have mentioned. If I'm at the computer then I feel like I should be coding, which is not what I need to do starting off.

Sometimes a little coding or prototyping will be helpful/necessary, but I only get to that point after exploring a bit.

It could be that maybe you're just not a morning person? I had a co-worker who complained of the same thing -- not being productive until towards the end of the day. Maybe that's just how some people work?

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.