Live data from Hacker News

Why I'll never abbreviate a variable as long as I live

beehollander.wordpress.com

81–90 of 111 posts

Re: Why I'll never abbreviate a variable as long as I live

#81
post #74

When hiring we ask for sample code from developers written specifically for the job application. We place a really high premium on readability. Occasionally we'll get code from devs that is very concise - not just abbreviated variable names, but complex long statements using ternary etc. I'll usually ask them to resubmit code and really focus on readability and it turns out fine. But I think there might be a misconce…

I'm sorry, how can verbose code impact performance???? Please elaborate.

In shell scripts, for example, accessing a longer variable takes longer time than accessing a shorter variable. In my testing, accessing a 100 character variable took around 20% longer than accessing a 1 character variable.

Re: Why I'll never abbreviate a variable as long as I live

#82
post #7
post #5

I definitely prefer more verbose names to abbreviated ones, but I'm not sure that never abbreviating a variable name is the right way to go either. Surely there's a middle ground between `Ttpfe` and `timeOfTenPercentHeightOnTheFallingEdge`?

Use context. If you can't, refactor so you can. If you can't, well, you're SOL and stuck with timeOfTenPercentHeightOnTheFallingEdge. Edit: e.g. if all of your variables are "timeOfTenPercentHeight...", cut that part out of the name. Full names can be just as bad as abbreviations - e.g. if they're all "timeOfTenPercentHeight..." then they all start to blend together.

Exactly. Make a "times" record/object/tuple (whatever the local custom you have for an aggregate type is), perhaps with a "tenth" nested such item (10% = 1/10), with "fall" and "rise" members.

    times.tenth.fall
    times.tenth.rise
Hopefully, they aren't using some ancient version of FORTRAN.

My first paid work in the 80s was in a language with 8 or 10 character long names, depending on use, with only scalar values outside of ISAM tables. One compiler variant extended that with arrays (but not nested arrays). You had no choice but to make some weird names.

That said, when I started doing ANSI C with 32 char names, I felt like I had failed when I needed a variable that had to be that long to explain what it did. Either it had too broad a scope, or should have been bundled in something else (record/struct).

Re: Why I'll never abbreviate a variable as long as I live

#83
post #60
post #56

Great writeup, full of sharp details. In the 90's I worked on a FoxPro application, also for DoD. My boss, a retired Navy Captain, used very terse variable names, partly because he was a hunt-and-peck typist, and partly because earlier languages allowed only two-character names. But FoxPro allowed variable names of any length. However, it only recognized the first ten characters. To my boss's chagrin, I often used na…

Hearing that absolutely terrifies me like?? Silently allowing names to collide in that way just sounds ridiculous to me.

Many early 90s C compilers did much the same thing, though the limit was usually around 32 chars, rather than merely 10.

Re: Why I'll never abbreviate a variable as long as I live

#84
post #56

Great writeup, full of sharp details. In the 90's I worked on a FoxPro application, also for DoD. My boss, a retired Navy Captain, used very terse variable names, partly because he was a hunt-and-peck typist, and partly because earlier languages allowed only two-character names. But FoxPro allowed variable names of any length. However, it only recognized the first ten characters. To my boss's chagrin, I often used na…

I remember in college in the mid 80s trying to get something to work on one of the Apple IIs in the library in BASIC, only to discover that my earlier experience with the disk based interpreter supported 6 char names, but the ROM based interpreter only recognized the first 2 chars, but would accept longer names it would not differentiate.

Hilarity ensues...

And, yeah, I also did a lot of XBase in the late 80s, though usually "Clipper", rather than "Fox".

Batch files made a decent build process, and you could be disciplined with regular arc/zip files for source - not too unlike "make clean" and svn. We certainly had a lot of cruddy manual processes otherwise back then, though.

Re: Why I'll never abbreviate a variable as long as I live

#85

Earlier quoted context omitted.

Whenever we interview a candidate, the one thing we give high premium on is structure, the rest come next. bad variable names, long complex code...can easily be adjusted . If the candidate doesn't have a good understanding of how to structure a code (what goes where, for what purpose, separation on concern...), it'll take much more effort to teach that candidate than to teach the bad variable namer. Properly structur…

