Write your code as if you're writing a letter
Next time you have to write any significant amount of code, imagine that you are going to have to write a letter that teaches someone how to reproduce it. The only code you can show them are tests. It really changes how you approach the problem.