Re: Pass by Reference
- Posted by DerekParnell (admin) Dec 18, 2014
- 3587 views
But it doesn't answer the question why OpenEuphoria support pass by reference.
If one passes a reference to an item to a routine, without actually looking at the receiver's source code, can the coder know if the passed item will be modified or not?
If a language knows, without a doubt, that a passed item cannot be modified by the called routine, then many optimisation possibilities open up for it.
If you want to see this philosophy in action, take a look at the D Programming Language. That modern language does support PBR but that is not the default. The default is that declared items are read-only, even when passed by reference. This language forces the coder to make extremely explicit, any intention to modify items passed to routines. The resulting object code can be very optimised when the compiler knows about this.
In general, it is a safer practice to pass by value, and much less costly to maintain programs written this way. The performance of PBR is not generally an issue but in those situations where it is a factor, you can revert to less safe coding practices (using 'global' memory).