Get used to writing your code twice. If you were writing prose, almost any methodology recommends that you revise and edit your first draft, often multiple times. My first pass at an implementation is for me to understand it and solve it. If it’s a throwaway tool, that may be where it stops. If it’s committing to a common repo, I’m probably going to significantly rewrite and enhance the code at least once. If it’s the basis for a new technique/sample code, it’s going to be multiple times with feedback.
Seek feedback on your code. Fresh eyes provide fresh perspective. You’ll learn a lot about yourself from others commenting on your code.