I have a confession, which you may have guessed from the title. I write messy code.
Wait, it gets worse: I like writing messy code.
It feels freeing, like a stream-of-consciousness first draft. What I don't do is put messy code up for review. I have a process to get from a rough first draft to a clean PR.
I used to hide my dark secret, but I don't think I'm alone. Even if I am, this process works for me. Maybe it will work for others, too.
I rarely see the simplest solution at first. But I spend time on software design before I start, focusing on boundaries between systems, modules, components, etc., and keeping separation of concerns top-of-mind.
With that in place, the interfaces are clear so I have more freedom to make the individual pieces messy. Then as I work, I cover the functionality with automated tests. I clean things up as patterns emerge, using the test suite to confirm everything is still working. During cleanup, I'm thinking about readability and simplicity, and if necessary, performance optimization.
The two most important parts of this process are the software design and the tests. The design helps solidify separation of concerns, and the tests let me refactor and clean up without the fear of breaking things along the way.
This way, I can have my dark secret and nobody needs to know (Shh don't tell).