C++ Is An Absolute Blast

C++ Is An Absolute Blast

By Zed A. Shaw

I want you to ask yourself an honest question. When was the last time you actually had fun in programming? Looking back, I don’t think I’ve actually had fun in programming for close to…10 years? I don’t have fun with JavaScript, Python, Ruby, C, nothing. When I say “fun” I mean, you genuinely were excited to work on your project and the whole time you work on it you’re thinking, “Damn this is a blast. I can’t believe that wild idea I had actually worked!”

For example, I’m working on a little roguelike game and I had the idea, “I bet I could use this dijkstra algorithm to connect rooms during map generation by inverting the map and then running it. It’d probably make really cool carved out tunnels between rooms.” I then had the greatest time figuring out how to pull it off and didn’t feel like C++ got in my way. I managed to pull it off and learned a lot in the process. I then had the idea, “I wonder if I can take my FTXUI user interface and just render it directly into an SFML render window.” Sure enough, I could totally do that too and not only was it not that difficult but I learned a lot about how C++ does unicode. None of this was easy, it was just all possible and I can’t think of too may ways C++ would stop me from doing what I want. That’s fun.

I think programmers have lost the story of why they got into programming in the first place. I know I didn’t learn to code just so I can make a bunch of billionaires more billions. I didn’t get into programming so that I can fight an immutable rendering engine into finally showing a cornflower blue button. I definitely didn’t get into programming just to make a few authoritarians at the top of a random open source project happy.

I got into programming because it was fun. I remember staying up late until 4am desperately trying to get my shitty gwBASIC code to render a character to an MS-DOS console. I remember working on weird GUI ideas and network servers for weeks on end just because I had an idea. I remember fighting one bug for a month only to find out it was a stupid spelling mistake. I remember that all of this–even the frustration–was a hell of a lot of fun. Easily more entertaining than anything else I’ve learned.

One thing I definitely remember was that C++ was also a lot of fun. Even back in the day when it was an overhyped and honestly terrible language. It was fun because I could probably make almost anything with C++. No waiting around for someone blessed by the Python Illuminati to create that terrible wrapper around a C++ project’s code.

But…somewhere along the way, C++ became…unfun, and I think the trend continued with every language to this day. The story of C++ is a possible warning to other languages, and a story of a great comeback from the dead that nobody realized happened.

In the late 90s to early 2ks, I was actively using both C++ and Java until I mostly quit using C++ about the same time the C++ community did this:

That’s how it felt anyway. Just a bunch of idiots finding the new angle bracket shaped Template Metaprogramming Hammer and bashing everything nailshaped within 100 meters. I remember insane discussions with people who thought adding two numbers with a template was “faster” than adding two numbers directly, even though the assembly language output was exactly the same.

This obsession with using template metaprogramming for everything–combined with what I recall as a weird arrogance in the C++ standards committee to refuse to make things nice for programmers–is what tainted C++ for me and many people. It became the language for architecture astronauts who cared more about the Pimpl pattern and metaprogramming than actually making the language nice to use.

That’s why I loved Java. Sun Microsystems totally cared about programmers and what they needed. Java had a Garbage Collector! Java totally would never end up doing the exact same thing. No, not at all. Java programmers would never become obsessed with insane boilerplate, AbstractFactoryFactory Visitor patterns, and caring more about standards than usability? No, never.

I think this is probably about the same time that many people my age quit using C++, and most of you probably remember an overly wordy complex language with a bunch of syntax but not a lot of gain for all the <> angle-brackets.

But, C++ kept evolving, and the standards committee seemed to realize that if they don’t do something they’ll become an obscure language only used by a single 10 trillion dollar industry. How pathetic!

They did the work, improved the language dramatically, and actually made it fun again all without losing their original goals. Sadly, nobody knows about this huge revolution in C++ so I’m going to update your perception of the language.

The Amazing Comeback of C++11

