I have to agree with Ravyne, with only one modification/addition to make. Even when you know all the good/bad practices, making your code work without constantly backtracking to correct things is a notable goal. While I don't necessary like the concept of agile programming in general, I do pick bits and pieces from that and other areas as I go. In this area, I do tend to agree with agile, just write the damned thing and make it work, sure it can be horrible stuff at the end but if it is working the primary goal is out of the way. But, additionally, instead of stopping and refactoring at each problem, you now have understanding of all the problems and can take the overall result as a whole in account if/when you desire to refactor it.
Of course, as RedBaron just stated, working code is a hell of a lot more impressive than half completed "pretty" code. The tutorial code I've been using in my articles ranges from stuff I'm fairly happy with to stuff I really didn't write, it was my evil twin... really it was ...... I hopefully commented the really horrible bits and mentioned why they are not refactored at the moment, but if not, oops. Overall the code functions for what it is being used for, that's really all that matters.
Knowing you have some bad code is important, learning to admit it and live with it till the appropriate time, that's a serious skill. What really matters is dirty or not, it functions and gets the job done first. I usually go with a rule (think this is from agile or something) that I'll ignore things for a bit and the first time I have to fix a bug, modify a piece of dirty/bad code I'll make a note of it, the second time I touch that code, I go back and tag it for refactoring. Every week or whenever my list of todo's gets too big, I spend a day or so not so much 'fixing' those items but at least putting a little time into correcting the worst bits.
It's just an idea. The primary response to bad/dirty code is run and hide or immediately fix it. Get over it, EVERYONE writes dirty/bad code sometimes, just keep moving forward and making notes as you go. Don't get defensive about bad code, sure it is embarrassing but fixing every little detail doesn't lead to complete shippable products. Learning to write better code next time and of course identifying the bad stuff, you learn with practice.