Hacker News new | ask | show | jobs
Ask HN: Confused by a friend in discussion of variables
5 points by IAskForAFriend 3373 days ago
A friend of mine is not a programmer, but does program. My friend has a degree in mathematics, works in the supply of a specific type of computer hardware, uses Perl to accomplish various scripting tasks, and is very capable in doing so.

In discussion about programming languages I mentioned that "variables" are boxes to put things in, and the thing we put in them are "values". "Values" can be complicated, and may actually be references to other things.

My friend went thoughtful, and then said:

Suppose I have a hash:

    $next{"thingy"}="whatname";
    $next{"whatname"}="wotsit";
    $next{"wotsit"}="doohickey";
Then I would have said (my friend said) that:

    $next{$next{$next{"thingy"}}}
is another name for "doohickey" and hence is a variable.

Is this a common point of view?

2 comments

Kinda. Sometimes these are called "lvalues" (because they go on the left-hand side of an assignment statement), or perhaps "places", or some similar name. It depends on the language, and what languages the designer was influenced/inspired by when they were doing the design work. That leaves "variable" to just refer to the simplest case.

Oh, and just for the record, your friend _is_ a programmer. Maybe it's secondary to the mathematics, but nobody is ever just one thing.

Thank you for the reply - interesting.

Just to clarify, saying that my friend is not a programmer was meant to set expectations, not to be disparaging. My friend write short scripts to accomplish specific tasks, but is not employed to write programs, has never studied programming or computer science, has never written a program longer than about 50 to 100 lines, has never written a program for someone else to use, and actively refuses to be called a programmer.

Neither of us consider that a problem or criticism, but simply a statement of fact. I play music, but I'm not a musician. I sing, but I'm not a singer. I dance, but I'm not a dancer. I write stuff, but I'm not a writer. I program, but I'm not a programmer. I do math, and use math, but I'm not a mathematician. On occasion I run, but I'm not a runner. Yes the exact boundaries are fuzzy, it's difficult to create clear and precise definitions, but to describe someone who cooks the occasional dinner "a chef", or even "a cook", is to lose distinctions I think are worth retaining, and to dilute the terms to the point of being effectively worthless.

Oh, and my friend doesn't use the mathematics particularly either, and refuses now to be called a mathematician.

But it's unlikely we'll reach agreement on this, so I just thought I'd make my position clear.

What you have there is an l-value, which is an expression that evaluates to a location into which a value can be placed.

A variable is a single name and is the simplest example of an expression that is an l-value.