I want you to go ahead and look at what was added to C++ in C++11. Go ahead, click that link and look at that list of insane improvements. Let’s highlight a few massive changes:

  • auto — Yes, C++ actually added an automatic type inference keyword. I was as shocked as you because I remember C++ being an obnoxious jerk that made me type the same damn word over and over for no reason.
  • nullptr — What? Yes, they fixed the bullshit C thing of this weirdly defined NULL that’s a zero but not a zero because some jackass on the C standards committee still writes code for a PDP-11 that has 13.5 bit words and no zero address.
  • range-for — Are you reading this right? Yes, C++ has similar iterators and for(x in list) that Python has. Best of all, it works with auto so you can loop over lists and not care about getting the type right. JavaScript still can’t even figure out what a for-loop is but C++ has one.
  • lambda expressions — What?! Yes, C++ has lambda, and it’s not bullshit like Python’s lambda. Lambda’s in C++ are so good I think they end up dramatically changing how you can approach design. Checkout how FTXUI uses them to see how much they improve the usability of APIs.
  • — Do you understand what just happened? In 2011 C++ had a better default time library than almost every language I’ve ever used. It’s so good you can actually write 100ms to create a 100 milisecond time point. Yes, and this is valid syntax and is type safe.
  • — What? Yes, C++ has built-in regex now and they’re pretty damn good too. They do have one flaw that it’s not actually exactly like JavaScript in the “ECMAScript” mode, but it works really well otherwise.
  • unique_ptr and shared_ptr — Yes, these implement various kinds of reference counting and enforcing memory ownership. Once these were added people largely stopped doing loads of heap allocation and instead now opt for more on the stack and only these pointers where needed.
  • — Yes! Multi-threading is baked into the language by default. What is this language? The C++ I remember said, “You want threads? Write it yourself dipshit.” New C++ is saying, “Yeah! Threads are really nice! Here you go.”

I honestly don’t know what happened or why C++11 was such a massive improvement to the language but it reminds me a lot of ES6 in the JavaScript world. Just a complete overhaul of the language’s philosophy and style without alienating the previous way of doing things.

Yep, C++’s Got That…Sort Of

More importantly though, C++ is now a more modern language with quite a lot of the things you find in other languages. Here’s a list of some common things you may need:

  • Need to traverse the filesystem? Check out filesystem.
  • Need package management? Check out Conan, Meson’s WrapDB, and vcpkg.
  • Need a matrix library? Checkout Eigen.
  • Tensorflow is written in C++, FYI.
  • Graphics? I mean do I need to mention that tons of games are written in C++? Well try out SFML for a good start.
  • GUI? Ehhhh, yeah you have Qt and wxWidgets I guess. There’s also ImGui but my favorite is…
  • TUI? Yes, I believe that FTXUI is the best designed GUI library in any langauge. It’s that good, but only for Terminal UIs.

C++ pretty much has everything you might need, but if I’m being honest, it can be hit or miss on quality. I’d say the quality is generally higher than you expect, and I’d say it’s higher than what I find in JavaScript and Python. I think “hit or miss quality” is something I could say about every language if we’re all being honest here. I mean, do you really think Python’s package management is top notch? You do? Why are there like 10 package managers then? Do you really think any GUI API is good? How about filesystem APIs? I mean c’mon, they’re all pretty bad, so I’d say C++’s are about the same, and most are slightly better. Things like FTXUI are amazing. The STL is pretty awesome too.

Yeah, Yeah, But You Said “Fun”

I can hear you now. “Oh yeah, well Rust has really good web servers…and…and data structures…and..uh uh uh a standard library. Rust is just as fun as C++!” Yes, my point is not that all these new things are what makes C++ fun. The point so far is this:

If you believe that C++ is old and stodgy with tons of angle brackets, pointers, and this-> bullshit you’re wrong.

I’m finding that C++ is probably the most capable language in existence right now, by a vast margin. I don’t think I’ve ran into anything I can’t do, and not only that but there’s multiple options for almost anything I want to do.

  • If I want to make a desktop app I can hand code it myself using use something like fenster, or use something like SFML, or use QT or directly code it old school style (see fenster for a good guide on doing that).
  • If I want to play sounds there’s a ton of options from open source to paid to any kind of DIY. I can go grab SFML for something quick and dirty, or even pay for wwise to get the best in the industry.
  • If I want to do 3D graphics I can use OpenGL, Vulkan, Direct3d, Ogre3d, and so many others. You’ll trip over a 3D library in C++ when you walk out your door.
  • If I need math there’s everything from BLAS, Eigen to game specific libraries like GMTL.
  • Do you need to do AI? Did you know Tensorflow is actually written in C++.
  • If there’s not a library for it, it’s not too difficult to directly hook into almost any OS API and roll my own, and rolling my own gear is fun.

That’s only a few examples, but the most important thing to understand is, C++ doesn’t really get in your way. Since you have direct access to almost every library with C or C++ ABI, and also direct access to every OS, you’re pretty much able to make anything you need by yourself.

C++ DGAF

Alright, so you can do anything you want with C++, and the C++ standards committee has corrected course to focus on developer productivity since 2011. How exactly is that fun Mr. Zed A. Shaw?

C++ is in this weird creative sweet spot where the language and the ecosystem are extremely high quality, but the language isn’t popular enough to attract the weirdos who ruin languages.

