I recently came across the concept of “Rubber Duck Debugging”, with which I was previously unfamiliar. I first saw the idea on an old Linux mailing list, although there’s a Wikipedia article on the subject as well (of course). You should read the first link (it’s short), but the basic premise is that you can debug code by walking through it, trying to explain the code to an inanimate object (or an animate one, if you want). The theory is that when you get to the point where your explanation doesn’t make sense, you’ve found the source of the problem. I’m personally a big advocate of the “walk away from your computer” debugging approach: when you’re having a really hard time debugging a program, step away from your computer and don’t think about it for a while. In my experience, you’ll either solve the problem fairly quickly after you stop thinking about it, or fix it shortly after returning to your computer with fresh eyes. In any case, you need as many debugging tools as possible in your programmer’s toolbox.
In the past decade I’ve also discovered an effective, yet impractical, way to improve one’s programming skills: write a book! We’ve all had times where an application or some bit of code did exactly what you wanted it to, even though you didn’t understand exactly why. And, really, that’s fine. Sometimes functioning is all that’s required, even if that’s not an ideal goal. The next level of knowledge is knowing why something works. And a higher level is knowing something so well that you can explain why it works to someone else (duck or not). More importantly, you understand why the code should do A instead of B, or you are able to clearly see that X isn’t necessary. I’ve found that writing a book on a subject hones those skills. In short, I know personally that I’m a better programming because of the writing, and teaching, I’ve done. Clearly, it’s not practical for everyone to write a book on everything they do, but I would recommend you occasionally take a crack at trying to explain some code—even code that’s working perfectly fine—to anyone or anything as a way of solidifying your own knowledge.