Rewrite.
Write some code, make sure it works, and then look at places where it's ugly and figure out how to rewrite it so that it's better.
You won't write good code the first time, unless you're writing something that's trivial for you (too easy).
While the examples are too Java specific, the book Refactoring by Martin Fowler is a terrific introduction to the skill of improving code.
Rewrite.
Write some code, make sure it works, and then look at places where it's ugly and figure out how to rewrite it so that it's better.
You won't write good code the first time, unless you're writing something that's trivial for you (too easy).
While the examples are too Java specific, the book Refactoring by Martin Fowler is a terrific introduction to the skill of improving code.