r/cpp • • Dec 07 '22

C++ overtakes Java in language popularity index

https://www.infoworld.com/article/3682141/c-plus-plus-overtakes-java-in-language-popularity-index.html
382 Upvotes

137 comments sorted by

View all comments

Show parent comments

16

u/Raknarg Dec 07 '22

I meant that it's easier to follow and lacks implicit function calls (e.g constructors, function overloading) and data (e.g the extra pointer for virtual functions). It's not simpler to write, but it's simpler to read.

If you don't have any tools. But we're in the year 2022. And I don't agree its simpler to read in general anyways, the abstractions you have available in C++ are much better.

1

u/[deleted] Dec 07 '22

Even with tools, returning objects from a function can be a mess with the constructors which are called, I know it well from some painful experience.

C++ is great, but a stupid or even common mistake can cost a person an entire leg. I'm extra cautious because of that.

6

u/Raknarg Dec 07 '22

Even with tools, returning objects from a function can be a mess with the constructors which are called

Example?

0

u/[deleted] Dec 07 '22

It was quite some time ago using C++14, but I will try to replicate the code's general idea (it was something relating to file IO) from my memory. Also, it's something which copy-elision related optimizations help with, but they're not perfect.

class In
{
  /* complex copy constructor and simple move constructor */
  ...
  In(InOut& other) { ... }
};

class Out
{
  /* complex copy constructor and simple move constructor */
  ...
  In(InOut& other) { ... }
};

class InOut
{
  /* complex copy constructor and simple move constructor */
  operator In() { ... }
  operator Out() { ... }
};

I don't remember all the details, and there were some other objects, but I do remember it took me and some others to fix a bug which happened due to certain constructors being called implicitly. I hate whoever made that class such a mess.

3

u/Etheric2355 Dec 08 '22

You do mention the key problem: whoever thought it was a good idea to make such a mess.

A key aspect of using powerful tools is to remember that just because it is possible to make something does not mean it is a good idea.

→ More replies (0)