Re:Java is Pass-by-Value, Dammit
by tedunangst on Sunday March 22, 2015 @01:53AM
(#9245765)
"It works just like Python"
[ Parent
| on HN ]
Exactly. Objects in Java work just like objects in Python: pointers passed by value. The difference is that everything in Python is an object, whereas Java additionally has primitive types where the value itself is passed by value.
I don't know if that'd help or hurt, I've definitely seen people also say Python is pass by reference. It seems like they have the same problem.
Storically, python devs says the python language use "pass-by-name"
Re:Java is Pass-by-Value, Dammit
by icebraining on Sunday March 22, 2015 @06:13AM
(#9246237)
How so? Reading [1] on pass-by-name, I don't see how it applies to Python, which evaluates the function arguments before passing them.
The example given would be, in Python,
def double(x):
x *= 2
a = [4]
double(a[0])
If Python was pass-by-name, a would now be [8], but it's actually still [4].[1] http://www.cs.sfu.ca/~cameron/Teaching/383/PassByName.html