The Best Way to Get Better at Writing Code Isn't Just Writing More Code
31 Dec 2024 #miscMore than 10 years ago, I started my real coding journey with a Google search: “How to be a better developer.”
University had taught me a lot of things I didn’t need. I had to teach myself the ones I needed.
I went down the rabbit hole. That search gave me lots of ideas and inspiration:
- Write specs
- Write unit tests
- Document your code
- Learn Functional Programming
- Write self-documenting code
- Read Clean Code
- Start a blog
Yeah! Starting a blog. That inspired me to start this very blog. I didn’t know I was about to enjoy writing so much.
Those are good ideas. But what has worked best for me is reading other people’s code.
In fact, an ex-coworker taught me that lesson. That was his secret technique, even though he was our team’s architect, and we thought he didn’t need to study anymore.
So read more code. But read actively. You can’t read code like fiction, glancing over words on a page:
- Find a medium-sized library you use or find interesting
- Download its source code
- Compile and run it
- Look at its unit tests
- Debug one feature
See how the library authors implemented a feature.
If you find a new keyword, look it up. If you find a new data structure, look it up too. If you find a new method in the standard library, again, look it up.
Once you understand how a feature is implemented, try to recreate a bare-bones version without looking at the original code. That’s how you make sure you truly understand the code.
I used this strategy when I learned about the Specification pattern. I found a library implementing that pattern. I downloaded and read it. Once I got the main idea, I wrote my own dummy implementation. Then I wrote a post about it.
Don’t just write more code to get better at coding. Read more code. Actively.