Hacker News new | ask | show | jobs
by thom 1267 days ago
I've been getting back into C++ after an extremely long hiatus and I've been impressed by how thoroughly modern it is. The worst crime you're likely to commit these days is accidentally invoking a copy constructor more often than you want to, and even then, not actually creating leaks.

In fact, the most striking thing coming from a language like Java or C# isn't memory management at all, is how utterly non-OO C++ actually is, especially the standard library. I understand how key the zero-cost tenet is in C++, but it's very alien to be picturing an interface and thinking you'd like an Iterable<char> or IEnumerable<char> there, but having to learn about iterators and traits and concepts etc. To be honest, there are equally many functional affordances in C++ as OO ones at this point, but the native core is generic programming, which is very idiosyncratic.

2 comments

Even when C++ was created, object-orientation was not a goal, but rather a means to an end. Yes, that was a significant feature, and the original name was "C with objects", but even then it was only part of the bigger picture, and that part got smaller over time. The next big step away from an OO-orientation of the language (no, that's not a typo) was when the STL was adopted into the standard library - with its iterators and templated mini-algorithms. At that point it could certainly be said already that C++ is a multi-paradigmatic language, and that's become even more true over time.

You could definitely (?) implement a Java-like container framework, with class like Iterable<char> or IEnumerable<char> and almsot every OO bell and whistle - if you wanted to. But it would not be very useful.

C with Classes, not C with Objects, was the original name of what became C++.
> The worst crime you're likely to commit these days is accidentally invoking a copy constructor more often than you want to, and even then, not actually creating leaks.

As much as I like modern C++, use after free is still way too easy to commit. But if you stick to value types and mostly don't store references/non-owning raw pointers, then it's OK.