The reality is that we (can) learn from our mistakes, so the more 'mistakes' you make the more you (can) learn. Most people find it difficult to do this and keep on making the same mistake again and again.
So you just have to spend a lot of time writing code, no matter how much reading and training you do as well.