Convincing C programmers to switch to C++: A look at human behavior (2016)

  • A good example of human behavior in TFA as well as the talk it cites is how deeply convinced they are that C++ is objectively always better than C; they don't even try to suggest that there could be a tradeoff and sometimes C would be better. Of course the guy in the talk makes a living from C++ consulting; another part of human behavior is it's hard to convince someone of a truth which threatens their paycheck.

    And I'm not here to argue how terrible C++ is (I've done enough of that elsewhere), but only that "behavioral" arguments cut both ways, and are usually little more than an ad hominem attack and/or some good old marketing tricks rebranded as "behavioral science."

  • If we were discussing two languages Strawberry and Kiwi, and I had a large, established codebase in Strawberry and a bunch of programmers who are experts in Strawberry, it would be a hard sell to get me to switch to Kiwi even if Kiwi were better than Strawberry in every conceivable way and backwards compatible with it to boot:

    - Learning to use a new system effectively takes time and energy. Are you 100% sure that the benefit of the new system is great enough to offset these costs?

    - Hybrid codebases have higher maintenance costs than homogeneous ones. If Kiwi mixes with Strawberry seamlessly, maybe that burden is lower—but the more true that is, the harder it is to believe that moving to Kiwi confers a large advantage.

    In this specific case, I could believe that C++ by seasoned C++ users leads to demonstrable net gains. But it's easier for me to believe that switching to Rust or Haskell would confer higher gains, corresponding to the higher risk and higher cost of switching. So I think it's not that people are irrational about avoiding C++. I think that C++ is in an awkward place on the hill between C and things better than C++. If you need something better, you will go to something with better tradeoffs than C++; if you don't need something better, you just live with your existing C codebase.

  • In a lengthy piece about rational arguments, you would expect somewhere in there someone would actually present a rational argument for switching beyond "it's modern."

    I mean, maybe the actual details of the case for switching are slightly beyond the scope the author intended to write about, but simply starting with an assertion that "modern = better, therefore people should have already switched if they were rational" and treating that as self-evident strikes me as highly arrogant and logically fallacious.

  • > The C++ language is an improved version of the older C language (it’s a superset of C),

    The first statement is arguable and the parenthetical statement is false. C99/C11 have language features that C++ hasn't adopted, which makes it somewhat obnoxious to support C++ from C codebases that use them. One example is the "static" keyword used in array parameters.

  • In C++, "return (x);" isn't equivalent to "return x;" [0].

    But according to OP, it's not C++ that's irrational, it's the programmers who don't want to use C++.

    [0] https://twitter.com/sigfpe/status/857748171778252800 [EDIT: corrected broken link]

  • How to convince them:

    - Show them how classes makes things easier (automatic object management, some operator overloading, etc)

    - Show how the STL makes most things easier (arrays, maps, etc)

    How not to convince them:

    - Show uses of excessive/pathological inheritance

    - Use of templating beyond the basics

    - Insist they use C++ functions for every single thing

    - Insist they OOify every interface in their code

    - Creating giant classes (structs) with a getter and setter for every field with no control or validation

    - Going crazy with operator overloading

  • I do not fully agree with the premise that C programmers don't know what's best for them and need to be educated to switch to C++. I do agree that C++(14++) isolated is a better programming language in many ways compared to C. The problem is that a programming language seldom is used isolated, but is part of a toolchain or is used in an environment with other technologies.

    In this situation, C is a much better choice because most other languages have nice interoperability with C, but seldom, if ever, with C++. For example, as an iOS developer I can use C and C-libraries very easy with Swift, while inter opt with C++ is not possible at all and probably never will.

    The main thing keeping me away from C++ is that it does not have a stable common ABI. This makes it very nearly impossible to use C++ to create and distribute a shared library. I even believe Google developers internally are prohibited from creating C++ libraries for this reason. So I'm sticking with C for low level stuff. It's a perfect glue language and fast. For higher level stuff, why use C++, when you can use Swift, Java, Haskell etc etc?

  • Well, I've tried plain C in one project. The compiler didn't complain when I did some invalid casts, didn't complain when I forgot to return values from functions, provided some warnings against using some undefined functions, but compiled the units anyway (failing on linking stage), I had to write my own implementation of vector (probably buggy and slow), and probably I've forgot to free memory in some situations because C doesn't support smart pointers and automatic cleanup through RAII. Lots of times I felt I'm programming in some dynamic language that doesn't support types, because types are so weak in C. This means that lots of bugs were caught in runtime, not compilation step. Trying to use a hashmap meant I had to pull additional dependencies.

    Disclaimer: I don't love C++, I think it has lots of problems, but saying C++ is wrong, while C is right suggests to me that lots of people didn't take time to actually learn C++ but have strong opinions on it.

  • Scott Meyers points out that one of the simplest possible refactorings is "rename method". To rename f(), you need to know what f() is, and in C++, f() can be any of 7+ different things! [0] It's extremely complicated to determine which thing it is.

    But according to TFA, people who prefer C are just being emotional and irrational.

    [0] Scott Meyers. Things that Matter - DConf2017 [@27:51] (https://youtu.be/RT46MpK39rQ?t=27m51s)

  • “If you’re arguing, you’re losing.”. That is a quick way to stop any discussion. The reason I am not using C++ is because C already does everything I need:

    - Easier to write code generators for: I use libclang to read in annotations that will generate new code according to where the annotations are being used. If I have to take care of every edge case and new features added to the latest C++ standard it would make the code generator more complex.

    - Using plain old data structures: My code generator generates new code to be able to work with the plain old data structures which data can be interleaved or non-interleaved using data-oriented design. Classes will not add that much value.

    - C compilers are easier to write: I integrated the tiny C compiler inside my program to be able to compile C code on demand. The C code can then use the code I've already written.

    - No name mangling by default: I dynamically load a lot of plugins and do not want to bother with binary incompatibilities all the time (if compiled by different compilers like the tiny C compiler for ex.).

    - I mostly use libraries written in C

    - Low-level access

    If I need concepts or meta-programming etc. I can already use Nim or write my own code generator, else I would rather choose something different than C++.

    To be more on-topic. Confirmation bias. On The Internet you can find confirmation of something being true about almost every topic. Whatever people believe is the truth, it will not change the reality. Which programming languages are better is a very difficult thing to measure because there are many factors to consider. Being used to a certain programming language can be a good reason not to change.

    https://en.wikipedia.org/wiki/Confirmation_bias

    Update: added some explanations, and more on-topic

  • People aren't rational actors for a reason: Sometimes things are easy to argue for but aren't that great in practice. And so by following your heart instead of your head, you sometimes make seemingly illogical but objectively better decisions. And I think that there is a case to be made about how C++ is efficient in theory, while C is effective in practice.

  • In the sense that OOP is often used in very stupid ways (dunno about C++ but in other languages, have a look at PHPUnit it is the best example of misunderstood OOP) I can understand C programmers. Golang is also very simple for a reason

  • Talk about the cat calling the kettle black. C++ arrogance and hypocrisy at its finest: Wondering why C programmers can't be reasoned while being impervious to any reasonable argument themselves towards the many modern alternatives to C++.

    Why on earth should a C developer chose C++, when they could chose Go, Rust, Swift and Nim instead? And if you really insist on an old language I'd rather use Objective-C than C++.

    Only reason to ever pick C++ is that you got a sizable existing legacy C++ codebase. That is why I am stuck on C++.

    A C developer by definition doesn't have legacy C++ code to deal with so there is no reason to pick C++.

    Saying C has no benefits over C++ is rather ignorant. Complexity has a real cost. For most of my C++ career that has been reflected in an utter lack of functional tools for manipulating C++ code, e.g. doing refactoring. Refactoring C code is a lot easier, as a regexp search and replace is far more dependable, since there is no function overloading.

  • >* Based on research by Kahan et. al., Saks mentions that otherwise intelligent people will likely misunderstand data if understanding it challenges their preexisting beliefs.*

    While this happens, it's also an empty argument that can be applied to everything.

    How about the author there misunderstands his own data on C++ because it challenges his preexisting beliefs (that C++ is "de facto" better)?

    It goes downhill from there fast, to argue that those pesky people who dare to not want to use C++ are irattional, conditioned from childhood, etc (those willing to use C++ are not, because of course C++ is the only reasonable choice a programmer can ever make between C and C++).

    >In fact, Saks found that quite often logic, facts and the truth were simply not sufficient enough to convince people. Instead, people reacted in a very irrational and emotional way, and kept sticking to and defending their beliefs. People’s basic reaction was “show me all the data you want, C++ is still undesirable.”

    The problem in the paper is that some BS arguments and numerical data in favor of C++ (which I'm assuming they have -- they fail to mention any of them in this article) are conflated for "THE truth".

    Sorry, author, but you are not showing people "THE reality", you're showing them some arguments and some numbers.

    The programmers you are talking to (those that have tried both C and C++) are the ones that have actual empirical experience from actual reality on what C++ gets them -- and whether its worth the tradeoffs they've seen.

    For one, there's an ergonomic factor in language and API design (it's usability) which can be highly subjective -- and syntax/api usability is one of the big reasons people dislike C++. This issue cannot be shot down with any "objective" argument or numbers table....

  • C++ offers too many options for how to do things. C is a nicely restrained subset. The end.

  • Perhaps we need an article called "Convincing people to stop using C++ already."

  • Why do programmers feel the need to convince other programmers to switch to a different language? How does it affect Programmer A, a C++ programmer, whether or not programmer B prefers to use C? I like both C and C++. I also like Objective-C, Ruby, and Python. Each one has its place--and if I'm starting a new project, I'll use the one that makes the most sense to use given the project's requirements--or a mix of them if it's appropriate. If I'm joining a project in-progress, I'm happy to use whatever language has already been chosen. Why get into religious wars?

  • At a cultural level, when you have to convince somebody of something, isnt that generally a bad approach if you want somebody to change their view?

    Though, Keeping thIngs Simply Stupid, is really the only lesson one has to know/learn. When C++ has a specific function go with C++, when C is sufficient use C. If a bash script is sufficient use that.

    If people could just show why something is cool in what situation, instead of why something should be used over something else. And this includes guides 'how to switch desktop OS' too.

  • Already discussed in HN: https://news.ycombinator.com/item?id=12573886

  • This reminds me of Godel's proof - A formal system (axiomatic system) cannot be complete and consistent at the same time!

    Each side of the argument have their own set of premises/axioms to come to certain conclusions but there are always unknown truths which people tend to ignore. if there are no unknown truths then the argument should be contradictory

  • I've noticed that the best way to get programmers to use a different language is to build something they want to use in that language.

    I could talk to my perl programming colleagues for days about the advantages of python over perl, but what got them to switch was boto, since we were moving to aws.

  • The talk starts off with

        “If you’re arguing, you’re losing.” — Mike Thomas
    
    No, no, no.

    A shouting match doesn't help anybody. A civilized exchange of arguments does. And the establishment of evaluation criteria is a very good basis for listening to the other.

    The not-arguing approach often times results in "let me show the merits of my technology without listening to your requirements / evaluation criteria".

    C is different from C++ because it targets different use cases. So it needs to be evaluation in the context of use cases. End of story.

  • But in the table I see, pair-compared, C is faster than C++. Am I interpreting this wrong?

  • I like to think of C# as what C++ should have been.

  • C++ impregnates the tissues, and then it hardens and settles like silt. It makes your aorta stiffer than a hockey stick. Whereas C caresses your insides, leaving nothing behind but its scent

  • > In fact, Saks found that quite often logic, facts and the truth were simply not sufficient enough to convince people. Instead, people reacted in a very irrational and emotional way, and kept sticking to and defending their beliefs.

    You start criticizing people for not believing you when you have one example comparing two different programs implementing an unspecified task on an unspecified compiler. This is ridiculous.

    I mean, for crying out loud, your headlining video is a talk by a person who admits that he hasn't done the thing he's trying to convince people to do.

    He says things like this:

    "You don't want to wait for the market to take care of this, you would like to take some proactive steps to be able to make more of the people who should be using C++ willing to use it."

    in the context of aerospace, which clearly he has no authority to speak on, since he misses one of the fundamental reasons why C++ is not popular or even acceptable in much of aerospace: implicit allocation. Implicit allocation is incredibly dangerous for high assurance systems. You really need to know exactly how much memory can be allocated, when, and what state the exact allocations will put the allocator in. C++ has some facilities to manage this, but man, it is easy to drop a plane from the sky by assuming that your allocation did what you wanted instead of verifying it.

  • C and C++ have a lot of wiggle room when it comes to implementations. I prefer C (when possible) just because there's less surface-area for arbitrary behavior (which is already more than enough arbitraryness).

    I'm writing this mostly as a plug for DJB's proposal for a "boring" C compiler: https://groups.google.com/forum/m/#!msg/boring-crypto/48qa1k...

  • I found some alternative facts!!!! http://benchmarksgame.alioth.debian.org/u64q/c.html