Name your variables explicitly
When I discovered MaintainableCSS, I couldn’t help but clap here:
As Phil Karton says, “there are only two hard things in Computer Science: cache invalidation and naming things.” So spending a whole chapter talking about naming is essential.
Hell fucking yes! 👏
I can’t stand it when I see developers using unnecessarily short variable names, and for what? To save three characters?
Here’s a common example: naming the parameter in an event listener.
Yeah, they all behave the same, and I sort of understand why some folks like the brevity. But not everyone does. You might know what an abbreviation means, but the person trying to read your code might not.
It’s not obvious.
I’ve had to look at code before and figure out what the hell a
pid variable meant. Turns out it stood for
pageID. OK, so… Why not just call it that in the first place? It’s only three extra characters, but so much clearer!
Here’s another example from the Express documentation:
Again, it’s not obvious what the
res parameters mean. I don’t care if it’s the convention. Just be more fucking explicit.
Now, that’s better 😍
If you have questions, feedback, or any other suggestions, please do email me. I'd love to hear from you!