"I ran the code through minify, but it's bigger now?!?"

I don't understand.

Why would one submit a minified code for a review?

A friend of mine used to work at a place where one of the coder actually used 'a', 'aa', 'aaa'...when naming variables.

Re: Why I'll never abbreviate a variable as long as I live

#86
I say this tongue in cheek: With current IDEs having such great autocompletion, has anyone experimented with coding far outside of the ASCII character set? Programming language restrictions aside, I recognize the obvious troubles this would cause. And yet I do a lot of work on simulations where math formulas are converted to code, which means lots of compounded Greek names like "omegaSquared" or "epsilonMinus". Naming decisions becomes more challenging as subscripts and superscripts are added, yet alone matrix indices. At some point perhaps the symbolic name should be replaced with the descriptive name, such as "first_eccentricity_flat_to_fourth". But it sure would be nice to have access to something with such brevity.

Re: Why I'll never abbreviate a variable as long as I live

#87
post #64

May I recommend checking out Rob Pike's document for a counter-point http://doc.cat-v.org/bell_labs/pikestyle I think that his variable names section is utterly ridiculous, but it's a relevant read from a relatively prolific person, so worth sharing.

Thank you for that. That was a good little read.

While many of the Bell Labs guys didn't much like Pascal, Turbo Pascal managed to address almost all of the complaints I've ever seen, while preserving the good parts of Pascal (or Modula???).

Java must look irredeemable to the Bell Labs folks, though. Perhaps it is: UglyNames; limited structured constant literals; still too clunky lambdas for callbacks.

Re: Why I'll never abbreviate a variable as long as I live

#88
post #14

Heh. When I first learned to code as a kid, a variable was max two characters (the first of which had to be a letter A-Z and the other could be a letter or number).

Ha, you're right. Commodore BASIC, probably? (written by Microsoft, I think.) I do remember at some point having access to a language with less restrictions on variable naming, and thinking, "wow, that's so amazing"

Or Apple "integer" BASIC. Probably a few other dialects, as well.

Re: Why I'll never abbreviate a variable as long as I live

#89
post #65

I was recently implementing a geometry algorithm which I looked up on quora. It was described using typical vector notation, using r,s . t,u. Since I referenced the algorithm in the comments, I decided to use these same variable names in my code. I think this is the right choice, but my code reviewer didn't. But he didn't click on the quora link. Why is okay for mathemeticians to abbreviate things but programmers? Is…

In math, notations are designed to make statements about the problem domain concise. Once you pass a certain degree of concision, longer names impede readability rather than enhancing it. That is because the ability to take in an entire complex expression or subexpression at a glance tells you things—and lets you see patterns—that wouldn't be as apparent if longer names were used. Programmers in the APL tradition und…

If you read it and translate what he's saying to programming, you can glimpse a form of software that would make what people today call "readable code" seem as primitive as mathematics before the advent of decimal numbers seems to us.

This is an extraordinary (and enticing and often advocated) claim that has, so far, failed to produce the extraordinary evidence. It says something that a person as concerned with notation as Knuth used mathematical notation for the analysis of algorithms and a primitive imperative machine language to describe behaviour.

Re: Why I'll never abbreviate a variable as long as I live

#90
post #65

I was recently implementing a geometry algorithm which I looked up on quora. It was described using typical vector notation, using r,s . t,u. Since I referenced the algorithm in the comments, I decided to use these same variable names in my code. I think this is the right choice, but my code reviewer didn't. But he didn't click on the quora link. Why is okay for mathemeticians to abbreviate things but programmers? Is…

In math, notations are designed to make statements about the problem domain concise. Once you pass a certain degree of concision, longer names impede readability rather than enhancing it. That is because the ability to take in an entire complex expression or subexpression at a glance tells you things—and lets you see patterns—that wouldn't be as apparent if longer names were used. Programmers in the APL tradition und…

Dang, that was a good comment. Thanks.
Post reply on HN