Overcomming Programmer's Block?
goingware asks: "What do you do if your productivity drops to two lines of code a day, and you just sit and stare at the code and feel like you don't know how to do it anymore? On the outside, it would seem my problem is that I've got some difficult architectural issues that I'm wrangling with. I'm not sure what the right way is to approach a certain feature I'm building into my program in C++. But what my real problem is that I just sit and stare at the computer all day long feeling scared and anxious. I'm afraid to try anything out at all for fear of making a mistake. I know I could just back up the code and write any old thing and throw it away if it's wrong, but for some reason knowing that doesn't help." What do you do when you are stuck in code and your focus leaves you? This isn't something as easy as getting up from the problem for a while (although that helps), this is sounds like something closer to burn-out. What can programmers do to combat this?
"I've encountered this before, but it's not normally like me. I've been programming as a career for something like 13 years now and shipped dozens of products. I've had many obstacles before and overcome them through many and various means... means which all escape now.
Right now I feel like a clueless newbie assigned the task of re-architecting a nuclear powerplant control system.
This has really got me down. I have a product to ship. I called my client and asked to take a few days off from coding, and told her I'd be hitting the C++ books and taking a rest and trying to rejuvenate my programming creativity. She was OK with this. So part of that process is posting my question here."
One thing I've noticed is that simply working longer hours doesn't normally make me more productive. There seems to be a two or three hour surge of activity, after which I have to take a break - read some newsgroups, go for a walk, whatever. In these situations the "leave it and come back to it" approach really works.
If the problem still looks bad when I get back to it, then the next thing I do is ask a colleague for advice. In situations where there isn't another programmer around, I simply describe the problem to any willing listener. Often the simple act of talking about a problem elucidates the solution. 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.
If the task is simply beyond your ability, then it's time to admit it - approach your manager and say so. Grit your teeth and accept that no proprammer can do everything. Just hope that your boss understands that. If you lied about your abilities to get the job, then I've no sympathy for you (having fixed cock-ups by such people). Otherwise, if your boss is able to do his job properly, then he should be able to see this is a resource issue - not a general failing in yourself.
I've actually quit a job because I felt the task I got given was beyond my abilities - finding some comfort in the fact that programmers are a scarce resource. While it is a drastic course of action, I felt almost europhic knowing the stress was over. So if it's not just burn-out consider getting out of the job.
Chris
Doesn't anyone make flowcharts or other software and data diagrams before they launch their text editor? Assuming you're writing new code and not debugging, why are you staring at the screen? Coding anything vaguely complex off the top of your head is Not Good.
Stop thinking in C++. Start with the big picture. Map out the problem. Then drill down to the architecture. Then drill down to the core functions of each module. Then firm up your data/object models. Next, drill down to the detailed design. Most of this should be boxes, arrows and lines, not code.
Then, and only then, start doing serious real coding. If you wing it, you're liable to get stuck or produce something pretty unwieldy.
Finding myself unable to code, I started writing the code in english on paper. I would sit down in a corner of the room and start writing in english. "check the user permissions. if the guy is an admin, show this and that screen. for each line in the screen, make sure it's bla bla." and so on. Once I was done and saw that I had something that could work, I took the text, pasted it into the existing source code and started translating it to code (Java in this case). Maybe it won't work for everyone, but it did wonders for me and I was able to overcome my block several times this way.
The Slashdot crew isn't the mostly likely group to go hit the weights, but for me physical exercise really helps keep my mental side running smoothly.
Endorphines and what not, I guess... Plus it helps get your body tired so you can get longer, more restful periods of sleep. They've done lots of research showing heavy exercise can overcome some mental problems like ADD, and that is the same mindset I end up in when I feel blocked...
Best of luck.
I too have been programming professionally for over a decade (in C++), and here's what I've learned:
Don't be afraid to fail.
Sometimes, the problem definition is too vague, or there are too many unknowns in the mix. You have to follow the scientific method, and the first step of the scientific method is gather data.
You have a module that you cannot figure out how to do? cvs commit, then say to yourself, "Self, we're going to write something to see what is what. When we are done, we will delete what we have written, and using what we've learned, write it properly". You'll be amazed at how much clearer the hidden requirements become when you start bashing code against them.
Now, as to the C++ issue: I don't know if part of the problem is your level of skill in C++, or if that is just a red herring. If you really aren't comfortable using OOD, then for Torvalds' sake DON'T! Just write the code proceedurally. Again, I've often found that once I've written a code block, I can then better see where the objects are within the code. Then, I re-write the code to be OO.
In my experience, no object is reusable from the beginning, no matter how much work you put into it, no matter how long you worked on the design. Only after the third time a class has been used have you come close enough to defining what functions need to be virtual, what members non-private, what args need to be passed to the constructor, etc., to make the class really reusable. Accept it and move on.
Like I said, don't be afraid to fail. It's the only way you will succeed.
www.eFax.com are spammers
But you probably already know that. And I already know the cruelty of simply telling someone not to fear. I'm no programmer, but your problem is universal.
You are finding it difficult to work. This is because, as you perceive it, the risks of continuing outweigh the benefits. You may explicitly tell yourself that this is not so ("I know I could just back up the code and write any old thing and throw it away if it's wrong"), but the horde of automatic thoughts that rise up when you contemplate doing it say different. You know that in a long-term sense, bearing down and getting through the work is the best thing by far. But when an individual's fears of failure become strong enough, it can force hir out of the long-term perspective and into a low-level, immediate world, the same way that you can be stopped from contemplating Rodin's Age of Bronze by a splinter. This is the point where you might just be told to shut up and work through it, but another way is to figure out what your fears are, whether they're reasonable, and whether they can be disproved or transformed.
If you were trapped in a situation where the alternatives were painful, awful failure and procrastination, your solution would be to procrastinate. You must acknowledge that this is reasonable. The first step is not to blame or criticize yourself, which only increases your paralysis, but to compassionately accept that you're in a bad situation and start working to get a handle on it. It sounds like you're already on that road.
Now, we have to find out why you're fearful and emotional about this project and whether it makes sense to be that way. The simplest of all tools in my field of study is the double-column technique. Just think about the automatic thoughts that go through your mind when you contemplate working, and get them written down on the left-hand side of a sheet of paper.
I don't know what your thoughts are, but for many people they may look like this:These are frightening. Are they true? In fact, they contain cognitive distortions that all people make to some extent. The second and third show the especially insidious error of dichotomous thinking, the tendency to see things in an all-or-nothing sense. A single failure could be due to a specific hole in your education, emotional factors outside your work, a lingering virus, or all sorts of things. But even if you completely and utterly screwed up, would that erase thirteen years of success? Surely that makes no sense!
On the right-hand side of the sheet, write the best refutations you can think of to these statements. They should be compassionate, insightful, and constructive -- everything you'd tell a friend in your situation. In this example, they might be:Keep your refutations with you at all times, and write them down as you think of new ones, or notice new automatic thoughts. What you have to do is take the most powerful and frightening thoughts you can uncover and argue them down. I mean seriously argue, bringing up the best refutations you can and trying to believe them wholeheartedly. Even if you don't buy them now, think how much more productive they can make you. This isn't really dishonest; if this rational optimism leads to repeated failure, you can always re-evaluate it and change to thinking you're a washout.
Fear and self-criticism are terrible motivators. Relaxed understanding allows you to work with an absorbed sense of flow. To put it tersely:
chill.
- Michael Cohn
Important note: I am a student, not a licensed or degree-holding psychologist. I am giving you a digest of other researchers and writers. This may be valid self-help advice but should not be relied upon for severe or life-threatening problems
Recommended reading on the subject of Cognitive-Behavioral Therapy:
Beck, Judith: Cognitive Therapy, Basics and Beyond -- a textbook. Dry but comprehensible.
Burns, David: Feeling Good -- a self-help classic. Burns is a moron about a lot of things, but it's overflowing with useful techniques and arguments.
Ellis, Albert: A New Guide to Rational Living -- If you're sick of therapists who act like Deanna Troi, you'll be pleased when Ellis comes and kicks you in the ass.
-----
Go ahead, blame me... I voted for Nader!
Caffeine is EVIL
No, really.
It might seem like the problem is a particularly tricky algorithm to implement, or a bug that you can't track down, but this is never, ever, really the case.
The problem is Stress, and if you (I'm more addressing this to the clueless replies than the original poster) don't admit that and deal with it, it will just get worse.
A charge of Caffeine won't prep you to handle tougher problems, it will just make things feel even more hopeless and impossible. If there is any wonder-drink that will sort you out, it's a Smoothie, made from fresh fruit, that contains lots of de-stressing anti-oxidants and natural sugars.
Another wierd viewpoint I've seen in this discussion is that when you get burn-out, you should take a couple of days off and then dive right back in. DUH! Why not adopt a lifestyle you can maintain indefinitely??
Through my degree I tried all sorts of things that I thought would directly increase my productivity - Coke, ProPlus, Guarana - and they all just served to make me more stressed, depressed and non-productive.
What really increases productivity is having a rest and doing something different. I always try to:
Do something small at least every hour
- Go to the toilet
- Go fetch a smoothie
- Go and have a chat to someone
- Pray (I ain't religious, but I see that this would help) or meditate
Do something longer two or three times a day- Lunch OUT of the office
- A walk in the sunshine
- Watch a movie
- Have sex (on your own is just fine)
- Play an instrument
- Have Exercise (trust me, there IS a worthwhile sport for you, even if it's just a walk in the park)
Take the weekend off- Veg
- Tidy the house
- Dig the garden
- Go visiting people
Duh, people tell geeks to get a life. Sometimes we don't even look after the one we've got.I find it helps to stop and pray, even if just for a minute. I lean back in my chair, put my feet up on my desk and ask God for inspiration. It's helped me out of blocks many times. Of course, I liked the comment about becoming a sys admin too. :) I actually do both so when I get tired of one I do the other. It's 4:30 AM here in CA and I've been coding an inventory proggy since 10 AM. At 1 PM I get a break to install a frame relay!
T. Bradley Dean
tbdean