First rule in coding is to make it work. Once you’ve done that, clean up your code
and make it neat, understandable and simpler if you can.
Cleaning up code is a good habit, but so is aiming for clean code in the first place.
You’ll still need to clean things up even if you plan ahead, but you won’t have quite
as much of a mess to start with.
The best coders and average coders usually have similar code, the difference is
how long it takes them to do it. If you take the time to plan ahead and solve the
problem before you start coding it will help you become one of the best coders.
Obviously you won’t be able to foresee every problem so you will have to make
the little things work and that can get pretty messy so what you are doing is called
refactoring the code (and this is a good practice). The best thing to do is first solve
the algorithm on paper and figure out how you are going to accomplish the task.
Then code it and get it to work, then refactor to clean up, make more readable
and optimize. Look at how long it is taking you to solve/code/debug and of those
three the debugging should take the least time, then coding a little more and solving
the problem the most time. Hope that helps out.