Hacker News new | ask | show | jobs
by orzig 1266 days ago
I am with you on this, though I am in a minority at work. An underappreciated benefit is that you are signaling to the reader, when they first see the variable, that it will only be used briefly. That helps them ration their attention.

The strongest counter argument is that developers cannot be trusted to avoid building a house of cards if you let them use, even a single shortcut. And there is plenty of evidence, including my own experience, to back that up. But if you can prove you will re-factor when the time is right, it becomes a lot easier to make your case for brevity.

2 comments

> though I am in a minority at work

This should tell you something. Taking the time to name it nicely now costs almost nothing vs wasting your time trying to prove it can be refactored later and then doing that refactor later. Why? What are you getting out this? Taking 1 second to name it nicely vs the time it costs for everyone to listen to you "make a case for brevity", just please don't be that person. No one likes or respects that person more even when you are right.

The main argument I see for short variable names is that it's easier to read, and interpret (yes, ironically the exact same case the other side makes). In certain contexts (for small functions, math) code is a lot easier to read when using simple, or single variable names. Every now and then I see someone writing out math formulas with long names, and it's so difficult to grok the equation. Just use single variable names so we can grasp the whole thing in a single glance!
I disagree that naming something correctly always takes no time. Sometimes a useful and correct name is non-obvious, or repetitive, or you're trying to name something abstract or generic.
Yea, often vars are placeholders and making them descripting just makes them misleading and harder to get to the point. But yea at least I trust myself to refactor code and make the var name more descriptive if I see it's no longer just temporary placeholder... but would be a challenge to have others follow the same principle. One using is short name because it only helps, another to use it because you are just lazy.