- Evaluation Strategies and Method Arguments
- Argument Passing: Call-by-Value vs. Call-by-Reference
- Language vs. Implementation
- Call-by-Sharing
- References
Language vs. Implementation
Remember those passionate Ruby programmers I mentioned earlier, the ones who say that Ruby uses call-by-value? It just so happens that they have a very compelling argument. In a nutshell, they suggest that variables in Ruby aren't objects; rather, they're references to objects. When actual arguments are mapped to formal arguments, it's not objects that are being copied, but instead these references. Actual arguments and formal arguments are completely separate values, yet they refer to the same objects.
While this description seems to be in line with how Ruby behaves, I find the additional indirection to be dubious and unnecessary. Sure, if you peel back the covers of the official Ruby interpreter, you'd see exactly what I just described. In the C implementation of the interpreter, Ruby variables are pointers to objects. When methods are called, pointers are passed around, not objects. This is exactly how you emulate call-by-reference in C.
But does it make sense to derive the behavior of a language by inspecting a single implementation? Of course not. That's why we have language specifications and standards committees. So what does the ISO/JISC Draft Specification of Ruby say? [5]
I wish I could report that the language specification mentions either call-by-value or call-by-reference, but alas, it doesn't. However, the specification is very clear about how actual arguments are mapped to formal arguments. If fact, it describes an argument passing style that is neither call-by-value nor call-by-reference. That means we'll need a new term and definition.