Hacker News new | ask | show | jobs
by pjdkoch 1266 days ago
You're not alone. 3 to 5 letters works best for me.

Obligatory reference, given the aesthetic: https://archive.vn/mIwG0

My rule of thumb is to avoid variable names that are only used once. Instead, use something like pipeline operators, flow(), etc.

Another preference I have is to use initialisms. Might feel dumb at first, but eventually you realize (or I did, at least) that it matters more how things are "braided together" than having perfect names, and your editor prolly highlights all the uses of the variable where you have your cursor.

But, as always, prefer consistency with the rest of the team, even if you feel the rule is dumb. Don't proselytize. If the style really gets in your way to understanding the code, rewrite it and throw it away. There's something elucidating (and satisfying) in seeing a non-obvious piece of code in your native style.

2 comments

OP: "I prefer single letter variables"

Reply: "You're not alone. 3 to 5 letters works best for me."

I mostly agree with your comment, also the "prefer consistency with the rest of the team" part, but you are not proposing the same as what OP described.

Apparently they're not a fan of consistency, either :)
No, it's more than I'm just dumb.
> There's something elucidating (and satisfying) in seeing a non-obvious piece of code in your native style.

Not 5 years later, and when it is someone else's code. Just don't. Initialisms are no better than single char var names. No one later is going to know you started naming "SmartFooProcessingThing" as "sfpt" and when they search for it in millions of lines of the codebase, they are gonna come up empty and waste time.

There is nothing you should be finding "satisfying" in a non-obvious piece of code. And if you are working on team, there should be nothing "in your native style". Don't be that person.

I don't think we're talking about the same things.

> Not 5 years later, and when it is someone else's code. Just don't.

That's precisely when you rewrite more: when the initial context is gone.

> Initialisms are no better than single char var names.

Correct.

> No one later is going to know you started naming "SmartFooProcessingThing" as "sfpt" and when they search for it in millions of lines of the codebase, they are gonna come up empty and waste time.

They're not meant to be grepped for. They're meant to be local, fleeting, names for something.

> There is nothing you should be finding "satisfying" in a non-obvious piece of code.

There is. When you understand it, it's satisfying. Or so has been my experience. There's also the frustration of "why was this left like this in the first place", but sometimes it's merely a matter of preference.

Please note that I'm advocating for rewriting and throwing away things you don't understand, not for leaving puzzles for others to relish on.

> And if you are working on team, there should be nothing "in your native style". Don't be that person.

Indeed.