5 ms·
Disagree - the distinctions you are talking about (no pointer arithmetic) has much less to do with "pass by value" than the OPs points. Also, at the risk of be
by evrydayhustling 9y ago
Disagree - the distinctions you are talking about (no pointer arithmetic) has much less to do with "pass by value" than the OPs points.
Also, at the risk of being what you are calling pedantic, dereferencing is not the only thing you can do with an object pointer in Java. You can also check nullity, equality, and cast the object. These are substantive actions with semantics that are outside any particular object's implementation.
Really, the only thing i can think of that you can't do with Java pointers that you can with other languages is pointer arithmetic - and that's due to Java's original reason for being: making portable code where object implementations could be isolated from memory allocation inner workings.
- lisper 9y ago> You can also check nullity, equality, and cast the object Fair enough (though checking nullity is just a special case of checking for equality). > the only thing i can think of that you can't do with Java pointers that you can with other languages is pointer arithmetic Well, yeah, but it's not like pointer arithmetic is some obscure little feature that is hardly ever used. Pointer arithmetic is the thing that distinguishes C-like languages from Lisp-like languages. If you're trying to explain a distinction among programming languages that involves pointers you can't just sweep pointer arithmetic under the rug as if it were a trivial detail.
- masklinn 9y ago> Well, yeah, but it's not like pointer arithmetic is some obscure little feature that is hardly ever used. Pointer arithmetic is the thing that distinguishes C-like languages from Lisp-like languages. That's not really convincing given many languages have pointers (as a directly manipulable concept) and actual pass-by-value but no pointer arithmetic unless you call into some sort of unsafe escape hatch. > If you're trying to explain a distinction among programming languages that involves pointers you can't just sweep pointer arithmetic under the rug as if it were a trivial detail. Sure you can.
- danbruc 9y agoThat is why the article is wrong when it says that Java has pointers. It does not, it has references. C#, for example, has pointers and references and they are not the same.
- mbrock 9y agoI wonder if there is any kind of authoritative definition of these words that would apply to Java, C#, C++, and other languages. I suspect not. Compared to C++, Java object variables behave more like pointers.
- danbruc 9y agoReferences are opaque handles for values, you can just deference them and compare them for equality. Pointers are not opaque, their values are address and you can perform arithmetic on them. With that in mind C++ references are pretty much like references in Java or C#. The difference is that C++ additionally does not allow null references and reassignment, but that is more of a statement about the variable holding the reference than about the reference itself. And because reference variables are readonly after initialization it may feel like C++ pointers are closer to Java or C# references than C++ references, and for practical purposes this is certainly true, but with regard to the relevant difference of references being opaque, C++ references are actually closer to Java or C# references than C++ pointers.
- nordsieck 9y ago> References are opaque handles for values, you can just deference them and compare them for equality. Pointers are not opaque, their values are address and you can perform arithmetic on them. What about Go? It claims to have pointers. You can't do arithmetic on them, but you can take the address of a pointer so you can do all the cute double dereference list and tree algorithms.
- danbruc 9y ago
- pjmlp 9y agoPointer arithmetic was already a thing in Algol derived system languages, 10 years before C was invented. Lots of languages have it as feature, C isn't a special snowflake.