You know who I’m talking about. Remember how I said that I left C++ because a bunch of weirdos went insane with design patterns and template metaprogramming? Then I joked that this exact same thing happened to Java with design patterns and insane XML files? Then it happened with Ruby when Ruby on Rails became popular. Then it happened with Python, and JavaScript, and Rust, and pretty much every time a language gets popular there’s those insufferable idiots who ruin languages?

You see, C++ is unfashionable now so those morons don’t care about it. C++ is so unfashionable even the White House hates it, so all those authoritarian douchebags who run around smashing you over the head with standards documents have fled to languages where they can peddle their bullshit influencer garbage.

Those idiots are in your mentions, yelling at people, “Why don’t you use Rust?!” They’re the ones who shame you with, “Why don’t you use React?!” They’re the ones screaming, “Why are you using so much unsafe in your Rust code?!” They’re the ones who scream, “Seriously?! A for-loop in Ruby code! Gah! Amateur!” And thankfully, C++ is not popular enough for those grifters to profit so they mostly ignore it.

Well, actually the Rust weirdos will bother you but they’re usually too busy making the borrow checker happy to actually get anything done so you can ignore them.

This means that C++ the language–and C++ the community–simply Does Not Give a Fuck what you do. Do you want to write a matrix library? Go for it. Want to make a GUI library? Go for it. Want to write a game engine? Sit on your couch in the dark and go for it. How about a weird game that watches you code and makes fun of you? Seriously, nobody cares and most people think it’s hilarious or fun.

DGAF is Essential for Creativity

“But Zed, don’t we need a Great Glorious Leader to tell us how best to behave? Won’t C++’s lack of an authoritarian Benevolent Dictator for Life leave you without direction? Won’t you make…dare I say…mistakes?! How can you possibly survive without the BDFL grifters shaming you into working for them for free?”

I mean, I think you are probably not saying this exactly but you’re definitely saying it tangentially. This mentality is one of the biggest reasons why other languages are not fun. Other languages are strictly controlled by organizations that actively shit on you if you try to make something cool. If you try to make a competing project to one that a BDFL profits from, then you better be ready for their attack dogs to hound you for years.

I firmly believe that for creativity to blossom you need to be able to get your idea out without fear of criticism and shame. You have to be able to express yourself and only after you’ve pulled your idea out of your body kicking and screaming can you step back and look at it critically. However, once you get your idea out there you better be ready to critique it before someone else does. It’s this change in modes from “creative freedom from criticism” to “highly focused on quality” that makes for great creative work.

The best explanation of this concept comes from a painting teacher I used to have. Actually, this was every painting teacher I ever had. They would walk over to student’s unfinished work and try to correct it. They’d annoyingly stand in the wrong place–usually their 5′ tall eyes vs. my 6’2″ tall eyes–and say my drawing is wrong even though their perspective is totally different from mine. Or they’d comment on some aspect of the in-progress work that was difficult to judge because it wasn’t shown in the context of the full painting.

The mistake these teachers made was that they assumed a “mistake” early couldn’t be corrected as you go, and would stay a “mistake” in the final work. It’s entirely possible that what the student finally creates ends up working just fine when it’s finished, but in the middle of the process nothing looks right so trying to “correct” it is pointless.

This is an important thing about creativity these teachers didn’t realize. Everything looks and feels like crap in the “ugly middle” stage. In the beginning things will seem great, but as you work everything gets messy because you’re reshaping and moving everything around to reach your final vision. It’s more like walking a tightrope than driving a car where you’re balancing on a thin line trying to reach the other side, and the only way you learn to walk the tightrope is to fall over and over until you get your balance right.

A lot of other languages feel like people are constantly trying to push you off the tightrope midway just so they can sell you a car instead.

C++’s nearly unlimited space to create, combined with the relative lack of shame grifters makes it an incredibly creative experience. If I have an idea I’m only limited by my skills, not by a limitation of the language or some C++ blowhard influencer declaring me unqualified to teach because I don’t like his Benevolent Dictator for Life.

I think cppreference.com is the best programming language documentation I’ve ever used. It has nearly every single thing I believe languages need except for one:

  1. Every single keyword and library is fully documented with reference material.
  2. Every one of these also has extensive working examples. I think I’ve only hit about 5% that didn’t actually work as written, and most of those were due to the compiler’s implementation not the documentation.
  3. Every single feature not only indicates the C++ standard version that introduced it but it also links to the exact standard documents and other reference material that standardized it.
  4. It has a search bar that uses duckduckgo so it actually does find things even if you make spelling mistakes or can’t quite remember the exact terminology.
  5. In addition to fully explained reference material, very good examples, and exact version information, it also has full explanations of important concepts with examples. Take a look at the documentation on Copy elision. While still very technical, it is well written and includes many examples to show you what they’re talking about.

