views:

686

answers:

8

Java/C# language lawyers like to say that their language passes references by value. This would mean that a "reference" is an object-pointer which is copied when calling a function.

Meanwhile, in C++ (and also in a more dynamic form in Perl and PHP) a reference is an alias to some other name (or run-time value in the dynamic case).

I'm interested in the etymology here. What were early uses of the term "reference"? Lets go for pre-Java, but if you know of pre-C++ uses, that would also interest me.

(I'm aware that vocabulary changes, etc, but I'm just interested in the history).

+1  A: 

I would imagine that you could trace it back to C which had (and still has) pointers as well as reference and dereferencing operators.

Andrew Hare
I've never heard the term "reference" used in relation to C.
Paul Biggar
Andrew Dalke
@dalke - Thanks :)
Andrew Hare
Fair enough, though I seem unable to retract my downvote. Sorry :(
Paul Biggar
+1  A: 

I THINK it dates back to PASCAL, probably farther.

The original FORTRAN passed arguments by reference: passing the address of the variable, array, or matrix.

ALGOL-60 passed by name or by value. Call-by-name turned out to be a huge mistake, that taught programming language designers a LOT about what NOT to do. PASCAL passed parameters by value or by reference, depending on whether the parameter was marked VAR (pass by reference) or not (pass by value).

John R. Strohm
Great answer! So I guess Fortran came in 57, and Pascal in the early 70s? Did they use the term "reference" or just the concept.
Paul Biggar
@Paul - they used different terminology; see my answer
Stephen C
As a note, the Pascal Revised Report ( http://www.fh-jena.de/~kleine/history/languages/Wirth-PascalRevisedReport.pdf ) does not mention "pass-by-reference" and instead uses "variable reference." (Section 9.1.2)
Andrew Dalke
That being dated Nov. 1972
Andrew Dalke
+9  A: 

(this reply relates to C# only, AFAIK)

Don't tell Eric Lippert that references are pointers ;-p They happen to be the same thing in MS C# / .NET, but that is an implementation detail. A reference is an opaque, safe "thing" that allows you to locate an object. A pointer is a memory address. They worked hard to make sure that you always know which you mean...

It would be entirely feasible to implement a CLI and compiler that didn't treat the two as the same; you would still be passing a reference to the value, though.

References are not addresses

Marc Gravell
As always Eric's blog is informative!
RichardOD
Interesting. I believe the Java reference manual calls them pointers at some point - I'm more familiar with the Java case.
Paul Biggar
+1 Agreed, pointers are a kind of reference.
Andrew Hare
Great link from Eric Lippert!
Alex
A pointer is not a memory address. A pointer is often a memory address, but it is not a memory address. There are systems with segmented memory, for example, where a pointer might be an offset ("near" pointers) or a selector plus an offset ("far" pointers).C# pointers have the same operational semantics as pointers, by definition. Pointers are references that can be rebound, and that's precisely what C# has.
DrPizza
@DrPizza - hmmm... goes to show what I know. Fair enough; I'll leave "as is" as a note relating to references vs memory addresses, but your point is noted. I would have to dig deep into the definitions to even try to challenge it, so I'll assume it is correct.
Marc Gravell
+1  A: 

The earliest uses of the term "reference" as in "pass by reference" are probably lost in dim antiquity. Certainly, FORTRAN passes its parameters by reference and always has done.

A mention of "call by name" reminds me of a Nickolas Wirth (inventor of Pascal) joke (probably the only one):

"Professor, how do you pronounce your surname?"

"If you call by name, it is V-I-R-T, but if you call by value it is W-O-R-T-H"

And people say programmers have no sense of humor!

anon
+14  A: 

There is an early usage of the term "call by reference" in the paper "Semantic Models of Parameter Passing" by Richard E Fairley, March 1973.

In the early days, the terminology was inconsistent. For example, the Fortran 66 specification uses the phrases "association by name" and "association by value". We would now call these "call by reference" and "call by value". By contrast, Algol 60 specification (1962) used the terms "call by name" and "call by value".

EDIT: To those who want to label the pioneers who specified Fortran 66 as confused for using the phrase "association by name", consider this:

  1. The Fortran 66 was the first attempt to specify a language with (what we now call) call by reference.

  2. It was only the second attempt to specify a language with subroutines that supported parameter passing.

  3. Fortran 66's "association by name" can be viewed as a restricted (degenerate) form of Algol 60's "call by name". The restriction being that in Fortran, the name had to be a simple variable or array name, where in Algol 60 it could be any expression.

  4. It was not clear at the time (1966) that Algol 60's "call by name" was destined to be abandoned as a bad idea. Indeed, when I studied Algol 60 as an undergraduate in 1977, I don't recall the lecturer presenting "call by name" as a bad idea. (It was presented as difficult to understand ... but that's a different thing.)

Stephen C
Was "association by name" a reference (it sounds like an alias), or was it Algol-style call-by-value (which had all sorts of weird, described in another answer)?
Paul Biggar
@Paul - as I said, it was what we would now call "call by reference". Check the linked spec.
Stephen C
Functional languages still use the terms "call-by-name" and "call-by-value", along with an additional classification: "call-by-need" (e.g. Haskell).
Daniel Spiewak
Good finds! But I wouldn't have said "inconsistent", which has a hint of being confused. It seems that different people consistently chose different nomenclature but knew they referred to the same terms, and that "call-by-reference" (or "pass-by-reference") won over "association."
Andrew Dalke
Inconsistent != confused. I am simply saying that no consensus had been reached.
Stephen C
+1  A: 

I'd always thought that the idea was to distinguish between a pointer and reference. References will point to the object wherever it is.

A pointer is to an address in memory however in managed languages this can change. So you must have an abstraction via the reference to ensure your code always works. eg. you couldn't just write reference++ when using arrays in a managed language as the garbage collector can move your array. Please note I'm well aware of pinning and unsafe code in c# :).

As my java tutor had explained it to me as well, the other key "concept" with a reference is that you can't manipulate it. Pointers are for the programmer to manage, references are for the compiler/runtime to manage.

Spence
+2  A: 

I think the term you should use for historical searches is "call-by-reference" and not "pass-by-reference." For example, Wikipedia redirects "Pass-by-reference" to "Evaluation Strategy", which lists call-by-reference.

Using "call-by-reference" as a search term in Google Books finds a snippet from "The Main Features of CPL" from The Computer Journal, August 1963; 6: 134 - 143 (British Computer Society)

Three modes of parameter call are possible; call by value (which is equivalent to the ALGOL call by value), call by substitution (equivalent to ALGOL call by name), and call by reference. In the latter case, the LH value of the actual parameter is handed over; this corresponds to the "call by simple name" suggested by Strachey and Wilkes (1961). Note the correspondence to the three kinds of initialization...

This latter "call by name" is likely the same terminology as was used in the Algol 60 specification, which Stephen C earlier pointed out in this thread.

(I think "Strachey and Wilkes" is from CACM 1961 but I don't have access to any source text to verify.)

Andrew Dalke
John R. Strohm
A: 

Note that, in the '60s (yeah, into the '70s), "reference" meant using the name of something. This agrees with the usage of the older philosophical and linguistic terms "referent" and "reference". From Fortran 77:

2.12 Reference

A variable, array element, or substring reference is the appearance of a variable, array element, or substring name, respectively, in a statement in a context requiring the value of that entity to be used during the execution of the executable program. When a reference to an entity is executed, its current value is available. In this standard, the act of defining an entity is not considered a reference to that entity.

A procedure reference is the appearance of a procedure name in a statement in a context that requires the actions specified by the procedure to be executed during the execution of the executable program. When a procedure reference is executed, the procedure must be available.

outis
This seems to be talking in the sense of "dereference", as opposed to "call-by-reference". Is there another use of the term reference?
Paul Biggar
Before references were called references, and when "call-by-reference" was called "association by name" (as Stephen C points out), "reference" had a different use. Between the '60s and now, the meaning of "reference" changed.
outis
The above and Stephen's answer (especially point 3) suggest a possible etymology: "association by name" was a more restrictive version of "call by name" that only allowed variable references (in the sense of "that which names something") to be associated with dummy arguments. Whether there's any truth to this depends on how explicit the difference between the two calling semantics was back in the day, and whether or not anyone cared to make the two more distinct.
outis