From: Pedro Silva Date: 2008-09-06T22:32:32+09:00 Subject: Re: Request: arguments by reference Hi, > Well, of course there is some performance penalty, but I guess it is not > that fatal. I don't know the actual implementation of accessors in Ruby, > but I think that the time penalty could be really low, and the memory > penalty can be reduced by encapsulating logical group of variables in > one class (which should be done anyway). I think that if they decided > not to include passing by reference in Ruby (and also in Java), then > they had some good solution in mind, and this solution cannot be as bad > as you paint it. In my opinion there are essentially two reasons: 1 - Everything is supposed to be an object; 2 - Anything that needs to be altered is inside the passed object. If everything is an object than everything is "encapsulated", so when you pass the object's reference value you can change that object in any way you want. If you need to swap anything, that must be done inside any particular object. I guess they are counting on this two things. But once again, if this rules were perfect Java won't have primitive data types, nor Ruby would have immutable objects. > Also I think that in a well designed program, the situations where you > need such behaviour would not exist. Of course performance is important, > but I think that still the most important thing is the ability to create > a nice, readable and structured code, so I would definitely choose > encapsulating over changing the language. That would be almost true if there weren't primitives nor immutable objects, but that's not the case. I may be wrong, but who decided that these mecanisms are enough was thinking in the solution you gave, that represents a small amount of cases. The other solution (in Ruby) is to return as result all altered variables in a specific order and assigned them to variables you want to alter (I guess it's known as call-by-value-return). The main need for references is to allow primitive/immutable types to be treated "as objects". Even if the only thing that Ruby used to implement references was the object encapsulation, at least you have that option and don't need to be doing that all the time it needs to be done. Being inside Ruby it would be certainly faster than user made code. If you think in C pointers or C++ references that's what they really are - "capsules". I think it's preferable to have this option even if it isn't as performant, but the programmer has the choice. Pedro. -- Posted via http://www.ruby-forum.com/.