3 ms·
For me the benchmark is how much time it takes me to figure out my own code when I come back to it six months later. If I can glance at it and still know what I
by jillesvangurp 3y ago
For me the benchmark is how much time it takes me to figure out my own code when I come back to it six months later. If I can glance at it and still know what I was thinking, I did an OK job. If you stick around long enough on a software system, you will come across code that you wrote that you struggle to understand. Failing this test can be an educational moment. It's your code after all. So, obviously you messed up. But how? How could you improve things? These are important questions because failing to address the issue just sets you up for more problems later. The worst you can do is walking away and then having to figure it out all over again a few months later.
Cognitive load of understanding code is expensive. I tend to leave notes for myself. Document the not so obvious things with little one liner comments. Rename variables to clarify what they are for. Extracting code to get rid of the distracting clutter. Etc. I sometimes get comments from others that they find this helpful. That's nice. But I do it for myself as well.
Simple code is obvious in what it does. There's a certain elegance to simple code solving big problems. It takes effort to make things simple. Making things as complicated as needed but not more complicated. Being overly clever means you end up with a Rube Goldberg machine of unnecessary complexity and clever mechanics that is hard to understand and maintain. You get a certain satisfaction out of making that kind of stuff work but in the end it's a mistake.