If I'm working on a homework assignment, yes I go over it a few times and clean it up.
If I'm working on our startup, I often google / copy+paste, whatever gets the job done. If I find myself struggling to make it work how I want or I'm spending more time fighting with the code than I'd prefer, I go back and refactor the code.