While at UberConf I had the great opportunity to attend a talk by Venkat Subramaniam titled “How to Approach Refactoring”. Many times I have attended talks and read articles focusing on refactoring techniques, but rarely do these other sources discuss the behaviours that allow refactoring to work. Knowing all of the refactoring techniques without understanding the fundamentals that make refactoring beneficial, can result in making code worse!
There are many great refactoring books out there such as
- Refactoring to Patterns – Joshua Kerievsky
- Refactoring: Improving the Design of Existing Code – Martin Fowler
- Working with Legacy Code – Michael Feathers
However, during Venkat’s talk he recommended a book that is not about programming, but instead about non-fiction writing in general: On Writing Well by William Zinsser. Whether you are writing a newspaper article, a book, or writing code, many of the same principles for better writing still apply.
- Simplicity – Writing is a about communication. Often as developers we make code unnecessarily complex. We do this because for some developers it feels good and impresses others. A developer should never be proud of complexity in code, but instead focus on simplicity.
- Clarity – Make it clear. Don’t use cryptic naming, instead make it clear and easy to understand.
- Brevity – Make it short, but be careful not to take it too far. Reading a very long piece of text can make it take time to understand a piece of code, but it is also easy to make it too short. Use only as many words as it takes to make the code understandable and no more.
- Humanity – Write it for people. Remember that code is going to be read by other developers, so consider how others will interpret what you have written and keep that in mind when writing code to make it simple, clear, and concise.