Sometimes while building something there comes a thought that "ok.... it's working fine but I could have done that in much simpler way". So, how to build things with improved code quality in a single go?
You have to define what is acceptable and what is not. What increase 'code quality' and what is not.
I have a rule of thumb for that: code.test > code.readability > code.robustness > doc.readability > feature > code.performance
(test increase code quality more than readability. Readability increase code quality more than robustness...)
And read it like that : If I can increase the performance of the code without decrease the feature and the doc and the robustness and the code's readability and the test cover, so I should do it.
Again, if I can increase the robustness but the code's readability or the test will suffer, I should not do it.
This rule should be created and agreed by the whole team.
Hope it can help.
Cheers 🍻
This post has some hints about avoiding bugs: hashnode.com/post/what-are-some-programming-habit…
There are also books on the topic, like Clean Code and Design Patterns. Experience also helps.
But don't expect to ever reach the point where you write everything perfectly on the first try.
PK
Short answer to single go is not possible. Even a popular frameworks such Angular, Zend, Symfony, all are rewritten at some point because to improve the code quality. Software engineering is about constant improvement.
Code quality is not only about code which developers write. It is everything around code as well such as documentation, code format, maintainability, comments and so on.
I mostly concentrate on maintainability so frequent small changes do not consume hell a lot of time to achieve.