>But it's kinda both. It's pass-by-value for everything, with the twist that for class instances, the thing that's passed-by-value is the pointer to the object, so it behaves like pass-by-reference.
So he's saying: We call them all "chickens", but some of them walk like a duck and quack like a duck, so they're basically ducks.
You can't extract from that quote "THEY ARE CHICKENS" (all in caps)
When he says "kinda both" and "it behaves like pass-by-reference" I read some "subtle" hints saying that he thinks that basically class instances are passed-by-reference.
Except they don't completely behave like they are passed by reference (see swap in the article). It is only ever correct to say "they behave like they are pointers which were passed by value".
Continuing to say "they act like references" is wrong and how this mess keeps perpetuating.
"It's pass-by-value for everything" is a pretty clear, unambiguous definition that we can all agree with.
I think he goes on to use weasel words like "kinda both" and "the twist" to mean that it's true in a more abstract sense, if you don't use the precise definition of "call by value", and you're fuzzy about exactly what you're referring to (conflating the object with a reference to the object), and vague about how many times you de-reference the pointer that you're passing as a value parameter.
That's an unfortunate shortcut that many Java books and teachers take to teach Java to people who have no prior experience with any other programming language, to avoid teaching about pointers and other implementation details.
That leads to a superficial understanding of the language, and a blind spot in their misunderstandings, which you can see on display in Mark Stock's, Mark Hedley's and Kevin Ryan's stubborn postings to this thread: http://www.theserverside.com/discussions/thread.tss?thread_i...
Java passes pointers to objects by value, which can be used to emulate some but not all aspects of passing objects by reference (i.e. swap).
What your argument comes down to is that you prefer to think of the reference to the object you're passing by value as being the same thing as the object itself, which is not the case. The high level behavioral effect of passing a pointer to an object by value is that you are passing the object itself by reference. But it's impossible for a Java variable to actually contain an object itself, only a reference to an object, and there's no such thing as a reference to a variable or anything other than an object in Java.
Parameter passing by reference requires being able to express a reference to a local variable of any type, including primitive types, not just an object, and you must be able to pass that reference to a function in a way that makes it possible to implement "swap(ref a, ref b)".
Unlike Java, C# does have reference parameters, and it uses the "ref" keyword to distinguish them. Since normal C# parameters are passed exactly the same way as Java parameters, and C# has a "ref" feature that Java doesn't (you can implement swap in C# but not in Java), and you argue for calling Java parameters "pass by reference", then your argument applies to normal C# parameters too, so what do you call C# "ref" parameters if not references? Or do you carry your argument to its logical conclusion, and call both C# normal and "ref" parameters "references"?
Conflating passing a reference to an object by value with passing an object or any other value by reference does not magically give you the power to implement swap, so it's not passing parameter variables by reference, it's only passing the objects that the objects that parameter variables point to by reference.
>But it's kinda both. It's pass-by-value for everything, with the twist that for class instances, the thing that's passed-by-value is the pointer to the object, so it behaves like pass-by-reference.
So he's saying: We call them all "chickens", but some of them walk like a duck and quack like a duck, so they're basically ducks.
You can't extract from that quote "THEY ARE CHICKENS" (all in caps)
When he says "kinda both" and "it behaves like pass-by-reference" I read some "subtle" hints saying that he thinks that basically class instances are passed-by-reference.