Live data from Hacker News

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

beehollander.wordpress.com

91–100 of 111 posts

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

#91
post #52

Pwd stands for: ________? Correct, you guessed it! Once an abbreviation or acronym becomes widely used it makes sense to use it as a variable name for as long as you live.

This comment really deeply gets to the heart of the issue. Programmer X thinks "I'll abbreviate because MAN IT IS SO OBVIOUS what the abbreviation is, what sort of idiot would think anything else?". You have nothing to lose by typing: let password = '' as opposed to let pwd = ''

It depends on how many characters are significant to the compiler/interpreter. This was a real issue in the 80s, as laughable as it sounds now.

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

#92
post #89
post #65

Earlier quoted context omitted.

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

I see no connection here to what I wrote, which has nothing to do with functional vs. imperative programming. I'm talking about names and readability in code.

Imperativeness is a separate matter. One can easily have it without longDescriptiveNames, and although I don't have Knuth handy, I imagine he did.

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

#93

Earlier quoted context omitted.

"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.

I was joking. The example sort of looks like something that would fall out of minify -- although 'a' - 'z' would have to be used/visible in a scope before 'aa' would be generated as a name.

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

#94

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…

I'd expect that to be a prefixed variable with a comment of the link:

link to the post you got it from here

Vec_r, Vec_st, Vec_u

If you just used the raw letters that's jank. Single letter variables should only be used in very short code blocks or loops.

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

#95
post #92
post #89

Earlier quoted context omitted.

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

I see no connection here to what I wrote, which has nothing to do with functional vs. imperative programming. I'm talking about names and readability in code. Imperativeness is a separate matter. One can easily have it without longDescriptiveNames, and although I don't have Knuth handy, I imagine he did.

[deleted]

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

#96

Earlier quoted context omitted.

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.

I was joking. The example sort of looks like something that would fall out of minify -- although 'a' - 'z' would have to be used/visible in a scope before 'aa' would be generated as a name.

I should have clarified. The coder style of naming might seem to be run through minifier, but the coder actually wrote 'a', 'aa', 'aaa'...

My guess is that the coder saw a minified code a took it as a standard or something.

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

#97
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.

It depends on whether The Compiler is Smart Enough™ — verbose code, for example, declares variables for values before using them in expressions.

So instead of

    if (long.and(Complex(Expression)) && (other || long && expressions)
You use

    mandatoryConditional = long.and(Complex(Expression))
    optionalConditional = other
    otherOptional = complex && expressions
    
    if (mandatoryConditional && (optionalConditional || otherOptional)
Now you have more names hanging around, and longer code, but it's better to read, especially if these conditional variables are named properly. Some people fear that this could negatively impact execution time, but I don't think it will have any noticable impact in modern languages.

Another problem could occur where people verbosely allocate things, pre-computing and re-computing aggregate data structures, and a one-liner would've been more efficient since it goes over the same data only once.

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

#98

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…

I write a lot of code like that. Usually I start off with a huge comment block, detailing what the function does, outlining the algorithm used and explaining the notation. Only then I include both the link to the paper and and the full citation.

It's about as much work as writing the code in the first place, but it has saved me a lot of times when I or someone else had to go and work on it.

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

#99
post #92
post #89

Earlier quoted context omitted.

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

I see no connection here to what I wrote, which has nothing to do with functional vs. imperative programming. I'm talking about names and readability in code. Imperativeness is a separate matter. One can easily have it without longDescriptiveNames, and although I don't have Knuth handy, I imagine he did.

At first read the idea you propose is very attractive but I think you do need to address why APL didn't take off. Perhaps they chose a poor vocabulary, are there better ways to represent algorithms?

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

#100
post #20

Earlier quoted context omitted.

Historically, i wasn't even an abbreviation: It was the first variable name which would be assumed to be integer by FORTRAN compilers which implicitly assigned types to variables based on name. The choice was probably further influenced by longstanding mathematical tradition, which uses i and j as indices. (You could declare types and the compiler would respect it, leading to the old truism "GOD is REAL, unless decla…

I think the weirdest thing old Fortran did was to let you pass a constant by reference to a subroutine, which could therefore change its value.

PHP let's you change a constant in a subclass. Doesn't seem right.
Post reply on HN