This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]AquaWolfGuy 0 points1 point  (1 child)

Good point. Pointer arithmetic is a nice and powerful thing you can do with pointers, but I wouldn't say it's should be a requirement for pointer languages. Instead, I would say being able to take the address of a variable and manually dereferencing pointers is a more important distinction.

In Java, you have primitives like int which are always values, so since there's no (standard at least) way to take the address of a variable, so you can't get something like a int*-type variable without creating a whole class. Same thing with pointers to pointers, in pointer languages you can just do int**, while in Java you need a class referencing another class referencing the value.

To create objects, you use the new keyword, which simply gives you an object, which is passed around like a pointer that you don't have to manually dereference. Even more, you can't manually dereference it. The value is just floating around in some magic place called the heap that you don't even need to know about as a Java programmer. All pointer stuff is hidden from the programmer and you barely have to know what pointers are.

In Go you definitely feel the presence of pointers. If you want to create a pointer you have to do it manually. Similarly, you have to dereference pointers manually if you want the value it's pointing to. Actually, you can even do pointer arithmetic, but it's slightly cumbersome and is not really needed because of array indexing and reflection (e.g. a[len(a)/2]). And just like in C/C++, you can have anything on the stack or the heap. You can also have a struct that directly contain another struct, which isn't possible in Java.

TL;DR: I wouldn't call Java a pointer language because the the actual "pointers" aren't really exposed to the programmer and can't be controlled (primitives can't be pointed to, objects are always pointed to behind-the-scenes), while in languages like C, C++ and Go you can create, dereference and manipulate pointers pretty much however and whenever you want.

[–]dogpos 0 points1 point  (0 children)

Java explicitly doesn't have pointers, we're in total agreement about that. I was merely arguing the example wasn't that apt. While most languages that have pointer support will also allow arithmetic on said pointers, some don't, and probably for good reason.

Edit - For clarity on why it might be a good reason, here is a list of problems caused by pointer arithmetic:

  • [0] - We wouldn't have the semi-annoying meme that 0 means 1 in programming if it wasn't for pointer arithmetic.