1. 11
  1.  

  2. 14

    Ooh boy. I’ve had too much of a bad experience with C++ recently to be able to read this article without having my stomach turn.

    C++ is a terrible language that needs to be scrapped and rewritten (or replaced with C, because - you know - C actually works). Here are a few of the main issues I’ve had with it over the last few days while completing assignments for my CS class:

    • The STL is crap. There are way to many inconsistencies that you have to remember to be be able to effectively use it, and it’s difficult to determine what type you’re working with (without an IDE). If the type system is so screwed that I can’t write a simple project with Vim, it’s not good enough. Some of it is just asinine too (who the frick though streams were a good idea? Fun fact - you can’t get a file handler from an fstream - so much for a low level systems language)

    • C++ has too many high-level “features”. Yup, I agree with the author. C++ has a cleaner language inside struggling to get out. That language is C. Giving access to high level “features” without proper reflective programming leads to disaster and stupidly difficult debugging. Here are some of the ones that especially get to me:

      • inferred types: it’s a freaking statically typed language - and now you’re trying to get around your type system with autos? I know languages like go infer types too, but it doesn’t bother me as much with go, because the type system is more flat (though, I haven’t written much go). In my experience, C types have never gotten in my way - the only reason the auto keyword got added was because an iterator’s type is frickin' 80 characters.
      • late binding: it’s just a function pointer. Just use the syntax for a function pointer rather than pretending it’s something else and adding more syntax that a programmer has to remember (besides the compiler never knows what’s going on - it doesn’t even know what’s in freaking vtable - at least for g++).
      • C++ tries to hide pointers: just don’t. It trains people not to think about whether something’s been passed by reference or value, and results in too much magic. C++ is a low level language - don’t baby the developer and try to keep the scary pointers away from them (specifically I’m thinking of passing by reference with & and using iterators).
      • I don’t even want to think about what the magic, garbage collected pointers are going to be like when C++14 comes out. shiver
    • I fear C++ may have got itself into a bit of a Perl-esque quandary

      Hmm… I wonder why. Maybe that’s because its syntax has gone so far off the deep end (to the point that it can’t be parsed like a regular language).

    To sum it up, the problem with C++ is that it wants to be a safe, high level language, while at the same time being a fast, unsafe, low level language without powerful enough language constructs to work with. Lisp is the only language that’s pulled off both being very high level and very low level at the same time (and generally, it’s done with safety as well). The only sane way to write C++ code is to write C code.

    1. 5

      You missed the most hysterical streams feature: I/O manipulators. Streams carry state, and updating that state takes a silly amount of code:

      // printf( "%10.4f\n", 1.0f );
      // right align a float with 4dp, also break printing everywhere else in the program
      std::cout << std::setw( 10 ) << std::right << std::fixed << std::setprecision( 4 ) << 1.0f << "\n";
      

      Yeah great feature, like we are all gonna add a wall of setw/setfill/left/god knows what every time we want to print something.

      (wow, while I was looking this up I found this gem)

      1. 2

        Oh sheesh. I forgot about those. I’ll admit that C format strings are a bit cryptic, but i/o manipulators are unreadable (like everything else in C++).

      2. 6

        C++ tries to hide pointers: just don’t. It trains people not to think about whether something’s been passed by reference or value, and results in too much magic. C++ is a low level language

        Amen. I first encountered C++ at Google and I hated it. If the language is presented as a high-level language, it makes no sense.

        It’s more acceptable once you learn C++’s purpose, which is to be a C-like language where you don’t have to create your own string class and hash table. If you use C++ and expect to work at a high-level pace and use it as a high-level language, it’ll make you miserable.

        I’ve definitely met some great C++ programmers who swear by the language, but what I’ve noticed is that they mostly use it as C-plus-a-few-things and avoid the object oriented crap. They’ll use the string class and the STL collections when they suit their purposes, but they avoid friend classes and inheritance and all that nonsense. Of course, being dropped into an existing C++ codebase written by average corporate programmers is a fate that I wouldn’t wish on anyone.

        1. 2

          It’s more acceptable once you learn C++’s purpose, which is to be a C-like language where you don’t have to create your own string class and hash table.

          Statements like that are so common I’m starting to believe most programmers have not yet learnt about concepts such as libraries and code reuse. So for them, it is easier to write or switch to a new programming language than it is to address the lack of certain functionality by employing code that already solves it.

          1. 5

            In C and C++, the lack of a package concept and/or standardized build system makes re-using code a lot tougher than in other languages. That has an effect too.

            1. 3

              C’s lack of templates/generics make things like a generic hash table more difficult than they need to be. Incidentally, “C with templates” is IMO the best way to use C++ :).

              1. 2

                You make a good point. I think the problem is that programming culture, at least in the corporate world, has become so fixated on gluing together off-the-shelf assets, and so averse to the old Unix philosophy of modular small programs, that features get stuffed into frameworks and languages instead of independent libraries. This leads to coupling and bad software in general, and also to the current culture of developer powerlessness and mediocrity in which you hear nonsense like “I’m not sure that Haskell is ready for production”.

          2. 4

            There seems to be a growing awareness about these issues in the C++ community. I was reminded of Dan Saks talk from CppCon 2016 about talking to C programmers about C++:

            https://youtu.be/D7Sd8A6_fYU