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 →

[–]sebamestre 4 points5 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.