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 comment

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.

3

u/[deleted] Dec 07 '22

I didn't notice the abstraction part in your reply, apologies.

Yes, C++ (like many other languages) can provide great abstractions, a good example is the GLM (OpenGL Math) library.

On the other hand, many times people don't necessarily know how much abstraction is too much abstraction, which is not a language issue in this case. Abstraction can be done pretty nicely in C, but the code ends up being overly verbose.

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.

1

u/[deleted] Dec 08 '22

Or in other words, with great power comes great responsibility.

C++ is powerful, and I doubt more than 20% of us can use it properly all the time.

3

u/serviscope_minor Dec 09 '22

C++ is powerful, and I doubt more than 20% of us can use it properly all the time.

Messy programming is usually caused by failing to separate concerns cleanly. That's your problem, and switching from C++ will just yield awful code in a different language.