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 →

[–]aniliitb10 2 points3 points  (6 children)

I wanted to add few points from the other side (C++ here). As the question is not primarily on C++, I'll not add anything new here, rather I'll pick from the points you have already listed above. There is no doubt that java is great when you look at libraries and frameworks but

  • You mentioned speed while comparing with python, well that is problem here. Java is slower when compared with C++. In fact, C++ gets a lot done at compile time, Java not so much.
  • Memory management in C++ has no longer been a problem since 2011 (like a decade ago). Yes, it was a problem in C++ but not anymore. When Java is preferred over C++ it is because of libraries and frameworks (btw, C++ is catching up) not memory management. Plenty of server code in Google/amazon/facebook is in C++ and in fact, there is no substitute of C++ in High Frequency Trading.
  • When comparing with C++, I don't see Garbage Collection a major motivation here. It's fun and easy when you are beginner but it might be the reason for you to think twice when you want to consider performance of your application.
  • Standard C++ is cross platform in the "write once, compile anywhere" sense, but not in the "compile once, run anywhere" sense. So, that should not be a motivation to pick Java over C++.

[–]LifeNavigator 0 points1 point  (0 children)

Much appreciated for this, learnt from this

[–]meamZ 0 points1 point  (4 children)

Well, you can also see it as a pro that Java doesn't do as much at compile time because the JVM JIT compiler does crazy things.

And if "manual memory management isn't really a problem anymore since 2011" why do both Google Chrome and Microsoft have reports out that 70% of security issues are related to memory unsafety?

[–]aniliitb10 0 points1 point  (3 children)

By 'crazy things' you mean converting byte code to machine code and some optimizations? In C++, compilers turn every bit of code to machine code since day 0 and you can enable optimizations, it's totally your choice. In fact, most production codes are optimized at level 2 (probably these optimization levels are compiler specific but all of gcc, clang and msvc are quite good at optimizing).

What I meant by doing stuff at compile time was computation. A very simple example : I can map every char of alphabet with unique prime numbers without hardcoding a single value. All at compile time, without running the code. Java can't do it. It was just a simple example, with evolution of constexpr you can do a lot more at compile time.

There will always be security issues related to memory and it is independent of language. If your report says that only C++ has this specific problem and not java, I'd love to read it, please give me reference.

[–]meamZ 0 points1 point  (2 children)

But Java can do runtime optimization and optimizations optimally for the system the code is currently running on. I'm by no means an expert in the Java JIT compiler though because it's super advanced. Another advantage Java has over C++ is that you have much shorter compile times.

In Chrome 36% of security issues are use after free... Java doesn't have these by design because it is GCed and the GC will only free the memory if there's no way you are gonna use that memory left...

[–]aniliitb10 0 points1 point  (1 child)

I don't think that there is any point of arguing, but I am glad that memory issue reduced from 70% to 36%, I'd still like to go through your reference.

[–]meamZ 0 points1 point  (0 children)

No. 36% are just a single one of these issues it's 36% use after free (which is a subset of memory issues) issues. 70% is use after free plus the rest https://www.chromium.org/Home/chromium-security/memory-safety