r/cpp • • May 27 '20

Why is C++ such a controversial language?

/r/AskProgramming/comments/grmqkc/why_is_c_such_a_controversial_language/
0 Upvotes

40 comments sorted by

24

u/scrumplesplunge May 27 '20

C++ is my go-to language for pretty much any project. I have been using it for personal projects for over 10 years now. I also closely follow the standardisation process and read many of the proposals. I think the main thing that puts people off is the sheer unadulterated complexity of the language. It's an extremely powerful toolset but I think it's basically infeasible for someone to grasp the whole lot without years of concentrated effort. When you combine that with the fact that there are many inconsistencies or acknowledged design mistakes which are kept around for backwards compatibility reasons, it's enough to put off a lot of people.

2

u/NilacTheGrim May 28 '20

I agree with you. It's my go-to most productive language. For very large projects where performance matters I think it's a great choice. I have had to maintain very large codebases in C, in Java, in Python, in Go .. (hell, even in Perl). Hands-down C++ wind in my mind in terms of ability to rewrite and refactor and in terms of productivity for me personally (and performance always is as close to bare-metal as you can get).

It's got a lot of gotchas and I think novices are annoyed by the complexity and it does indeed demand of you as the programmer years of practice and training.

The benefits at the end of that arduous tunnel are immense in my mind. It's a language that has everything now -- even more so since C++11 and especially now with C++20.

I am very excited about the language and I can truly say it's amazingly great.

I wish more people saw it this way -- I think you're right, though, in your assessment about why they do not.

2

u/last_useful_man May 28 '20

I'll be a troll and point out that Java lets codebases grow larger still (at least as far as I understand), but then, maybe Java _requires_ larger codebases ;). This, again only as I understand it, is because of reflection, and how the language makes better tooling possible.

3

u/NilacTheGrim May 29 '20

