An old-school computer with a big C on it.

Explorations in C, C++, Win32, and SDL

10 January 2022

lately I've been experimenting with C, C++, Win32, and SDL. The first thing I've noticed is we don't know how good we have it in the JavaScript/web development world:

Blog posts and online resources #

You can find great documentation for web stuff everywhere. JavaScript has blown up in a time when all kinds of people are becoming coders. There are a thousand accessible blog posts for any topic. And these posts actually get surfaced by Google!

C++ was blowing up when at a time when developers were a small subsection of society. If you were a coder, you had to be passionate. Of course you were - you were making command line apps! And if you were lucky enough to build GUIs, you had a lot of patience. Blog posts about C and C++ are relatively difficult to find and usually assume a lot of previous knowledge. They usually reference star wars. They argue about the differences between C and C++ and their use cases. They talk about how pointer arithmetic separates the men from the boys. 🤮

But it makes sense that we’re going to get more resources about the languages of the web on the web. A lot of the knowledge on C and C++ exists in those old things called books!

Language features #

We also have a lot of friendly language features in JS. JavaScript arrays aren't real arrays. They're more like cuddly rows of boxes that will pat you on the head and buy you an ice-cream for accessing an index.

In JavaScript we have problems with differing module types from the migration from common.js to esm, but we have nothing compared to the nightmare of header file includes, DLLs, and Makefiles. Also in C++ you need to reimplement rounding floating point numbers into ints - There is no comfy Math class for you here.

Win32 and Microsoft #

Navigating Microsoft documentation remains extremely difficult. Lists of links to explain different APIs take you on a rocky journey. The win32 API is obtuse and ugly. It demands a huge number of arguments in functions to get a window showing. You need gigantic event switch statements to take user input.

Why though? #

This all said, I think all of this is worth taking a look at. Why? Because C, C++ and Win32 create efficient programs. In both program size and runtime speed they beat electron apps. In a lot of ways they are better for the user. They're close to the metal and teach you about what the computer is actually doing. Our browsers are written with C++, our youtube videos are processed with C++, our databases are written with C++. And all the tools for C and C++ are free for the taking on the internet. Download Mingw on windows and open up your favourite text editor and you’re ready to start compiling! There are more steps here than making an index.html file, but not that many more steps.

I know that if you want a systems language for cool kids, there’s rust. I know that the majority of web apps will be fast enough with JavaScript and PHP based tools (and all the popular alternatives). I know that the high learning curve of C and C++ mean they’re probably not the most bang-for-your-buck languages for a web developer to learn in early 2022. But I’m always obsessed with the old ways of doing things and can’t help myself exploring.

SDL #

SDL is a toolkit for C and C++ to create “multimedia applications” (games. It’s for games.). Lazyfoo has a great tutorial on how to use it. If you’ve made a few command line programs and want to try making games, I’d recommend trying SDL. It’s so lightweight, and gives you a nice way to dig into building a little game engine and see what C and C++ are all about. It’s cross platform, has a few more resources around online, and is a lot nicer than trying to write raw openGL code yourself.

More thoughts #

Do I even know what pointers are? The way I think about them is indexes of a giant hidden array which directly exposes the computers memory. I don’t know if this is correct, but I almost feel like a real programmer hitting that star key *.

And could I find a way to hook into and extend node with C++? Looks like I could! Assuming I have the time and willingness. And could I ever finish a game with C++? Probably not if I want to have money and/or time.

Back to blog