5 ms·
In most of today "real world" languages you can't use pointers.
by yetihehe 10y ago
In most of today "real world" languages you can't use pointers.
- vbezhenar 10y agoIf you can get NullPointerException, then you are using pointers. May be you meant that you can't use pointer arithmetic, but pointers are used almost everywhere.
- yetihehe 10y agoIf you can't use pointer arithmetic, you don't use pointers. Your language uses them internally, but not you. NullPointerException in Java/C# is a result of a leaky abstraction.
- bluejekyll 10y agoYeah, they could just as easily have made it a NullException and not lost any meaning. Or better yeah, they could have made a null safe language ;)
- vbezhenar 10y ago> If you can't use pointer arithmetic, you don't use pointers. Is it someone's definition of pointer? > Your language uses them internally, but not you. I'm actively using pointers that point to object. > NullPointerException in Java/C# is a result of a leaky abstraction. I don't agree. Java has uses pointers (which also called references and those are synonyms for Java), Java has concept of null pointer and I don't see why NullPointerException is leaky abstraction.
- yetihehe 10y agoIt is wikipedia[1] definition of pointer. > In computer science, a pointer is a programming language object, whose value refers to (or "points to") another value stored elsewhere in the computer memory using its memory address. > [2] Pointers are the most primitive. Due to their intimate relationship with the underlying hardware, they are one of the most powerful and efficient types of references. Pointer "points to memory", so if you change value of a pointer, you change what memory it points to. In java you can't change what a pointer points to. It's only references. > I'm actively using pointers that point to object. No, you passively use references that point to object. You can't do *(ptr+1) in java. Leaky abstraction means that it's called a pointer but it isn't a real pointer. Also as another commenter said, in C# it's properly called a reference. [1] https://en.wikipedia.org/wiki/Pointer_(computer_programming) https://en.wikipedia.org/wiki/Pointer_(computer_programming) [2] https://en.wikipedia.org/wiki/Reference_(computer_science)#Examples https://en.wikipedia.org/wiki/Reference_(computer_science)#E...
- vbezhenar 10y agoOf course you can change the value of pointer in Java, just assign any other address. Even if I can't do pointer arithmetic in Java, they are still pointers, just without pointer arithmetic.
- kleiba 10y agoBut in those cases you would hardly expect a Stackoverflow question tagged with "pointers".
- Sean1708 10y agoMost by number possibly, rather than by market share.
- olavk 10y agoThat is just a name, decided before Java settled on a consistent terminology. In C# it is NullReferenceException. We get into nitpicking, but I would argue references and pointers are not the same. Pointer are by definition memory addresses, while references are opaque and could be addresses under the hood. Note also that C# does have pointers, but they are separate from references.
- vbezhenar 10y agoWell, memory address is a memory address and pointer is a pointer. You can have virtual function pointer in C++, which is much more than just a memory address, it's a complex value, yet it's called a function pointer. If you're using that definition then yes, but I don't think that everyone uses it. For me pointer is an entity which points to some value, the key is an indirection, not an implementation. I think, that even C++ would allow compiler to implement pointers as something opaque (e.g. for safety).