4 ms·
> the only skill difference is manual memory management right? More differences off the top of my head: * Java gets a lot of benefit from having Object as the
by humanrebar 10y ago
> the only skill difference is manual memory management right?
More differences off the top of my head:
* Java gets a lot of benefit from having Object as the base class of nearly everything. It would be a long write-up to explore all the implications, but suffice it to say that the new C++ `any` and `variant` are attempts to get some of the features that Java has been taking for granted for decades.
* C++ is full of Undefined Behavior, which officially can do anything up to and including Launch the Missiles. Undefined behavior can be caused by something as innocuous as using an iterator the wrong way.
* C++ has barely any reflection mechanisms, which sounds like no big deal, but it prevents things that Java programmers take for granted, like high-powered debuggers, standard off-the-shelf database abstraction layers, and dependency injection mechanisms.
* C++ has value semantics, not reference semantics. That means that `SomeObject a = b;` is a copy by default. Sometimes. You can write SomeObject to behave either way. Or in some quirky (probably broken) combination of the two. This seems like a little thing, but it has wide implications in all sorts of design decisions.
* On the plus side, C++ culture includes determinism in cleaning up after yourself. This is related to, but different than, manual memory management. C++ has never needed a `finally` keyword and there's a good case that C++ is better for it. But it does mean that some things are subtly harder, like proper use of exceptions. C++ coders talk about 'exception safe code', a term I don't hear about in Java conversations all that often.
* Java is OOP with some functional stuff mixed in. C++ is typically similar, but the "modern C++" style is increasingly moving toward something... else? Something more like the STL and less like adventures in class taxonomy.
There are a lot more differences than that even, but maybe that will give everyone a flavor for how it's different. It's very different.
- bbatha 10y ago> * Java gets a lot of benefit from having Object as the base class of nearly everything. It would be a long write-up to explore all the implications, but suffice it to say that the new C++ `any` and `variant` are attempts to get some of the features that Java has been taking for granted for decades. Counter point, C++'s templates and preference for value types means that downcasting is rarely needed. `variant` also has no equivalent direct equivalent in Java, because it can only be "downcast" to one of the named variants whereas `Object` can be downcast to any type in the program. > * C++ has barely any reflection mechanisms, which sounds like no big deal, but it prevents things that Java programmers take for granted, like high-powered debuggers, standard off-the-shelf database abstraction layers, and dependency injection mechanisms. C++ prefers to do its metaprogramming at compile time. For instance you can get type safe sql[1]. C++ added features needed to do this kind of work only recently in C++11, and has not had the time or the guidance from the language committee for these types of libraries to gestate. Whereas Java has standardized library interfaces for just about anything. Regarding debugging, C++ has excellent debugging tools. While its true Java can give the debugger more information, C++ gives you more predictable execution (by not having a JIT) which can make debugging easier. [1] https://github.com/rbock/sqlpp11 https://github.com/rbock/sqlpp11
- humanrebar 10y ago> Counter point, ... downcasting is rarely needed. Dunno if that's a counterpoint. I'll agree everything you said there. I was saying Java uses the downcast in a lot of situations that C++ doesn't. And it uses downcast to achieve features that are not there or not as developed in the C++ ecosystem. It looks like C++ is ready to catch up, but these things need to percolate through the library ecosystem over time. > C++ prefers to do its metaprogramming at compile time. Terminology is a little muddled here, but I was talking about both compile time and run time metaprogramming. C++ has little support for either while Java has a pretty robust system for each. Java has things like JMX, JMS, and JDBC Template as standard things while C++ has at best a hodge-podge of things that don't necessarily play nice with each other.