which language allows you to change an argument's value?

Arne Vajhøj arne at vajhoej.dk
Sun Sep 30 23:03:15 CEST 2007

Erik Wikström wrote:
>> their reference (alias) mechanism.  And C, Python, and Ruby probably
>> won't let you do that.  What about Java and Perl?
> C will let you do it with pointers (it is just a syntactical difference
> from references in this case) and Java's references allows it.

Neither C or Java has call by reference.

C pointers and Java references may work similarly in most cases
but it is still call by value.

>                                                                I do not
> know about Ruby, Python and Perl, but (AFAIK) the all have OO support so
> I would be surprised if they used purely value semantics.

I can not see why OO should indicate anything about call by reference

>> isn't "what i pass in, the function can modify it" not a desireable
>> behavior if i am NOT passing in the address of my argument?  For one
> Being able to pass the actual object instead of a copy is highly
> desirable for two reasons. In most languages only one return value is
> allowed for a function so the ability to change parameters allows you to
> artificially return more without having to wrap them in constructs. The
> second reason is that for large objects the performance hit of having to
> create a copy each time you call a function can be forbidding.

Usually it is not a good thing, because it makes the code much
more difficult to read.

But sometimes it is handy.

I think C# got it right.

It allows it but require an explicit marking of it in both formal
argument list and actual argument list.

>> Java, Python, and Ruby, and we pass in a reference to object (not C+
>> +'s meaning of alias reference)
> In what way does the C++ reference differ from those in Java, Python,
> and Ruby in this situation?

C++ and Java are very different in this aspect.


More information about the Python-list mailing list