Jeff Schneider continues his search for answers on how to do pass by reference in Web services.
I believe pass by reference is impossible when doing Web services.
Some time ago, I had a long and heated discussions with a customer and several colleagues about whether Java does pass by value or pass by reference, where we were evenly split among the views that there is only pass by value on the one hand, and only pass by reference on the other hand. (Incidentally, while looking for a normative definition, I came across an article that shares my point of view - Java does pass by value only. Really. Think about it.)
To me, pass by reference semantics only make sense in the case of programming languages - it’s a syntactical issue that you put a variable in place of a formal parameter, and the language implementation (compiled or interpreted) passes a pointer to the variable instead of the value. I believe anytime you make a copy of some data - which is unavoidable if caller and callee don’t reside in the same address space - you can’t do pass by reference.
Of course I concede that a Web services-based language might offer some sort of syntax to pass pointers under the covers, but that would probably be a bad idea and only lead to subtle bugs. Better to pass references - and pass them by value.
Tobbi Bouda, one of the great engineers at Systinet, sent me some comments …
Hi Stefan, a few weeks ago, I met the same question.
At school I’ve been learning there are formally a three ways how to pass a parameter: 1) by value, 2) by reference, 3) by text. Let’s omit the third possibility because it’s rather historical stuff.
The first way is the most important one - languages can’t exist without it. A good example is C which has simple values and pointers to them, but no references.
The second way is used as an enhancement to C. C++ using ‘&’ operation does exactly what parameter referencing is expected to do. The original value can be changed. Not using the reference operator causes any object passed to method in C++ to be duplicated via copy-constructor.
What’s the situation in Java? Primitive types are surely passed by value. Object types are said to be passed by reference, BUT the only user-handle to an instance is reference. Finally, the reference is passed by value.
I’ve searched (very shortly) Java spec. but no exact solution found. Just some indices:
I.e. I think from the formal point of view, passing parameters in Java is always by value.
Tobbi