Most of the times when you are writing code you are make mistakes either in the structure or in the specific code. These mistakes become bugs that sometimes eat up a lot of time to diagnose. Once diagnosed, bugs are usually easy to fix unless there is a big structural mistake, which makes you, rewrite the whole code. So roughly you could divide the problem into two categories: bugs that happens because you are not understanding the problem completely or you don't have good understanding of the language you are programming in, and bugs that happens because you are tired or not concentrated enough etc. Structural problems can be fixed by planning better and understanding the programming language better i.e. the hard work involved with becoming a great programmer.
Here I am more interested in are the sloppy mistakes since the payoff is bigger in fixing them but they take equally long time to diagnose as the structural imho. Usually the IDE will help you diagnose and fix a lot of those errors. But there are some that are harder to find - the sloppy mistakes that affects the structure. In a recent assignment I had we were to implement a prediction algorithm and calculate the mean error. The algorithm was complicated both mathematically and programming wise. Calculating the error on the other hand was simple - just compare the predicted with the true values. Where did I make the mistake? In the error calculation of course. I was calculating the mean of the correct answers not the wrong ones. I was getting terrible results I rewrote the algorithm three times and spent time debugging but nothing worked until I started looking at the error function.
Now why did I do that mistake? And why didn't I go there and check it the first thing I did? I would like to call the problem the bias of complexity. Since the problem was complex I believed that the bug must lie in the code of the algorithm or in the way I had structured it not in the simple code calculating the error. Therefore I did not debug my error function.
So since the algorithm was complex I was biased to believe that the error must lie there but it was really all just a sloppy mistake. So the assumption that complex code is more error prone is not as correct as one believes. When the code is complex you concentrate more and check your code more, and when the code is simple you relax and just write.
But how do we fix this? First of all write test functions even for simple code. Second, always check the simple code first and verify that it is correct indices, error functions etc. Third, reevaluate your assumptions.