An untidy room is like bad code: you spend hours in finding things and when you try to add something you are just adding mess.
A tidy room is like good code: you immediately find things, and you can easily change the way they are organized.
The speed of development is related to costs. The speed of development can increase over time as you indulge in bad practices. It can improve with refactoring.
The speed of development is not just the time you spend to develop a certain functionality, but the time others will spend in adding functionalities to your code.
A maintainable code can easily be changed, reduce the costs, has a limited number of bugs, and... make the developers more happy!
The big question How to write maintainable code?
Remember: smart is the one who can see far away, but in the only direction allowed by the blinders. Wise is the one who can turn his head 360 degrees. • Don't be intelligent when you code. Be wise!
First principle: design before coding. • The more time you spend on design, the less time you will spend on debugging.
Second principle: understand the functionality before coding or bug fixing. • If you understand the functionality, the code will be an open book.
Third principle: be simple! • Find the simplest solution for the complexity you have to deal with. Complex solutions or not normalized schemas will add complexity exponentially along the development process. When you have to change something unnecessarily complex, you will resort to a quadratic complex trick.
Fourth principle: separation of concerns to avoid spaghetti code. • Separation of concerns is mainly achieved by encapsulating. • When a change affect only one part of your code, it's easy to add functionalities. • Spaghetti code means that when you touch something, the entire castle of cards collapse on itself.
When you puncture a tire, you can easily substitute it. With spaghetti-code, you would have to buy a new car.
Indicator of a good code (not spaghetti-code style!) • The time spent in reading and understanding the code or the time spent in bug fixing should be low, compared to the time spent in coding.
Fifth principle: code reuse. • "One of the attributes that most strongly distinguishes expert programmers from less experienced ones is that experts strive for and usually achieve a high degree of code reuse" (by Joshua Bloch, Effective Java) • That include writing atomic functions, which promotes code reuse.
Good code is always maintainable, bad code is always unmaintainable.
Final truth • The universe is actually terribly simple, unfortunately explaining things in a complex way is just as easy.