News for hackers. Stuff that matters.
Re:Java is Pass-by-Value, Dammit by learc83 on Sunday March 22, 2015 @01:17AM (#9245691)
Not everyone knows C. A large percentage (maybe even the majority) of programmers who graduate from Java schools don't know C very well at all. For them, "it works just like C" is an insufficient explanation.
Re:Java is Pass-by-Value, Dammit by userbinator on Sunday March 22, 2015 @06:23AM (#9246262)
Or Asm, for that matter (likely even fewer programmers); at that level, basic concepts like memory addressing and pointers become almost "obvious facts of life".

As someone who started in Asm, I think pass-by-value/pass-by-reference are also intuitive there in the true "understood without needing any explanation" sense, since basically everything you'd pass to a procedure is a value of some sort, and it only depends on whether you are to interpret that value as a memory address.

Re:Java is Pass-by-Value, Dammit by Dewie on Sunday March 22, 2015 @07:57AM (#9246435)
> Or Asm, for that matter (likely even fewer programmers); at that level, basic concepts like memory addressing and pointers become almost "obvious facts of life".

In my intro-to-java-class, indirection was one of the first things we learnt when we learnt about objects: variables hold a reference to an object, not the object itself. I don't understand why pointers are somehow a great insight that is exclusive to lower-level programmers.

And if a java person ended up trying to make a method that swaps two primitive values, they'd have to learn about the distinction between passing a primitive value into a method as opposed to passing a reference to an object.

Re:Java is Pass-by-Value, Dammit by learc83 on Sunday March 22, 2015 @12:46PM (#9247395)
The problem is that most introductions stick with the primitives are pass by value, objects are pass by reference. Based on that introduction, they'd know you can't swap two primitives, but they'd think that you could swap two objects.

>I don't understand why pointers are somehow a great insight that is exclusive to lower-level programmers.

They're not. You don't need to be a lower level programmer to understand pointers, but it helps immensely if you know at least a bit of a low level language.

When you're getting into details like call-by-reference vs call-by-value, it really helps to have a mental model what the computer is doing. You don't need to be an assembly programmer, but it does help if you spend a little time studying assembly language.

Re:Java is Pass-by-Value, Dammit by tedunangst on Sunday March 22, 2015 @01:53AM (#9245765)
"It works just like Python"
Re:Java is Pass-by-Value, Dammit by ptx on Sunday March 22, 2015 @04:29PM (#9248094)
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.
Re:Java is Pass-by-Value, Dammit by rifung on Sunday March 22, 2015 @02:48AM (#9245894)
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.
Re:Java is Pass-by-Value, Dammit by _ZeD_ on Sunday March 22, 2015 @03:43AM (#9245972)
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