We all like usable software, but what about usable code? How do we test the usability of the code we write?
One way is to get another programmer to work with it. If a bug is discovered in some code you’ve recently written, instead of just quickly fixing it yourself, see how easy it is for someone else to fix. Write a failing test that isolates the bug, find a pair – ideally someone who has been working on something completely different – and let them loose on your code.
Try to resist telling them where to look – watch how easy they find it to navigate the code, find their way around it. Listen to their comments, and encourage them to start making little changes – rename things that don’t make sense to them, for example. Hopefully you were pairing when you wrote the code in the first place so the design will already reflect two people’s perspectives on the problem, but you often need at least three people’s input on a design before it really starts to become usable.