4 ms·
> 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
by 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 agoI never used Go in any meaningful way so I just had to look at the documentation. I lean towards classifying it as references instead of pointers despite the name. References to references are perfectly valid even though they are not available in all languages with references. On the other hand Go exposes an implementation detail, the fact that references are implemented as addresses. This is probably true for most languages with references but they usually keep this an implementation detail so that it would be perfectly valid to implement references with something other then addresses. But because you can not really take advantage of the fact that references are implemented using addresses, you can not manipulate them and it seems you can not even calculate the difference between two pointers unless you go through unsafe, I would call it references [with slightly but inconsequentially exposed implementation]. As said, this is based on a ten minute read through the first couple of search results and I probably have not even hit any official documentation, so this might very well miss something important and be wrong.
- 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.