TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Every programmer has a variable naming philosophy

15 pointsby marketerover 15 years ago

4 comments

ryanelkinsover 15 years ago
I like to be somewhat verbose with my naming. I don't like to abbreviate unless its a very common and well understood abbreviation. If nothing else because I can have a terrible memory and find myself struggling to remember exactly what a variable is storing otherwise. I can't imagine what it would be like for a different programmer entirely.<p>Perhaps I've just had to work with too much code that has poorly (in my opinion) named variables.<p>Then again I also have intellisense and autocomplete so I don't really fear a slightly longish variable name if it makes sense.
评论 #1101520 未加载
评论 #1101377 未加载
meese_over 15 years ago
This reminded me of a previous comment (and discussion) on HN: <a href="http://news.ycombinator.com/item?id=840331" rel="nofollow">http://news.ycombinator.com/item?id=840331</a><p>"Another way to look at this: The first time you meet someone, you learn their full name. When discussing them with someone else who knows them, you use just a single name. If they're standing right there, you don't bother using their name, but just make eye contact, and maybe a "Hey". Should be the same way with variables."
评论 #1107728 未加载
thaumaturgyover 15 years ago
Here's mine, just for fun. I haven't seen anyone else using anything like it.<p>kVariable: A constant value, even in languages that don't support constants. Usually either a semantic shortcut for some value, or for some knob that can be turned at the top of the code.<p>xVariable: A local variable.<p>gVariable: Global. (I care much more about variable scope than I do about variable type.)<p>x, y, z, i, j, k: Counters. I try not to nest or overuse these too much. If it starts to get hard to follow, then I rename them.<p>There are a couple of other hints that I leave myself too. For example, I tend to pluralize the names of variables that contain arrays or lists of things: xWindowElements for example.<p>I never cared for Hungarian notation or its brethren. To me, it just had too steep of a learning curve for too little payoff, and didn't even convey the information that I usually needed.
评论 #1101428 未加载
评论 #1101528 未加载
评论 #1101494 未加载
sdhover 15 years ago
Why does it matter if a variable name is longer than it should be? As long as the code is legible, who cares?<p>I assume the author isn't saying that all variables should be named like "i" and "j" (and those examples are bad ones since they are well-known conventions), but that a variable shouldn't be named any longer than is needed to convey meaning.<p>Ok. Why even make this point? Programmers should err on the side of too long rather than too short. And, whenever possible, use the conventions of the language in favor of their personal philosophy.