funkiwan (2) [Avatar] Offline
#1
I was a bit surprised to find the following footnote on pg . 60:

'The phrase "passing an object" is short for "passing a reference of an object." In Groovy and Java alike, objects are passed as references when they are arguments of a method call.'

I think this could be edited a bit more for clarity. Here's a couple of links that do a far better job than I could of making the distinction between passing by value and passing by reference:

http://www.ibm.com/developerworks/library/j-praxis/pr1.html
http://javadude.com/articles/passbyvalue.htm
Mittie (397) [Avatar] Offline
#2
Re: Pass by reference?
Hi funkiwan,

thanks for the pointers, which cover the topic of "pass-by-value" vs. "pass-by-reference" very nicely.
However, the footnote is not about this distinction. It is only about the wording that we use in the book to make our life a bit easier and - to make reading easier with the somewhat "sloppy" wording.
But since the user (i.e. reader) is always right: which footnote would have helped you?

thanks for posting
Dierk
funkiwan (2) [Avatar] Offline
#3
Re: Pass by reference?
Thanks for such a quick response! I understand that your point wasn't attempting to directly address the difference between the two. It's been my experience that so many Java programmers are under the misconception that it's a "pass-by-reference" language that I think it's (extra) important to be clear when you discuss argument passing.

Perhaps something along the lines of:

'The phrase "passing an object" is short for "passing a copy of the reference of an object." In Groovy and Java alike, objects references are passed by value when they are arguments of a method call.'

or

'The phrase "passing an object" is short for "passing a copy of the reference of an object." In Groovy and Java alike, all object variables are object references. Copies of the references are passed as arguments of a method call.'

You might consider also including either of the links I referenced or one of your own that details the distinction.
Mittie (397) [Avatar] Offline
#4
Re: Pass by reference?
very good suggestion!

thanks a lot
Dierk