The day I gave up on C++

C++[This is an article written in 2013. Things have changed, not a lot, but they have. Every time someone discovers this post via reddit I feel like taking it down – it’s not particularly good, it was written when I was quite upset with my lack of ability to become productive in C++. I will not bother you with the updated view, and I will keep the article because people seem to stumble into it every now and then, probably because they are equally frustrated and, like me, they didn’t know how to express it. I am tempted to do a rewrite of this, though (and I have)]. I wanted to mark this somehow, in my calendar or something. I always liked C++ as language, it was nice to build so many nice things with it. I learned C++ when I was in 11th grade, and I kept learning for years. Probably everything that I know about design and design patterns I pass through the C++ filter. I map all the things I learn in all other languages through C++, and understand them better. I must confess, I always loved C++ like that.

But, C++, this relationship doesn’t work anymore. It’s no longer love, and before we split I want to tell everyone why:  You’re ugly. You wanted to be a splendid girl, and borrowed the flexibility of your older sister, C. You just wanted to do too many things. You grew up among bearded fellows that made you do all the wrong things, like your sister used to do. But it didn’t work out that well for you. And I was younger, didn’t know better, and I fell in love. But the thrill is gone, now.

A famously quoted joke is the following: what is the 11 in the C++11? It’s the number of feet they glued to C++ trying to obtain a better octopus. Of course, it didn’t work.

And I must confess, C++11 looks tempting. If you write your code from scratch, C++11 might be an option. But when I say from scratch, I really say from scratch. Write your own libraries for everything. And for Christ’s sake, replace completely the STL! Boost? Don’t make me laugh. Boost is a Vernian, submarine sized octopus that is out there to kill you.

Let’s take my reasons one at a time:

C++ IDEs suck. Big time. I tried about 10 IDEs in the last two months. They all suck big time. Not only do they suck, but they are counterproductive: Visual Studio the absolute best IDE when it comes to C#, wants to make a point from actually sucking in an equal quantity for C++. Eclipse made me cry, netbeans sucks, kdevelop sucks, code::blocks sucks, codelite sucks, monodevelop sucks and whatever you might suggest that is the next best thing in IDE sucks too. Trust me. Now, I know, this is not the language’s fault. But you’d expect that after all these years of experience, of needs for C++ support in IDEs, you’d see some improvement. No, the IDEs become proud in sucking more each year in their C++ support (of course, Eclipse does that for all the languages, but that’s a different story).

It’s an unmanageable language. You have header files split from source code. Why? Because in the 70s and 80s it was difficult to have proper metadata in object files. For C, it makes sense: it makes writing a compiler a lot simpler, if you don’t count the number of people that killed themselves after writing the preprocessor of C. But we understand C. C is cool. C is simple. C is meant for other stuff. But in C++, header files are the rope that you hang yourself with. You don’t want to include the same header file two times, so you use, what? Header guards? #pragma once? All these are error prone (#pragma once for not being supported by all the compilers). So what do you do?

It’s a barely portable language. If you want to write things portable you have to #ifdef stuff. This, of course, makes your source code ugly. Right now, C++ is less portable than Java or C#, that really have this ‘write once, run everywhere’ thing.

It’s a counterproductive language. The real reason for me being so upset with the language is the fact that the language constantly gets in the way of my project. I started working on my own game ladder, and wanted to start with PONG. Easy, right? Wrong. It’s almost impossible to understand how you keep in standard containers objects created by some libraries. And when the standard library is the obstacle, it’s definitely an issue.

Talking about STL, STL sucks. I know, it’s the fastest and sharpest knife in the kitchen. But it sucks. It sucks because it is so intrusive in your code, because you never know if you should create containers on the heap or not, it sucks for the uninspired names and for the unstructured approach to the containers. You don’t have an ‘Add’ function, instead STL has a push_back, but not for all containers. No, for stacks you’ll have a ‘push’. ‘Remove’ is called ‘erase’, and the ‘remove’ you see there is not what you expect: you have to use erase with the result of remove. You don’t have a unified interface for containers, and you can’t simply say: I want something that I can enumerate, which is what you want most of the times.

