What to do when you’re faced with a problem that you can’t solve quickly

junior-programmerproblem solving

I'm a beginner learning Java and after reading the docs I'm trying to solve some of the problems at codingbat.com. Some I managed to solve pretty quickly in a matter of seconds but some not quite. The problems themselves are easy (example http://codingbat.com/prob/p126212) but I sometimes have a hard time finding the solutions. In part because I think of the best possible solution and automatically discard the ones that might work but aren't so elegant and in part because I can't find the right algorithm. This is either due to my inexperience (I have used PHP for web development for about 2 months so I'm not a total beginner – even worked with one framework to build a website) or due to my inability to think of a good algorithm.

I normally don't look at the solutions. I sometimes get stuck even for 1 1/5 hours at simple problems and some of them I eventually solve but some I can't so I eventually look at the solution.

Is it normal/good/bad to concentrate this long if I find a problem I can't solve? I might overreact but should this be so hard for me? Is there such thing as not being able to think of algorithms even with much learning and reading?

Thank you all in advance.

Best Answer

Its actually a pretty easy situation to get into when you're coding for yourself. Its bad to spend a long time focusing on the best way to do something when you don't produce anything in the end.

However I think it's also bad to never stop and reflect. You are pretty much a beginner with only a few months dev. experience if I read your question right. At this point in time you should be focusing on writing something, anything. If you're writing for yourself. If you're not writing for yourself you'll learn to be quicker as if you don't your job will be in trouble.

My advice is

  1. Write code. Bad code / good code it doesn't matter at this stage. You just need to know you can bash something out when required.
  2. Set yourself deadlines. Try to be reasonable with them but not so loose as you may as well not have any deadlines.
  3. Don't try to alter functioning code to be better written unless.
    1. You have a performance issue you need to fix.
    2. You have enough time and you feel that your new way is an awful lot better.
    3. You feel you can learn something new by trying to implement in a different way.
  4. Pay attention to the small details, such as comments. It can really help you fix your mind on the problems and the solutions with your own code when you comment it. Try it, it allows you to step away from the solution and focus on the problem.
  5. Get other people to review your work if possible.
  6. If doing this as a hobby enjoy it. If the worrying about the problems is taking away from your enjoyment, it implies your doing something wrong.
  7. Ask people what they would do with the same problems. This may be the best site for that.

Code that functions but is written badly is a lot more useful than no code.

One last comment that may help you. The interface to your code is a lot more important than the code itself.

Finally In time you will gain speed and confidence. If you can't look back at your work in a years time and say "What was I thinking?" then you really haven't learn't enough.

Related Topic