views:

191

answers:

7

What do you do when you encounter a programming problem that is really hard for you to solve, and you have no idea yet? Usually, how do you solve it at last? Thanks in advance!

NOTES: Could someone introduce something about problem solving practice?

+19  A: 

If I can, I leave it alone for a while. Often the solution will pop into my head when I least expect it. (If only we always had the luxury of waiting - often we don't.)

Edit: Another hugely useful thing to do is describe the problem to someone else. Even if they can't help, the very act of explaining it to someone who's unfamiliar with the problem will often clarify things in your mind. Sometimes you get straight to a solution that way, without the other person saying a word. 8-)

RichieHindle
+1 works for me every time
RedFilter
yeah, sometime this work fro me
MemoryLeak
+1 for talking about it with someone else.
strager
Stack Overflow can fill that role really well. Many times I have not submitted a question, because I got a new idea while formulating and writing the question. :)
deceze
The old describing the problem trick, that's worked for me lots of times. My theory is that you want to fend off all the obvious causes, and process of doing that takes you down the path of the correct solution.
russau
Wow deceze, you actually realize before you submit the question? I usually realize what the answer is about 10 minutes later... when it's too late, in fact.
Yar
+4  A: 

I just think it over when a pencil and paper.

  • Break it down into each part
  • Look at what parts I know
  • Research parts I don't
  • Put it all together
  • Profit

For me the trick is breaking it into manageable bits.

-- Edit

I must agree with the poster above about talking to someone else, as well. Even if you don't have anyone you can talk to, explain it to a fluffy toy, and the answer will often become obvious.

Noon Silk
+1 for 'Profit' but you forgot '????'
Daniel
My ex-boss kept saying he was going to make a lifesize cardboard cutout of himself for people to explain their problems to. 8-)
RichieHindle
+3  A: 

I find using a whiteboard to explain the problem to someone else very useful.

JRL
+1  A: 

Sometimes I'll search Stack Overflow to see if anyone has encountered the same or a similar problem; if they haven't, I'll sometimes post a question about it.

McWafflestix
haha, this is what i am doing, stackoverflow is really a good site for programmer
MemoryLeak
A: 

The book Peopleware put it in a nice way, that despite being a different context also works here.

The manager's function, they write, is not to make people work but to make it possible for people to work.

In this case you are your own manager, so its up to you to make it possible for yourself to work. If its something difficult you are struggling with, then you need to listen to yourself.. what is it you need in order to get started solving it.

For me, it can be that a major class in the project has the wrong name and is inelegant. In order to solve the problem in an elegant way these needs to be fixed first, otherwise it will end out as a half baked solution.

10 cents

neoneye
A: 

For many problems, writing unit tests can help. Break it down (as silky suggests) and try writing tests for the various pieces. Then write code to make the tests pass. Check out some of the literature on TDD.

Writing throwaway "spike" code is also a handy way to figure out new things.

TrueWill
A: 

Well, it depends on the kind of problem, whether it's something you can research. For the things you can't, often specific design problems where I have problems keeping all the factors in mind at once, I've found two methods to work well:

  • Get rid of all possible distractions (computer, phone, people), e.g find an empty conference room. Take along pen and paper and draw a free-form diagram of the factors involved in the problem; sometimes tables also work well. I've found that the ability to concentrate hard without distractions and the graphical representation usually enable me to find a solution.
  • For really hard problems, sleep over it. Maybe that's just me, but I sometimes come up with the best ideas when I think about something in that half-dazed state right before I fall asleep - and strangely, I can always remember them come morning.
Michael Borgwardt