The focus on performance actually makes STL impracticable. STL is optimized for the compiler, and it’s counterintuitive. And some smart-asses will say: use boost instead. Boost is smart. No, sorry. BOOST SUCKS. Boost is the ugliest piece of software ever created. It’s useful, but ugly. And no person alive could ever cover all of Boost libraries. Why would they? Ah, they have to, because IDEs will never ever ever help you with that.

And let me mention the namespace stupidity. Because STL is so bad, boost and others create their own containers. The best toolkit to use with C++ is by far Qt because they rewrote everything from scratch. But the problem is that you will have constantly nameclashes. So, I C++, it’s bad manners to use the ‘using namespace X’, especially in the headers. Which makes quite common definitions like:

std::list<std::shared_ptr<sf::Drawable>> x;

Call me when you get what I have there. Compare this with List<Drawable>, and let me know which is better.

The language sucks. It sucks because it’s so complicated. C++11 managed to complicate it even more, and now you often wonder how many ampersands you have to place in your constructor? STL is unusable, is counterproductive and makes your programs unreadable.

Any beginner will be crushed by the statements C++ programmer have to write. So from now on, I will recommend to any beginner to jump from C to C# or Java. It makes much more sense, really, do it.

And I say this with great regret in my heart. I always loved you, C++, as ugly as you were. But now the thrill is gone: you became unusable and counterproductive, and I really have no time to write proper containers in 2013.


