Live data from Hacker News

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

beehollander.wordpress.com

41–50 of 111 posts

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

#41
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).

That same engineer would frequently nest for loops inside for loops inside for loops with indeces like ii, jj, and kk. Drove me nuts sometimes.

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

#43
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"

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

#44

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…

Probably has to do with decades (centuries?) of knowledge that is passed on in a somewhat consistent and rigorous way. Programming is a relatively new field, with tons of self-taught practitioners.

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

#45

The problem was not that the variable was abbreviated. The problem was that the abbreviated variable was so similar to another abbreviated variable that was used for a similar purpose.

sure but if the variable was not abbreviated the chance of collision would have been less.

Even with a 200 character variable name, the chance of collision is 100% if it was auto-completed or copy-pasted.

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

#46

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…

> "Is it because they deal in more abstract entities where the name is irrelevant?"

Partially, but also because math equations don't really have strong maintainability needs. Another mathematician isn't going to walk in 6 months later, get confused, and blow up the universe.

Though I'd argue that in fact math equations should be better named. They're rather abstractly named as a matter of convention, but they would be more easily understandable in many cases if variables were more carefully named.

Another risk of "porting" geometry algorithms, especially complex ones, directly from their mathematical expressions, is that you don't gain insight into why they work. This makes debugging later difficult, since nobody who wrote the code actually understood what the algorithm was doing. Forcing yourself to rename variables into something sensible will also force you to understand the mechanics of what's happening.

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

#47

I self-tested variable name lengths on my own code. Three letters is enough to avoid most collisions. Words do not make sense yet. At four letters most words become decipherable given an appropriate encoding. At five letters a two word phrase may make sense. I make a rough decision based on variable scope - shorter lifetime means shorter variable name, but I rarely go with just one letter as it reduces uniqueness. If…

Did you self test on code from years ago or was it all fresh in your mind?

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

#50

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…

>Why is okay for mathemeticians to abbreviate things but programmers? Is it because they deal in more abstract entities where the name is irrelevant?

for example, xyz^2 in a piece of written math means something different than it would in a program (in the math case we are obviously not taking the variable "xyz" and squaring it). I guess what I am trying to say with this example is that perhaps variable names in math are one symbol because concatenation, in many cases, already means "multiply".

Post reply on HN