It may seem like it, but no engineer writes "right" code on the first try. They get it working, then they iterate, cleaning it up to make it "right".
Experience teaches us where to start, where to think ahead a little, and how to structure code such that it can be refactored in the future.
Writing code the "right way" means 1) getting something working 2)taking what you've learned and refactoring and/or.
If you care about maintaining a chunk of code for 6 months, or a year, you'll quickly learn to refactor. If you are prototyping, right likely isn't a priority to begin with.