Re: Pass by Reference
- Posted by mattlewis (admin) Sep 12, 2009
- 2374 views
I know I've lobbied for some kind of "var_id" mechanism before, but good copy-on-write semantics (which I believe that Euphoria has?) and an optimization of the case "foo = func(foo)" should take care of most pass-by-reference needs, IMO.
There are some cases where that's possible. I think one place where reference semantics are probably necessary is when you start dealing with OO. Consider the case where you have a member procedure that does something with private data. In this case, you may not even consider this to be passing by reference, but it really is, from a low level perspective. However, I think that it's perfectly natural, and not likely to confuse anyone. (This assumes, of course, that some sort of OO is eventually added to euphoria).
There are certainly benefits to easily passing references, and if you came from another language, it wouldn't surprise me that this was something you found extremely lacking. If we add something like this, we have to be careful to keep it 'euphorian'.
One aspect of that is to avoid making it too complicated, or difficult to use. That's a difficult task. While we've talked about the theoretical performance implications of COW, they appear to mainly be just thattheoretical. I'm sure we could create a situation where it was a real performance killer, but I think that in real applications, it's not.
So the real reason for adding it should be that it makes certain tasks easier (which it certainly will) without making other things more difficult, or causing drastic changes to the language as a whole.
Things like var_id(), and other reflection like techniques are more likely to surface when we get into dynamically evaluated code. It might be a reasonable workaround for a more native implementation of PBR.
Matt