As software developers we can’t stop bad code but we can make it better. There are a number of ways we try to make better code. We try to follow best practices like TDD. We’ve all read a number of books on design patterns, code standards, rules, and guidelines. It is a fact though, that the real world gets in the way. Deadlines are tight. Projects get rushed. Code is written quickly and sloppily. None of these things are going away but there is one simple thing we can do no matter how tight the deadline.
When you write a piece of code, take a brief pause and look at what you just wrote. Ask yourself:
Can I make this code better?
Chances are you’ll see at least one thing that could be changed. A large method that could be broken up. A convoluted logic expression. Or any number of small things. If you take just a moment to change that one thing before moving on, all of your code will be cleaner, easier to maintain, and in general much higher quality.