4 ms·
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 wo
by learc83 12y ago
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.
- tedunangst 12y ago"It works just like Python"
- rifung 12y agoI 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.
- _ZeD_ 12y agoStorically, python devs says the python language use "pass-by-name"
- icebraining 12y agoHow 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 http://www.cs.sfu.ca/~cameron/Teaching/383/PassByName.html
- ptx 12y agoExactly. 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.
- userbinator 12y agoOr 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.
- Dewie 12y ago> 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.
- learc83 12y agoThe 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.