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

37

u/[deleted] Dec 07 '22

C is still popular for its simplicity.

85

u/Raknarg Dec 07 '22

Simplicity in this case is not an advantage. Assembly is simple too, and it's simpler than C. The simplicity means that it's much harder to do more complicated things, and way easier to make mistakes.

18

u/[deleted] Dec 07 '22

I should clarify what I mean by "simple".

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.

Contrast it to assembly which is all just instructions that not only vary between architectures, but require extra work to understand what happens due to the lack of names and proper types.

From my absolutely subjective experience, I always found it easier to do work on C code bases compared to C++ (you could also claim it's just much easier to make a mess in C++).

1

u/Spartan322 Dec 18 '22

Given operator overloads also can hide behavior and classes can have implicit conversions operators that aren't even guaranteed to call a constructor, (say your conversion returns a static object, why? Hell if I know, but you can) it is quite easy to make C++ a mess if you dive in using every feature you can just because its cool. This is where code standards are a lot more relevant for C++, it has a lot more hands off approach to telling you what you can and can't do, whereas in C its a lot of one note best solutions. Seems lot of languages since force you down a one or maybe a handful of these paradigms that C++ allows. (which is honestly why I love C++ more than almost any other language specifically)

In any case, if you want to consider the need for standards and styles an issue for C++, you could, personally I would suggest it presents a more readable base so long as you don't do weird and stupid things in the implicit functionality. (like don't make operator+ itself produce a side effect and modify the object in a general library, keep such behavior to operator+=) The worst cases I've seen is when nobody standardizes the operator overloads and you have no idea what happens when you call one of them. Like some vector<T> class has operator+ on it and you don't immediately know what that means.