C vs C++

I have had a difficult time choosing between C and C++ over the course of this project. At first, I decided to use plain old C to start off this project. Rapidly, I thought C was annoying to program with and offered very limited features. Then I realized that objects are really useful in the context of making games, so I switched to C++11.

I’m not sure these decisions were mistakes. My early switch to C++ forced me to learn, about how objects work, opened up to me the world of the Entity-Component-System (ECS). I implemented many useful feathers in C++. Many of my tools were C/C++ compatible: especially SDL, the base layer of this project. After a while though, I thought C++ was abstracting too many things that should be simpler, closer to the metal. My initial decision to start with C was already influenced by Suckless.org and various blog posts linked therein. Recently I was considering switching C after having built a many thousands line codebase of various useful functions and classes. Still, I did decide to switch, though. It was a hard decision: I was still using C++ exclusive third-party extensions, namely Entityx.

In the end, more experienced programmers on the internet, that have demonstrable skill and track records of popular and performant software, keep telling me that OOP is bad (although objects aren’t), that C++ has longer compile time, that it is more complex, that it forces you to type more for nothing. I believe them. Trusting my instincts, I personally feel that many concepts and features of C++ are over-designed and over-complicated, abstracting too much away. C and C++ both felt arcane to me at first, but the C++ rabbit hole seems deeper and experienced programmers swear it is less well designed. Because of their influence, even using C++ I was using the least amount of C++ features I could. I was trying to minimize the use of external tools, especially the C++ standard library tools. Those feel more like black boxes than open-source extensions. Still, C++ has 2-3 features that I wish C had: vectors, namespaces… Sean T. Barret has already implemented typesafe dynamic arrays for C. Namespaces I can do without, even though it is slightly annoying. ECSs for C exist, for example flecs. C structs are basically classes anyway, With some discipline, the “_variable” convention to note private variables and functions that input the object itself, I can replicate OOP without any problems. With experience, I may also be rid of some of these dependencies by programming some version of them myself.

I think I’m more than halfway through the conversion of my codebase to C. Many of my C “classes” are fully functional, proved thanks to test scripts. Since this project is fully within my control, I am taking a chance and making this game fully C. I can imagine this kind of conversion being impossible if I ever were to work in a software company: even more reason to try out pure C.

Leave a comment