Reflection is pretty useful for some patterns, I must admit. In C++ we get a little bit of it with extra tools (like Qt's moc).

30

u/adnukator May 27 '20 edited May 27 '20

Torvalds tends to go on rants about whatever he feels like at the moment and some tend to see his statements as some form of ultimate truth. However his fairly recent project Subsurface is written in large part in C++, so apparently it's not that horrible a language. I've seen shit code written in languages other than C++, including his beloved C (mildly fun fact: some of them were C++ haters, using Torvalds' reasoning, without realizing what they were spewing in C), so it's not completely fair to map programmer competency to language quality.

Blow has yet to prove any of his not-so-humble claims (not to mention actually inventing a measuring system of productivity and a unit for it). His words are so far meaningless.

Truth is that C++ before C++11 wasn't that great, but with it and newer standards, it improved in many aspects. However, as with any programming language, it's still just a tool with its pros and cons. Additionally, it's objectively more difficult to set up any slightly non-trivial project in C++ than it is in other languages. You need to find a balance between what you need and how well you can use it. You don't see bakers complaining about how drills work, but with programming languages you see something like this all the time (not only with C++). If I'm fine garbage collection and don't require the compile-time power of C++ or need some GUI layer, I use other languages for what I need, without feeling guilty. And I hate webdesign in general, so you won't see me using Javascript, php and similar languages, yet they are perfectly valid choices for what they are used for.

Also, my experience with teachers is that they are far from being the top notch programmers that some of them think they are - something I've learned after finishing college after I started working full time. Schools aren't too keen on using anything newer than C++03, or even C99 [citation needed]. Therefore, teachers might base their assumptions on the old patterns they or their acquaintances saw ages ago.

23

u/[deleted] May 27 '20

Torvalds wrote that about 20 years ago when C++ was truly awful compared to now.

3

u/NilacTheGrim May 28 '20

Also Torvalds is the type of person to argue a point to death very passionately and to go on rants. I wouldn't take what he says in such moments as anything but cute entertainment. He's a wonderful guy -- but he loves to debate and prove himself right (or at least did, back when I was involved in LKML). I like that about him. This was before reddit and before it became commonplace to do so online.

1

u/Wouter-van-Ooijen Jun 12 '20 edited Jun 30 '20

" Schools aren't too keen on using anything newer than C++03 "

I teach C++17, and I am eager to switch to 20 when gcc becomes easily available for my targets.

-10

u/Astrinus May 27 '20

I think that C++14/17 is the sweet spot.

Seems that C++2(.) is going to prove the Greenspun's 10th rule with all its constexpr. And going linenoise like Perl.

3

u/germandiago May 27 '20

There have been lots of things to abuse for years in C++. Just look at some of the template-heavy libs in Boost. But things have improved.

C++ can be abused but when you do not after you know a bit of advice, the resulting code can be very clean. Use things when you need, not just for fun to make a maintainance nightmare.

27

u/wheypoint Ö May 27 '20

Please stop cross-posting these, it's getting annoying. Every few weeks theres another "why do people dislike c++" post.

C++ has problems, C++ also has a lot going for it. Both have been answered too often already.

Bonus points for every post quoting Torvalds over 20 yo edgy rant about "sub-par programmers", and about a language that's not the same as current C++.

1

u/MINIMAN10001 May 29 '20

Bonus points for every post quoting Torvalds over 20 yo edgy rant about "sub-par programmers", and about a language that's not the same as current C++.

I've figured that by now everyone recognizes the pattern "if something is mainstream, there will be sub par people"

The same complaint is made about subreddits going downhill after becoming a default subreddit

8

u/Jataman606 May 28 '20

My main gripe is not really with the language, but with people refuting any argument against C++ with "but you can write bad code in any language". While true, good language will steer you towards good code (like Rust for example) and bad language won't even warn you when you do something idiotic. And lets be real, everyone has bad days and does some stupid stuff from time to time.

8

u/AlexAlabuzhev May 28 '20

Linus Torvalds said...

Jonathan Blow, a game developer said...

And another man once said "There are only two kinds of languages: the ones people complain about and the ones nobody uses".

2

u/MINIMAN10001 May 29 '20

I feel like he was the wisest of them all.

Everyone wants x but with y.

Few people want to go through the committee and see it through.

But no one talks about z because no one cares.

15

u/wyrn May 27 '20

Jonathan Blow has had this to say about C++:

This is not a case of me saying “People using RAII are doing a totally great job in their domain, but that is different from my domain”.

I think people using RAII are doing a bad job in most domains. They are not being good programmers. (...) A lot of code that ships today is soft-real-time code. For example, every app that runs on a phone. But then, you go and try to use Android and it is bloated and horrible, yet the hardware it’s running on is a very very fast computer compared to what I had to work with in the year 2000 early in my game-making career. What is wrong here? Pretty clearly something is horribly wrong.

I don’t see that you can seriously claim that people are successfully building software using RAII. Phones are horrible and slow. The Web is horrible and slow and buggy and barely works. etc, etc. You can only make these claims if you have very low standards for working software.

In reality, RAII (especially when combined with some other things like exceptions) bloats your code and makes it much harder to understand, which exacerbates all of the in-real-life performance problems listed above.

See also Matt Newport's response to some comments made by Blow in video form. I like this slide in particular. I'm pretty comfortable ignoring this kind of criticism, to be honest. I think most of the actually valid, worthwhile, useful criticism of C++ comes from the C++ community, which makes perfect sense: it really is a complicated language and you need to understand what you're criticizing in order to make a meaningful contribution. In contrast, most of the wholesale rejection of C++ seems to be like the above.

12

u/guepier Bioinformatican May 28 '20

I knew Jon disliked RAII but somehow I missed that he tied it to mobile phone performance, which is hilarious. The major reason why Android is historically so much slower than the iPhone, despite much beefier hardware in many cases, is precisely that Android apps by default use a GC, and Apple apps use (A)RC. I.e. a form of RAII. (scroll down to “ARC is not a garbage collector”).

I must be missing something because I seriously doubt that Jon Blow could have it so backwards.

13

u/NilacTheGrim May 28 '20

Dafuq. Who in their right minds can complain about RAII?! LOL. It's the single most useful thing since sliced bread. Languages that lack it feel so bare...

I do not get it.

8

u/JankoDedic May 27 '20

Its domain imposes a lot of constraints, much more than for other languages. It has to have high performance, lightweight abstraction and backwards compatibility.

Some people don't like it because it's harder than other languages, and some people don't like it because they don't like systems programming (pointers, memory management, other low-level things).

5

u/CoffeeTableEspresso May 27 '20

I agree with most of this, but the domain isn't the thing forcing backwards compatibility.

5

u/JankoDedic May 27 '20

Perhaps "the domain" isn't the most accurate term, but the ecosystem certainly does force backwards compatibility.

5

u/ShillingAintEZ May 27 '20

Both of those people formed a very solidified opinion before modern C++. Jonathan Blow is sharp, but he is too jaded to invest in learning the good parts of C++. His language design seems cool, but if it has no concept of ownership it will be a huge black mark that will remain a problem.

7

u/[deleted] May 27 '20

It's big, complicated, contains tons of historical baggage, lags behind languages like Rust in the areas of build systems and package management, and yes, there is a lot of poor C++ code in the world. All C++ hate can be attributed to a combination of these factors IME.

1

u/germandiago May 27 '20 edited May 28 '20

Yet you have successful environments. I have used CLion + Meson and some Conan and hey, it is not Java or C# but it is much closer than it used to be when paired with C++17. Still a long way to go though.

4

u/[deleted] May 28 '20

C++ with CLion is so nice right now. I can't go back to straight vim, but honestly I think the experience is better then anything I get with Rust

2

u/NilacTheGrim May 28 '20

Linus Torvalds has said many controversial things. He likes to argue in an opinionated fashion. I wouldn't take his assessment of the language too seriously.

2

u/MINIMAN10001 May 29 '20

The most important thing about any argument is data. Without data it's merely a jaded man's rant.

Nothing wrong with ranting but it provides no merit for or against a language.

2

u/die_liebe May 29 '20

> Jonathan Blow, a game developer said "C++ is a weird mess. My new language would increase productivity 50 to 80%

I would be interested in learning more about this magical language.

2

u/divbyinf May 27 '20 edited May 28 '20

EDIT: Downvotes are to be expected, but why not say why I'm wrong? I'd love to change my mind or know what I could do better.

This is maybe a bit of rant, but I have to use C++ in a relatively large codebase, and while C++ as language has its major issues, I'd say my real gripe is with the tooling. This becomes inseparable if it starts to dictate how I use the language. Some of all the new features are great and everything, but personally I could live without many of them.

I'm sure others will disagree, but for me that's the real issue in my daily work with it. The tooling doesn't seem to be adapting very well to the changes in the language at all. For reasons beyond my control, I predominantly use the latest Visual Studio and a few basic extensions such as VAX.

It's nice that we've had auto for so many years now, and spiffy for-loops so I don't need to go through the exercise of writing iterator types out by hand anymore, but why is it that tools like IntelliSense/VAX still have trouble to properly deduce so many things, or it's done with so much delay or the wrongly focused completion list item, that it's rather useless for me. Was IntelliCode supposed to make things better? Maybe all of this is better than nothing, but often just barely. Un-autoing code should be an automatic refactoring option (the compiler knows the type for sure at some point).

Plus it seems like many namespaces are still impossible for the tools to properly understand. If there's a function with the same name in the global namespace or some other random namespace in a project, then jumping to that function apparently can have priority over a function of the same name in the same namespace and same project. Go figure.

Why does singlestepping through a breakpoint take so long now. Why can't I set a single trivial conditional breakpoint without DoS'ing the program half the time.

I could go on, but it all adds up to a rather unpleasant experience compared to using other languages that the tools just seem to properly grok.

Maybe some of these issues are inherent to the language itself. I'm sure there are many large codebases out there that are a pleasure to work in, or maybe it sticks to all std:: and the tools just understand it. But otherwise I'd really like to know how the OOB settings are smoothly working for them.

End of rant.

1

u/lozz08 May 28 '20

It tries to bring together so many ideals at once.

0

u/Jimmaplesong May 27 '20

It’s a great language, but there are many ways of doing things... if you have some image data and want to run it through three libraries, you’ve got to be ready to create adaptors to transform the data and handle memory differently going between any two. The ITK and VTK are the most painful example from distant memory. One needs you to handle memory, and the other wants to handle its own memory.

It can take days to do something that can be done in Python in hours. But... it is one of the best ways to extend Python. Rust is probably the shiny modern alternative that addresses these things, as well as memory issues that plague C++

8

u/[deleted] May 28 '20

For all the love Python gets... it kind of really, really sucks. I'm honestly more productive with Java then Python; the tooling is better, unit testing is easier, the coding conventions actively prevent you from writing bugs while Python doesn't care, and the code is about 100x faster and actually has real multi-threading.

And, for all the love Rust gets, I'm someone who learned Rust first and then went to C++ and C++ is IMO a better language. Things like tooling, online resources, and maturity matter a lot more then slick features.

4

u/target-san May 28 '20

Things like tooling, online resources, and maturity matter a lot more then slick features.

Please note though that C++ has 2-3 orders (if not more) more resources invested into it. IMO Rust is going very, very well if resource investment is taken into account.

4

u/CletusDSpuckler May 27 '20

We use Python when we want to code it fast.

We use C++ when we want it to actually RUN fast.

2

u/germandiago May 28 '20

I think you can code C++ fast also. The problem is the compilation step and dependency gathering (every day less, fortunately, thanks to Conan and Meson wraps in my case). You can already do (for your scripting-like stuff):

auto myFunc(auto a, auto b, auto c) {
     ...
    return blabla;
}

If you want, later you can add typing or concepts:

std::floating_point myFunc(auto std::integral a, auto std::integral b, auto std::signed_integral c) {

}

On the other hand, in Python you can use typing + mypy, but that adds a "compilation step" also.

6

u/ShillingAintEZ May 27 '20

If python does that automatically it just means someone has done it for you. That has nothing to do with the language. Also image libraries that don't take buffers to pixels with width, height and channel arguments have created their own problems. That too is not a problem of the language.

2

u/rtomek May 29 '20

That's quite an extreme example, and also using one library to represent the entire language, especially if it was years ago. ITK and VTK don't necessarily have the greatest APIs, but more due to being fairly old and Kitware has definitely put in some effort into modernizing the code. There's a mixture of old-style C programming practices and more modern practices sprinkled throughout that code base. I normally try to get in and get out as quickly as possible when interfacing with those libraries, I couldn't imagine the nightmare of building software on top of those libraries.

I guess example does have one good point though, some libraries make you manage your own memory and some manage it for you. With the other languages you mention it forces one way of doing things rather than having the freedom of choice. At least with modern C++ I can use std::unique_ptr::get() or std::unique_ptr::release() at the interfaces to keep things simpler on my end, you just have to know the correct time to use each one.

-10

u/SpliterCbb May 27 '20

I work in C++ and have worked in it for decades now and here's my opinion:
I agree with Blow more so than Linus.

The issue I have with C++ and with the new versions is that they're encouraging the move away from simple, clean code, and instead encourages weird abstractions that are hard to read through (OOP is a big culprit, but auto, bracket constructors and constexpr don't help).

Most of the issues come from the syntax tho, C++ is this weird malformed kid of C and OOP where they tried to keep it backwards compatible with C, and as such they had to make a lot of syntax workarounds that didn't make sense (Lambdas are the syntax hellspawn of C++11 trying to be compatible with C++03).

An example on how to do syntax right, look at Java: Java was designed from ground up to look like C but be a completely OOP language and they have much less awkwardness. When you override a function you specify it, and it has to override it, if an override hides a function you get errors, no multiple inheritance. (Only reason people use C++ over java is essentially the performance, Java has way too much security built into it and no control over memory).

The second thing that C++ did horribly (again, because it was trying to be backwards compatible) was the templates. Templates are useful but they're really badly implemented since you require the entire code to be present in the file where you want to use it, so you need to include the entire header, but then there's templates of templates of templates, and you change one thing and have to re-compile the entire project.

The reason I agree with Blow more is he sees the potential on how C++ could have been much better: Objects of Arrays, named overrides in functions, compile-time type information, having proper compile-time code execution in the same language (that thing on its own would double the producticity), serialization, better enums, build parameters specified in the code itself.

I have no doubt he's not overestimating the 80% productivity improvement thing, in C++ on huge project wes deal with so much superfluous crap that any one of these features would be a big boost.

8

u/germandiago May 27 '20

What you say is not accurate. The reason why you need templates in headers is because they generate code. And that code must be inlineable if you want to make it fast. At the time templates were added, link-time optimization was not there yet.

As for modern C++, not sure yet whatthe balance is. But keep it simple and do a for loop with a transformstion. But now you use std::transform and use a policy for parallel and ta-da! I best hands down the performance of your simple code. Said in another way: there are tradeoffs.

1

u/SpliterCbb May 28 '20

Most classes don't require code to be inlineable tho. You can create the member declaration in the header and the definition in the cpp. Templates could have done the exact same thing if C++ wasn't trying to be backwards compatible and instead went with modules for code. So the header would still have the class and member definition, but the declaration of big functions where inlining doesn't add performance could still live in the cpp equivalent.

The reason they didn't do it was because C uses headers/includes as simple text copy, rather than it being a reference. If they went with modules they would've broken backwards compatibility, so they had to either make sure that all of the template code was included in the header, or add another source file type specific to templates, they went with the first option.