Thoughts On Writing Good Code
Slow down when writing code.
At ng-conf, John Papa gave a talk on writing readable code. You can watch the video here. I recommend it.
Writing clean, readable code seems like an obvious and simple thing to do, but this talk made me realize that I have been ignoring it. For whatever reasons (I’m guessing the thrill of increasing my throughput 🤓), I’ve been focusing more on closing tickets than writing good code. Recently, I have really been trying to focus on writing quality, readable code. I’ve come up with two general steps to help me when I’m working on an issue:
- Just fix the issue or get the feature working.
- Go back and clean it up.
I’ve been stopping after step 1. This has produced some code that I definitely don’t want to go back to. Ever. Now, I’ve been trying to slow down and worry less about getting lots of bugs fixed. Instead I’m trying to figure out what it takes for me to not only complete a ticket, but complete it in a way that I’m proud of the code I’m producing. Luckily I work at a company that doesn’t pressure me to get more and more tickets done all the time, so I’m able to actually slow down.
Recently, a couple of my coworkers and I have been pushing for more code reviews on our team. I’ve found this a very effective way to help me write better code. When I know for sure that someone else is going to look at my code, I put more effort into making it readable as I’m working on it. So, code reviews. Do them. Even if it’s just with yourself.
For me, focusing on readable code is like switching keyboards: my “productivity” has dropped, but I’m sure it’ll pick back up as I get used to it.
I have found that it is okay to slow down, and that I need to. I have felt that focusing on writing readable code has been helping me become a better developer. Next step, make git commits more often.
Hit me up on Twitter if you have and comments or good tips on writing readable code.