Yeah the best way to learn is definitely just throwing yourself into a project. By the time it's finished, you'll be a much better coder.
Personally, I like doing this, and just referring to written tutorials or language documentation wherever I get stuck. I also do what Zesh does, writing pseudo code before actually writing the program. It allows me to plan everything out better.
And yeah, I run into that problem of previous bad code tons. It really sucks when you working on a big project, because it gets really tedious to have to keep going back and fixing things. However, you can also look at is as an obvious sign that your improving.
One REALLY important thing is that you don't just keep looking up things about code without actually trying it yourself. Thats why projects are so important. If your not writing the code your "learning" about, your likely to forget it very soon, or be very bad at writing it yourself when the time comes. Its better to search for things on google when you get stuck, and repeat the code so often that you memorize how it works.