73 Replies to “The day I gave up on C++”

  1. Vlad

    One of the reasons IDEs suck is that the language is complex. It’s incredibly difficult to do something like Intellisense in a language like C++ (much easier to do it for java or c#).

  2. Dorin

    Correct, but we’re not talking about two years, we’re talking about 20 years of IDE development. Microsoft constantly made theirs worse, and the rest seem to follow this trend as well.

  3. Vlad

    Oh ok! Do you find VS 2012 worse than VS 2010? Just wondering if I shouldn’t upgrade then.

  4. Dorin

    Since I did my tests with 2012 and became this upset…
    2012 is a good IDE, but not for C++. Can’t compare with 10, since I didn’t use it for that

  5. Mithrandir

    I recommend looking at Haskell. It will blow your mind from the start but each time you’ll code in it you will fall more and more in love with the language.

    And you won’t even need IDEs. A simple Vim editor will be just enough.

  6. Dorin Lazăr

    I’m thinking about that too. But now I’m a bit disappointed, and I’ll take a break from these things, hoping to find a warmer spot in writing. But I will definitely investigate Haskell too, I’m quite drawn to the functional programming paradigm.

  7. Roxana

    Code becomes complex.
    Instead of one’s computer,
    Choice words get scattered.

    Writing turns awful.
    Instead of desperation,
    A switch to coding.

    The wise strategy
    Instead of stability
    Becomes flexible.

    This is not the Tao. But it is close enough.

  8. Cipri

    I know that you are an anti Apple type of guy, but if you find some time take a look at Objective C. I started to like it even if I still love Java 🙂

  9. Dorin Lazăr

    I will not invest a single cent in the platform of Apple 🙂 It took me a while to be ok with Microsoft; really, don’t get me started on Apple’s platform.

    If you want to check out a wonderful language, C# is the one. 😉 and maybe Haskell 😛

  10. Cipri

    I was there, I know. You know me, I am a Java guy, I use to have the second android Phone On the market. But, ar least you should give it a try. It is something else, It was the big surprise for me, a pleasant one…

  11. Timotei

    Did you try the “Visual Assist X” plugin? It’s awesome. At least for me it really made a difference when using C++ in my projects. It’s “almost” like ReSharper. True, it’s still a plugin and not an IDE, but it’s an option.

    PS: Also, you could try Qt Creator, last time I used it it could make non-Qt C++ programs too.

  12. Dorin Lazăr

    @Timotei: didn’t try visual assist X but, on the other hand, I don’t have the full Visual Studio (I only use the Express version, I don’t want to pay hundreds of dollars on the IDE that I’m not sure I’ll want to use). It does sound promising. Still, it’s the language that is the culprit.

    The same goes for QtCreator. QtCreator was nice, it was the good part of Visual Studio 6, improved, so I liked it. But still, it doesn’t help me much, because in the end projects built with it are kind of ugly, and the project management part is not as good.

    And for crying out loud, there’s no good cross platform compiler to support all C++11. Don’t get me started on MinGW and how much it sucks, and cygwin, which are trying to be the oldest piece of software alive, and the fact that VC++ 11 doesn’t even have initializer lists. Seriously?

  13. yyyy

    c++ is complex because it support multi-paradigms, each paradigm have its own merits and defects.I like multi-paradigms philosophy in c++ because I don’t have to “reinvent” the wheel when I need them.When I use other language without template like c++, I have to “mimic” template in c++, because they do not support generic programming, template help me reduce codes when I develop algorithms.

    c++ is complex, but we don’t need to learn all of it, ch1~ch16 of c++ primer 5 are more than enough for most of the tasks.

    c is too low level, c#, java are not fast enough for foundation softwares(libraries), and they are own by specific company.Whether you like it or not, c++ is irreplaceable.

    >And no person alive could ever cover all of Boost libraries
    nobody could ever cover all of java, c#, python libraries too, but why should we?just pick the one you need.

    >Talking about STL, STL sucks
    stl is not perfect but still cool and easy to use, efficient, and flexible(generic).”push_back” or “add” is not a big deal, the names is impossible to fit the flavor of every programmers.Atleast I like “push_back” more than “add”, I can know the data “push” to the
    back of the containers but not “add” into “every possible positions”.”insert” the data at front, back or other position are crucial for the performance to some containers(vector, queue)

    About the remove, it is a reasonable design choice for a generic algorithms, the algorithms is impossible to know how to “erase” the data of “unknown” containers.The containers could be everything.

    >std::list<std::shared_ptr> x;
    most of the times we would declare something like “std::vector x;”
    It is a rare case to declare something like std::list<std::shared_ptr>.
    Besides, you could use
    “using DrawList = std::list<std::shared_ptr>;” to save some typing

  14. Dorin Lazăr

    I agree with your points, however, the problem is that we always have to give in to one or another style that we dislike. So if, for example, I don’t want to use pointers, only copies of objects, then it’s impossible to do it if one or another library requires pointers. There’s no unified model; a unified model would help especially library implementers, to make them work together well. If you want an example of this: should I have std::list ? should it be std::list ? Should it be std::list> ? Will QWidget be destroyed at the correct time, or will it cause my application to crash on exit? And now the most important question: WHY do I have to ask myself about all these things?

    That makes developers hesitant until they develop a style, then acrimonious when relating to other styles. How will that developer work in my team?

    And remember, it’s not about saving some typing. It’s about understanding what that thing is. That’s what types are for.

    PS: lists are ideal when your allocation is O(1).

  15. yyyy

    >It’s a barely portable language
    just use the right libraries for your need, like Qt.It is hard to argue whether c++, java or c# are more portable, it is all depends on your requirements.My android apps developed by java can’t work on windows, mac, ios and linux, but most of my c++ codes could works on the platforms I mentioned above, only a little bit alternation on the codes(#define).

  16. yyyy

    About the problem of “should it be std::list” or not, it don’t looks like a problem of c++, but a problem of data structures, it is a fundamental problems every programmers should learn from the schools or books.If they don’t, teach them or fire them.There are not “unify” containers for every jobs, and no “unify” paradigm fit for every tasks.It is a big loss to restrict the power of the programmers by making the langauge with a “unify” paradigm.

    pointer is good to access the data but not resource management, just wrapped it by smart pointer if you want to make sure the resource could be release.

    And the resource management, to tell you the true, I like the way of “RAII” more than the manage language.

    1 : I know the life times of the resource
    2 : I can guard every resource by RAII, not just memory(mutex, file and so on)

    After you grasp the idea of RAII(it is simple), resource management in c++ is like a piece of the cake.

  17. yyyy

    yeah, I don’t like macro too, but this is the best way in c++, I have to bear with the merits and defects of every language when I use them.No perfect language in the world.

  18. yyyy

    Forgot to say, std::list are very inefficient(low cache hit), especially when c++11 support rvalue reference.It is only suitable when there are many(the number is depends on machine and compiler) data which need random insert.

  19. Craig

    Microsoft are a dying behemoth. There’s absolutely no future whatsoever in Windows as a platform. End of story.

  20. Dorin Lazăr

    I like the fact that we’re not disagreeing here. Although I think that some sort of unification would be quite helpful, maybe for a higher level data structure. I really do appreciate the flexibility of IEnumerable.

  21. Chris

    The main problem with C++ has always been its complexity. Some people see the multi paradigm approach as a strength but I think that a language that tries to do everything in the end not is good for anything. Sure, C++ 11 has simplified a lot but on the other hand: here comes yet another way of writing code in C++. Using a subset of the language could be a solution but people never seem to favor the same subset and without strict coding rules (and reviews) the code base will quickly degenerate to an unreadable mess of different styles. As the author I really do not see any domain where you would use C++ these days.

  22. Mike

    Any language with header files sucks. I’ve spent too many precious hours of my life chasing circular includes and putting forward class declarations in header files and I’ll never get them back. What a precious waste of life.

  23. Timotei

    Sorry, but when you’ve got circular references, that probably means your design is broken 🙂 So the header files “sucks” actually warns you that “you’re doing it wrong”.

  24. VanillaFace

    “C++ IDEs suck.” – Couldn’t agree more. There’s no decent C++ IDE on the planet. Period. That’s why I use vim, youcompleteme which is based on clang to get semantic code completition, and rtags for jumping to definitions, which is, again, based on clang. Guess how fast my IDE starts? If you’re on linux terminal write “vim”. Yeah, that fast.

    “It’s an unmanageable language.” – Oh really? 😀 Because commercial games do it, huge projects do it, Qt VERY SUCCESSFULLY did it and, somehow, it’s unamanageable? Or maybe you need to learn manageability yet?

    “It’s a barely portable language.” – Fair point. But isn’t sometimes QTcpSocket same on linux and on windows? Shouldn’t you rely on a library for portability if you don’t want to deal with it yourself? I mean, yeah, someone else did the dirty job for you, but ain’t that the same for java where portability is also done for you?

    “std::list<std::shared_ptr> x;”

    So… I guess you don’t want to write typedef once if you use it many times?

    typedef std::list<std::shared_ptr> PtrList;
    PtrList x;
    PtrList y;
    PtrList z;

    “C++11 managed to complicate it even more”

    Yeah, I’d much rather write
    std::vector::iterator i = v.begin();
    instead of
    auto i = v.begin()

    🙂

  25. odraencoded

    Yeah, this post says it all. I came here being frustrated with CodeBlocks because it sucks so much. It’s not just the intelisense. It’s to the point I want to strip it of all its “functionality” and leave only syntax highlighting, the build settings and file navigation.

    I’m sincerely amazed by how much these IDEs suck. Netbeans has a terrible font support and is outstandingly weird to set up libraries in a project. I couldn’t bear to read the text so I switched to CodeBlocks. CodeBlocks code completion is an huge piece of shit. It makes no sense at all.

    It just shoves closing brackets and new tabs without thinking twice. Neither of those have a non-intrusive way of showing spaces and tabs. And the CodeBlocks GUI is basically pumping the window full of new menus, floating panels and tabs for plugins used for stuff I honestly have no idea about.

    Then there is QT creator. I don’t have tabs. What. The. Fuck? To think I would find a multiple document interface program in this decade without tabs?!

    The IDE support really, really hurt me. I’m giving up on this shit. I don’t even know as much as you, but I already know C++ is just not worth the trouble. This is just too much bullshit.

    People need IDEs for their C++ to fix the problems in the language, like header guards. So I’m really fucking amazed that IDEs have made it such an overly complicated task to create a header file. Like CodeBlocks needing you to actually open a save file browser to do it. This is stuff the developers of the very CodeBlocks would have to deal with on a frequent basis, to think they would leave it like that just confirms that these IDEs are seriously trying to outsuck eachother.

    I’ll give up on C++ too before it’s too late. I just have to find a replacement language to program games.

  26. hoge

    Your sample code (std::list<std::shared_ptr> x;) raise an error on my compiler because it misinterprets “>>” as shift operator. Indeed C++ is not nice (I know it’s just a typo, but I hate to put space between ‘>’). I found Python and lua is kind of nice language. Especially lua is work fine with C so I can use it for built-in scripting stuff. I tried Haskell but It was too difficult for me 🙁

  27. Dorin Lazăr

    @hoge: It’s not a typo. You need a C++11 compiler for that to properly compile.

    However, there’s a certain appeal to C++ that makes me come back to it, again and again.

  28. alex

    @there’s a certain appeal to C++: it’s the power of it. yes, its’ complicated, it’s a behemoth, is full of quirks and bad legacy. but is as sharp as it gets and it would blow up your leg if you ask for it, without begging (that’s the main critique that I have against c++: i like the ability to blow up legs, I would just like it to not be there *by default*, but that’s another story. And truth is, the language itself is becoming better, basically C++11/14 is a new language that just happens to be bckward compatible with C++03. And I am looking forward with eagerness to modules and scope_guards (unwinding_exception) in C++17 (and, I hope, even earlier). In the meantime, you could have a look at the D programming language (dlang.org).

  29. Dorin Lazăr

    C++’s new developments sound promising, especially the modules proposal that hopefully will catch wind for 2017. The modules and a proper IDE will make C++ a desirable language. 😀

  30. Alex Telea

    About the IDE support for C++ discussion: It’s indeed a valid question why it wasn’t done (well) so far. My opinion: simply because the effort to do it so is not worth it (for the IDE developer). Make no mistake: developing an ‘intellisense’ like tool for C++ is orders of magnitude more complex than doing the same for largely context-free languages such as Java or C#. I’ve worked with several people on this topic (R. Raggi from Nokia, working on QtDevelop; Scott McPeak, who laid the foundations of what is now LLVM/Clang, used by OS X; Taras Glek from Oink/Elsa, to mention just a few; also developed/sold tools that do that, google for SolidFX). Bottomline? (a) Developing a _strict_ syntax/semantic analyzer for C++ is about 10x harder than one for C#/Java; (b) Developing a _fuzzy_ analyzer for C++ (needed for understanding potentially incorrect/incomplete C++ code) is about 5x harder than (a). Is this a problem of C++? Not really I think. IMO, if you want to have a more expressive (read: context-dependent) language, like our own spoken languages are, you have a (big) price to pay. Sure, if you’re OK with a less flexible language (read Java/C#/etc), no problem: all is simpler, but then the programmer’s expression freedom will be inherently limited.

    Apart from this, tech rant: GLR (Generalized Left-Reduce) parsers are STILL relatively new. And parsers with a feedback loop to semantic analyzers are also not mainstream (dudes still learn that you have to use lex/yacc to build a FULL parse tree and only THEN do semantic analysis). Well, good luck building intellisense-like features for C++ with that.

  31. Dorin Lazăr

    @Alex: Still, C++ was here for 30 years now. The C++ part of Visual Studio, about 20 years. I would’ve expected some better support, if you understand what I mean. It’s true that it’s harder, but even so…
    Anyway, as I think I repeated through the comments, I will probably not give up on C++; it’s just tough love. After all, beautiful code can be written in any decent language, and C++ makes no exception.

  32. Dorin Lazăr

    @Peter: I’ve come back to C++ because I like to see its evolution. I’m not convinced that there’s any other language that can offer the same performance, and I think that C++ goes in the right direction, especially after I’ve seen the modules proposal for C++17.

    But truth be told, I’ve come back to C++ because I haven’t been really awed by other language, that would really solve my grievances. And since I use it as a personal projects language, I’m fine with it; after all, I know it well enough.

    There is some other rationale as well: while most languages will try to hide the machine from me in nice abstractions, C++ allows me to see exactly the cost of what I do. Sometimes it’s a good reminder.

  33. Alex

    C# native (called Roslyn project) is the END of C++.
    Open source .NET platform is the END of JAVA.
    Period.
    It’s just a matters of 1/2 years.

  34. Jerry

    I have not yet given up on C++ completely but I’m having loads of fun replacing serious pieces of code formerly trainwrecked in C++ with much more maintainable Elixir/Erlang.

  35. Alex Puchades

    I agree with some of your points, however, I would like to give my opinion about the matter:

    • I agree that the language is already very complex, and now even more with C++11: type deduction (all of them, see https://www.youtube.com/watch?v=wQxj20X-tIU), initializer_lists (everything about them),… Though, as time goes by, I don’t see it as a problem anymore, it’s simply the way it is.

    • Rvalue references were VITAL, it was simply ridiculous that you had to store noncopyable objects in the heap simply because of a language flaw (wasn’t C++ all about efficiency?) in order to store them in stl containers.

    • The STL sucks, agreed (though I don’t fully agree with some of your reasons), and I hope the whole Ranges thing will put some remedy.

    • Also take a look on iostreams… The API is inconvenient (though definitely an improvement over the printf one, which cannot be extended easily for custom types), its error handling is archaic, its performance is so bad that people don’t use it (http://channel9.msdn.com/Events/GoingNative/2013/Writing-Quick-Code-in-Cpp-Quickly?video, http://ericniebler.com/2013/11/07/input-iterators-vs-input-ranges/).

    • However, I don’t think Qt fares better: I think the majority of its duplicated functionality (containers mainly, because QString has some raison d’être) should be deprecated, QScopedPointer refusing to take advantage of move semantics is simply ridiculous,… and they OUGHT to start using exceptions as a saner and proper way of error handling.

    • Btw, Boost is AWESOME (though it’s just a matter of taste), you don’t have to use all of it, and I very much prefer the standard versions where available (std::unique_ptr, std::optional,…), but it definitely has raised the bar in API design on the C++ side.

    • The preprocessor sucks SO MUCH, which is probably the main reason that we still don’t have a proper module system in C++.

    • BUT, the worst thing in C++, its biggest flow once you get through all the complexity IMHO, is that as of C++14, we still don’t have a standard ABI, which means that you have to expose a C api, which sucks; or else having to compile zillions of versions of your library (taking into account OF COURSE different compiler settings). That’s why some library authors prefer header-only ones, which increase significantly compile times.

  36. Dorin Lazăr

    @Alex: my opinions might have been a bit toned down after a while, although I haven’t used C++ for a while now. Currently I’m working on an embedded solution, and I’m still pondering if I would choose a C++ based solution or a C# based solution. My experience with C# was quite good, and I feel that I never been as productive with C++.

Comments are closed.

Sprijină dorinlazar.ro

GDPR

Uniunea Europeană vrea să vă informez că nu vă folosesc datele personale pentru nimic. Și o fac aici.