In my opinion the single best way to learn to write better code is to read a lot of it. By reading you'll learn things from those with experience and with good practices. Most importantly, by reading code you'll find that certain practices make code harder to read and as a consequence you will develop a taste for good code while cursing any "bad" code you come across. Ultimately it's all subjective but in the end, I find that reading code in unfamiliar codebases as a powerful self-improvement tool.