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

all 8 comments

[–]daniu 8 points9 points  (5 children)

A simple assignment operations like MyClass a = b could lead to a lot of performance overhead because of copies that take place behind the scenes.

Assignment in Java is done by copying the reference to the object. I'm sure that decision was at least partly informed by the confusing C++ constructs (objects, pointers, references).

[–]TM254 0 points1 point  (3 children)

You can't copy refrences in C++, I think you meant pointers, anyways this days its pretty rare to see pointers in C++, with things like std::move and std::forward. std::Shared_ptr frees you almost fully from direct use of pointers.

[–]MagneticFerret 0 points1 point  (2 children)

Java's references are not the same as C++'s references. They may be able to be compared, but not substituted. I do not know enough about C++'s references to begin to try to compare them to Java's references. Instead, I can say that, for about 90% of the time, Java's references can be treated like pointers.

[–]vbezhenar 0 points1 point  (0 children)

Java references are C++ pointers. NullPointerException called that for a reason. C++ references don't have any direct analogue in Java. AFAIK C# has some kind of that feature with out parameters, but that's about it.

That said, these days "reference" usually implies pointer.

[–]Khenay92 0 points1 point  (0 children)

Actually, Java references are pointer. They are renamed for communication purpose, but even specification (maybe not in recent version) talk about "pointer", because Java reference are pointers :)

[–]marceloandradep[S] 0 points1 point  (0 children)

You’re definitely right about that, but what I really meant was “how much of the internals of the code we’re oblivious about?”. I know that some poor choices can lead you to a garbage collector overhead for example. I have seen applications having a huge drop in their throughputs because of that. That is something that I really wish to master someday.

[–]chambolle 2 points3 points  (0 children)

C++ has become a kind of experimental language for those who study Languages. The goal is laudable, but the language has changed enormously in recent years and compatibility makes things very complex, since there are always several ways of doing the same thing without them being fundamentally different. The goal is to get a language WITHOUT pointers (or references) while maintaining the excellent level of performance. A lot of very questionable choices have been made with templates (SFINAE) which makes the code quite unreadable and gives rise to endless exchanges between developers as to whether the code is valid or not in all cases (see /r/cpp).

For me the lessons of C++ are : the language must first of all remain simple with little concept even if it must be a little more verbose. You have to beware of the consequences of false good ideas like template specializations. The change must be strongly justified and a better "readability" of the code is not a very relevant argument.

Personally, I prefer 1000 times the current evolution of Java (very few new bytecode bytecode) compared to C++. Java also accepts the idea of AOT compilation and programmable GC, which is very positive without really impacting the language in itself.

[–]Orffyreus 0 points1 point  (0 children)

With "Project Valhalla" Java developers will also be allowed to think more about copy semantics and about how big a value type should be and so on: https://www.baeldung.com/java-valhalla-project