On Wed, Nov 13, 2013 at 2:21 PM, Eric MSP Veith
[email protected]wrote:
Gerald Vim wrote in post #1127166:
my $y = shift;
$y = $y + 1;
return $y;
}
my $x = 2;
print f($x), "\n"; # => 3
print $x, "\n"; # => 2
Java, in contrast, does not know about pass by value and always does
pass by reference.
Not true. Java is pass by value, the JLS is clear about this:
When the method or constructor is invoked (§15.12),
the values of the actual argument expressions initialize
newly created parameter variables, each of the declared
Type, before execution of the body of the method or
constructor.
There are many informal resources out there about this debate, see for
example
http://www.javaranch.com/campfire/StoryPassBy.jsp
or
http://architects.dzone.com/articles/java-pass-value-and-not-pass-0
In Ruby, as in Java, the fact that you are dealing with references
belongs
to the conceptual model of the language. It is not the case that you are
supposed to be dealing with objects directly and references are
implementation. The language tells you that you are dealing with
references. (The fact that MRI uses pointers is implementation.)
So in Ruby, as in Java, the arguments hold references, and call
semantics
are pass by value. You pass references to objects by value.