The only thing missing from the cppreference.com documentation is how to install various compilers on different platforms. I’m kind of mixed on whether they should do this or not. For other languages this kind of documentation is very important, but for C++ I think they most likely would get pushback from various members (*cough* Microsoft) and probably can’t. However, given that there’s only a few C++ compilers and a few platforms, it’s entirely possibly they could add a series of getting started guides.

It’s Not All Puppies and Butterflies

While I’m having an absolute blast coding C++ I want you to understand that I do not in no way think the language is without flaws. Not even close. My thinking is C++ is now about as good as any other language out there, and that no language is perfect. You’ll have annoying things to deal with in C++ just as you have to in any other language, it’s just C++’s annoying things are different.

For example, in C++ it’s a real pain in the ass to get a non-microsoft installer working on Windows. No, MSYS2 does not work. MSYS2 is hot garbage so shut up. I had to create a whole set of PowerShell scripts just to make installing compilers and dev tools easier.. If you think that’s terrible, then why are you using Python? If you try to install any Python on Windows you have to deal with the installers not adding Python to the PATH…unless it’s a blessed installer from Microsoft or ActiveState. Then the installers are allowed to add Python to the PATH on Windows.

You see, C++ wins here because I don’t have to deal with some arbitrary backroom dealing that gave Microsoft and ActiveState a free pass to violate the apparent “law” that no Python installer shall use the PATH. That alone is a massive win for me. It’s not fun to have to argue with idiots who think this situation is normal in Python.

If you think your language is superior, give me about 1 hour and I’ll find enough irritating bullshit to make your language look like a pathetic usability nightmare. The all suck, it’s just C++’s suckage doesn’t seem to ruin its fun.

Just a few of the pain points I have with C++ currently are:

  • +95% of the compiler errors are the worst in the entire industry. I’m not even being hyperbolic here. C++ error messages are just the worst. I think if the standards committee wants to make the biggest impact it’d create a standard for error messages, because the current state of error messages is almost malicious.
  • The build tools are so bad. I have no idea why C++ build tools are just nightmares to use but the people who make them just make the dumbest decisions. The best one I’ve found so far is Meson and it’s full of idiotic decisions like ignoring installed package directives to use broken system libraries without telling you. I literally ran into this the day I wrote this essay and it was infuriating.
  • There’s no incentive for compiler manufacturers to follow the standard. I mentioned that Clang as a bug in std::source_location and it’s a great example of the kinds of crap you run into sometimes. I really think the standards committee needs to start listing compilers that leave bugs like this unfixed. Just a simple page that lists compilers and how compliant they are, with special callouts for compilers that have obvious bugs would do a lot.
  • The language is insanely complex because of its history. C++ does have a ton of legacy stuff you have to wade through to find the nuggets. My understanding is it’s kind of like C++ is three (or more) languages similar to JavaScript. You have the old style where almost everything is heap allocated and raw pointers are everywhere, then you have the Template Metapocalypse style, then you have post-2011 style where almost everything is on the stack with very few pointers, and I’m seeing a newer style where everyone just uses struct instead of class and doesn’t use a lot of inheritance. Navigating all of these “eras” of C++ can be daunting, and there’s more than a few code review Youtubers who seem to be stuck in one era or another.
  • I really hate RAII. I’m finding that there’s a ton of situations where RAII gets in the way of real world configuration situations, to the point that this one “feature” of C++ seems more like a glitch than an actually useful thing. In my opinion–given how so many other languages don’t have this at all and are just fine–C++ could do well to devise a middle ground between the current RAII and the initialization constructors other languages have.

But, that’s for another essay. For now, I just wanted to express how much fun I’m having doing dumb stuff in C++ and hopefully educate people that C++ isn’t the language you think it is. If you ever see a course that tries to shame C++ with a billion angle brackets, just know that the author of that course is a clueless moron who has no idea what they’re talking about. I mean, check out this GUI layout code from FXTUI:

  document_ = Renderer([&]{
    return hbox({
        hflow(
          vbox(
              text(format("HP: {}", player_.hp)) | border,
              text(status_text_) | border
              )  | xflex_grow
        ),
        separator(),
        hbox(map_view_->Render()),
    });
  });

Be honest, if you didn’t know this was C++ could you guess what language it was? I rest my case.


More from Learn Code the Hard Way

Leave a Comment

Your email address will not be published. Required fields are marked *