I just finished reading this wonderful blog post entitled, “It’s all Greek to me: Thoughts on code readability and aesthetics” and I got to thinking about how I viewed these crazy one-liner code exercises. The earliest JavaScript example I saw was this guy who had replicated Flappy Bird in something like 14 lines of code. I took a look at it, and considered this guy a genius. And there have been others. Reddit posts where someone made a fancy feature in a few lines. Often the resulting code looked like a cousin to hieroglyphics rather than the language I was used to writing.
But what I’ve come to learn about programming is it’s not all about how small the codebase has become. If I reduce down my code, then sometimes I forfeit understanding as a result.
For instance a variable might be $a in someone’s function, but it might be $title in another. I think the latter makes the most sense, even as temporary variables in code. Losing site of the message means the reader has to interpret what’s happening and they might not see the intent.
I’ve worked on a codebase for a few years now that was written by a talented programmer. He could get things to work, so he knew the language. But he was also writing the code only for himself, so the lines are littered with $a, $b, $xx, and other nondescript variables.
When it comes to readability, being a bit more verbose doesn’t hurt at all. Keep things DRY, but tell the who story.