Being Clever
I’ve been doing a lot of thinking about coding styles lately. One of the interesting things about the space that my firm plays in is that it attracts people that are technologically inclined but have not typically had prior coding experience. A lot of the folks come from accounting and finance backgrounds. As such, they don’t have the background in things like version control, CI/CD, code reuse and refactoring, or any sort of true development best practices.
What this causes a lot of times is a lack of understanding of how to avoid pain in the future. For example, you don’t comment your code to understand what the code does today, you comment it to understand what it does six months from now after you haven’t looked at it in awhile.
This has really hit home as we’ve been brought in to fix some work that we didn’t originally do ourselves. Picking up where another firm left off and having to pick your way through their work has been an interesting exercise. And I’ve landed on a new personal axiom of software development.
The cleverness of a solution should be inversely proportional to how long it needs to be functional
If you’re going to put some clever trick into your code that does some whiz-bang thing to get it working, make sure it’s not pertaining to some important function that is going to be around for awhile. The reason for this is that when other people go to look at your code, they are not going to be nearly as clever as you are. Included in that group of coders is future you. Basically, the more tricky and slick you are with code, the more likely you are to royally screw things up when you go back to work on the codebase in the future.
In the case of us coming in behind someone else’s work, they did some cool tricks to get things working. And we stubbed our toes on every single one of them. And the worst part is, the code was documented…it just wasn’t front and center as we were working on it. When we finally isolated what was going on, there were plenty of simple and intuitive options they could have chosen to do the same thing, but they opted for the slick way to do it, and it ended up biting us.