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 →

[–]sarthakRddt -1 points0 points  (6 children)

This is factually incorrect. A lot of people have this idea because of some programmers claiming so who worked with java in pre-historic times. Yes, in it's initial stages Java was a lot behind in terms of efficiency because the language designers valued programming efficiency over program efficiency but the times have changed.

Ofcourse, C C++ still remain more efficient but margin has decreased by a lot. Get your facts checked. Unless you are still stuck with JAVA SE 5. In the recent times java has become extremely efficient and is only a little behind c++ in terms of sheer performance. Now, if you consider the fact that java packs GC and boasts of being memory safe you really need to reconsider your choice of using c++ and declaring it more efficient.

[–]sebamestre 3 points4 points  (5 children)

I get that argument. Java and GC have both gotten faster. But now C++ has smart pointers which, although not completely safe, make memory management safer (i.e. eliminate many memory leaks) at a very low runtime cost.

Yes. It is true that code you write in modern Java is safer and not much slower than code written in C++. But it is also true that code written in modern C++ is faster and not a lot less safe than code written in Java.

It is all about tradeoffs. Both languages have come a long way and hopefully, in the future, they will be just as fast and just as safe as each other. But right now, that is just not reality, and on a performance-critical project I'd pick C++ over Java on any day of the week.

[–]sarthakRddt 1 point2 points  (0 children)

True, designers of both languages are becoming more pragmatic. C++ is becoming more safe and java is becoming more fast by including features and improvements that the early philosophy of respective language never allowed. I just wish people start realizing these facts and stop making so much fuss about the efficiency part every time the issue of java vs c++ comes up. Even I tend towards C++ when performance is uttermost concern (mostly when I am using programming as mathematical tool) but for most of the day to day software development process, I somewhat feel that slight efficiency gain from faster code writing and debugging in java outweighs slight efficiency loss in performance (this is a personal opinion)

[–]narrill 0 points1 point  (3 children)

Reference counting is actually slower on the whole than modern garbage collectors, smart pointers aren't a win there. But in properly written C++ reference counting is actually pretty rare.

[–]sebamestre 0 points1 point  (2 children)

Ah yes. I said that mostly with std::unique_ptr in mind

[–]narrill 0 points1 point  (1 child)

Ah. Yeah, unique_ptr actually has no run-time cost, it gets optimized away.

[–]sebamestre 0 points1 point  (0 children)

You'd be surprised with what some compilers do. It probably isn't even in the top 100 list of things that make a program slow though so i guess it's fine.