Writing Code
I was recently reminded of the concept that code is more often read than written while reading "Tidy First?" by Kent Beck (If you haven't read "Tidy First?", I highly recommend it).
From my own experiences in reading other's code--including my own years later--it's not often on the forefront of a developer's mind.
If given time to pause and think, writing high quality & readable code is something that can be easily achieved. But in reality, there is no luxury of time. There's deadlines to be met, QA is looking for a fix, the backlog keeps growing and growing, etc. There's a huge amount of reasons why code is just "written in the moment".
A couple of thoughts recently came to me about mentoring others on how to keep good code on the forefront of our minds.
My first thought is to practice, practice, practice. Programming is a skill, just like any other. Just like great musicians, we should be putting in practice. Growing our skills, perfecting our art, composing new things.
A great practice exercise for writing good code is to write a library for someone else to use. And while writing that library, write the something that uses your library. This is a great way to develop the skills needed for writing good code. It doesn't matter if you publish the library for the world to see.
Writing a library forces you to think about how everything fits together, how someone else will use it, what will they think of the ergonomics. Do it again and again until it becomes second nature.
And my second thought is to simply think that you're always writing a library for someone else. You're not just writing code to solve the problem. You're writing a library of code that can solve the problem. A library that someone else will come along and use for their own solutions.
Thinking outside of the immediate and thinking of others takes time and practice. But doing so makes code that is easy to read, easy to support, and can be extended in the future.
So the next time you're writing code, write like you're writing a library.
And go practice already!