4 ms·
I found this article rather surprising since I come from a primarily Java background. Do any other languages besides C++ allow this definition of pass-by-refer
by kentosi 17y ago
I found this article rather surprising since I come from a primarily Java background.
Do any other languages besides C++ allow this definition of pass-by-reference? The reason I ask is that it seems silly for me to change the way I talk just to satisfy one language that i don't even code in.
And if so, when would it actually be practical to use this? The idea of reassigning a parameter in a function and then having that reassignment affect variables OUTSIDE the function sounds very strange to me (and possible even dangerous).
- Xixi 17y agoIt used to be very common in Turbo Pascal, where if I remember correctly you had to use the keyword ref.
- enjo 17y agoI disagree with the sentiment that you should simply ignore proper semantics because it's inconvenient. As the article points out, this stuff really does matter. There are classes of problems that these type of true reference semantics can be quite helpful. In C/C++ the technique is largely used in contexts where you want to return multiple values from a function, as there is no native support for dynamic tuples. Such is the way of statically typed languages. There are also cases where this type of reference to a pointer magic can really improve the efficiency of the algorithm. True reference passing is a tool. For those living in dynamic languages (as I do now), not a particularly relevant one. But that doesn't make the distinction any less important.