Pass by Reference in Web Services
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
Needless to say, I totally agree. In a former life, I used to be a C++ language lawyer, and having had to explain things like “const * & s” a few times helps appreciating languages like Java ;-)
I believe that passing by reference is possible also when different address spaces are used. Reference is not the same thing that C-like pointer. RMI and other middlewares for distributed programming support the concept of global reference as an extension of the local one (based on the pointer concept). A global reference is able to identify the position of a data in a distributed memory built atop of a distributed system of computers. RMI, for example, supports passing by reference of remote objects, since they are not copied when passed as parameters or return values. More precisely, RMI supports passing by value of global references (the same semantics of Java parameter passing for conventional objects). Sincerely, I don’t understand why Web services can not support reference passing (i.e. a syntactic extension to specify the passing of a data reference or a standard mechanism to pass by value a global reference). Can you explain your point of view on this ?