4 ms·
I argue with my coworkers often about it. I think the problem is that what Java calls references, works more like C/C++ pointer, rather than C++ reference. The
by skocznymroczny 9y ago
I argue with my coworkers often about it. I think the problem is that what Java calls references, works more like C/C++ pointer, rather than C++ reference. The name similarity but differing behaviour is what's confusing people.
- vbezhenar 9y agoNullPointerException :)
- froh42 9y agoThe exception was named like that before pointers in Java were called references. Urban legend says it was Sun's marketing department demanding Java sounds less dangerous than C/C++.
- michaelcampbell 9y ago> I argue with my coworkers often about it. I fail to see what possible value this has.
- chrisseaton 9y agoMaybe it's significant in their line of work? For example work involving Java semantics, such as language research.
- colanderman 9y agoPeople write incorrect code when they don't understand the semantics. I see this often in Python, especially surrounding its behavior with default parameters.
- alangpierce 9y agoPedantic arguments like this can be a good source of fun as long as everyone approaches it in a lighthearted way and acknowledges that it's pedantic. I could certainly see a conversation around pass-by-value/reference happening in my office, but if it got to the point of people getting angry at each other, that would be a sign that something is very wrong. When actually communicating with people for the purpose of conveying ideas (not just for fun), it's best to avoid terminology where not everyone has the same understanding of the definition. Open discussions about terminology are also a good way to identify these types of ambiguous terms and possibly come up with technical terms that everyone agrees on.
- ohf 9y ago> Java calls references, works more like C/C++ pointer, rather than C++ reference What makes you say this? You can't do pointer arithmetic on Java references, and the internal memory model is completely obscured. C++ and Java references look similar to and are accessed like variables. The major difference is that Java references can be reassigned, like a pointer, which is necessary in a language without true pointers.
- edflsafoiewq 9y agoIn C++, references aren't objects (eg. they have no size and no address), they can't be stored in a vector, there's no way to operate on the reference itself, everything is transparently forwarded to its referent, there is always a referent. In Java, a reference is a value, it can be stored in an ArrayList like a normal value, you can operate on the reference itself (reseating it, comparing two of them, comparing to null), there is not always a referent.
- ohf 9y agoTouche.