Live data from Hacker News

Ask HN: I prefer single letter variables

news.ycombinator.com

51–52 of 52 posts

Re: Ask HN: I prefer single letter variables

#51

This is a ridiculous thing to have to discuss. Probably it is a product of software development's version of the "Homeowner's Association", Code Review, where petty rule enforcement is allowed to overrule good sense. The essence of a name is twofold: it identifies a thing, and distinguishes it from every other thing. Anything that achieves these two ends is a good name. Where there is only one thing, its name doesn't…

> ... pay more attention to names that are too similar than to short names. Ah this is exactly why people dislike the short names. If you ever have more than a few of them and they aren't even real words, common abbreviations, or hijack well known unreserved names I would immediately reject that during code review. I think most people are fine with plain English 1 to 3 word names concatenated in whatever style of the…

Keep control of syllables. Each counts against your cognitive limit of "seven plus or minus two" items that fit in registers.

Re: Ask HN: I prefer single letter variables

#52
post #35
post #22

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 to…

> 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…

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.

Post reply on HN