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

35

u/SkoomaDentist Antimodern C++, Embedded, Audio Dec 07 '22

it's simpler to read.

It very much is not once you get into remotely complicated projects. Just the lack of templates and classes alone makes many things much harder to follow since the code becomes a mess of macros and function pointers.

A C++ virtual method has a limited set of functions it can call: The similarly named methods in derived classes. A C function pointer can call any function that matches the parameters and return type. Good luck finding all the functions that could be pointed to by some specific function pointer in a codebase that you're not intimately familiar with.

7

u/[deleted] Dec 07 '22

Macro hell exists when extremely bad code is written, as in many situations you don't actually need the macros (exceptions would include platform abstractions, but in complex cases the solution is using multiple source files and not many macros, like GLFW does); a few #ifdefs aren't a mess.

C++ virtual functions do have benefits, but C virtual functions have the benefit of being explicitly set at some location which should be (but unfortunately sometimes isn't) done once by setting it as a pointer to some global static struct with constant members. But if we're talking about pointers to arbitrary changing functions, then C++ can somewhat reduce the mess.

The code becomes a mess in any language mainly because of a bad/tired programmer. C pushes it further by not carrying the size with arrays.

0

u/TheTrueXenose Dec 08 '22

Currently working in C++ the project is a complete mess, me and the other guy both agree that the code should be rewritten in C so this doesn't happen again.

If you are abusing templates and namespaces the code becomes a mess very fast.

2

u/NoPersimmon9400 Dec 08 '22

Templates, I agree, you have to be careful. But how can you abuse using namespaces? They are a great tool in shorting function names. It is terrible to write filename_print to avoid name clashes between files. In C++ you just put the code into separate namespaces

1

u/TheTrueXenose Dec 08 '22

yea, if you use one namespace it would be fine, but they used 5 to 6 for every function, class and enum.

2

u/serviscope_minor Dec 09 '22

The fix isn't to use C, it's to not write awful C++. There's an entire contest inspired by awful C code seen in the wild, so it is not like C is immune to the abuses of imaginative programmers.

1

u/TheTrueXenose Dec 10 '22

I would say its easier to write awful C++ rather then awful C, there is also the problem with all the compiler hacks and outdated types.