Live data from Hacker News

I write games in C (yes, C) (2016)

jonathanwhiting.com

231–240 of 288 posts

Re: I write games in C (yes, C) (2016)

#231
post #70

Earlier quoted context omitted.

> C++ doesn't take longer to compile if you don't abuse templates. Surprisingly, this is not true. I've written a C++ file only to realize at the end that I did not use any C++ features. Renaming the file to .c halved the compilation time.

I don't believe you, I measured compile times in c compilers and my own. If you provide more information I'd be more likely to believe you

That's fair. I'm unable to provide more information though so we'll have to disagree.

Re: I write games in C (yes, C) (2016)

#232
post #126

Earlier quoted context omitted.

Maybe it is similar for the same compiler (but one should check, I suspect C could still be faster), but then there are much more C compilers. For example, TCC is a lot faster than GCC.

tcc is 8x faster, twice as fast isn't doing it justice. As for the header thing, that'd could potentially be true if the compile time was something like 450ms -> 220ms, but why bother saying it when you're only saving a few hundred milliseconds

Going from 220 to 450 ms would be a disaster in my project. It has many thousands of files. Recompilation of almost everything happens from time to time.

If those made-up numbers were true, they would be very significant and an argument in favor of keeping the code in C

Re: I write games in C (yes, C) (2016)

#233
post #41

Earlier quoted context omitted.

Yeah, you could argue that choosing C is just choosing a particular subset of C++. The main difference from choosing a different subset, e.g. “Google C++” (i.e. writing C++ according to the Google style guide), is that the compiler enforces that you stick to the subset.

C's string handling is so abominably terrible that sometimes all people really need is "C with std::string". Oh, and smart pointers too. And hash maps. Vectors too while we're at it. I think that's it.

The C++ std::string is both very complicated mechanically and underspecified, which is why Raymond Chen's article about std::string has to explain three different types (one for each of the three popular C++ stdlib implementations) and still got some details wrong resulting in a cycle of corrections.

So that wouldn't really fit C very well and I'd suggest that Rust's String, which is essentially just Vec plus a promise that this is a UTF-8 encoded string, is closer.

Re: I write games in C (yes, C) (2016)

#234
post #143

Earlier quoted context omitted.

If you have patience, the first 30 or so episodes of Handmade Hero are pretty good. https://guide.handmadehero.org/code/

Handmade Hero is a bad idea for anyone wanting to learn how to make a game in C or C++. Casey intentionally avoids using standard libraries and frameworks and his irrational hatred of high-level code and modern standards will lead developers astray and waste their time. Even if you're using C you don't need to implement your own renderer or do half the things he does. Get a library like SDL3 to handle the basics, may…

We'll have to agree to disagree on this one.

Re: I write games in C (yes, C) (2016)

#235
post #228
post #206

Earlier quoted context omitted.

Of course, but gcc with -O0 is still slower and there is no TCC for C++.

There are other C++ compilers to benchmark against, using the same common C subset for comparison, though.

Is there still any non-LLVM C++ compiler left besides GCC? LLVM is not exactly known for its speed.

Re: I write games in C (yes, C) (2016)

#236
post #20

I write mostly like I would in C, but use C++ features as needed. It ends up looking similar to Rust if you squint. All these "I write games in C" people complain about C++ features, and then end up reimplementing virtual interfaces manually with struct headers or massive switch statements, just to feel better about themselves. Writing games in C is not harder, you just have to implement modern language features by h…

> C++ doesn't take longer to compile if you don't abuse templates.

It actually does though, unless you also drop C++ stdlib usage completely (have you looked at how many lines of code just alone pulls into each source file? - it's upward of 20kloc and growing with each new C++ version).

And at that point you get into discussions with various C++ camps about why you don't use the C++ stdlib and instead prefer to reinvent the wheel (and this friction with other C++ coders is the main problem of carving out your own subset - it works ok in complete isolation, but software development work hardly happens in splendid isolation and even then you'd might to want to use C++ libraries written by other people from time to time...)

And once you've been dragged into such C++-subset-discussion month after month, year after year, at that point it is much less exhausting to just write plain C. And the C community (if it can be called that) seems to be much less concerned about coding style dogma and generally a nicer bunch to interact with.

FWIW, I switched around 2017 and each time I have to interact with a C++ library for lack of alternatives it's usually not a pleasant experience (with the notable exception of Dear ImGui - but even there I started to prefer the C bindings so that I don't need to strictly separate the UI code from the rest of the code base, which sometimes makes sense, but often not, especially with an immediate mode UI framework).

Re: I write games in C (yes, C) (2016)

#237
post #70

Earlier quoted context omitted.

> C++ doesn't take longer to compile if you don't abuse templates. Surprisingly, this is not true. I've written a C++ file only to realize at the end that I did not use any C++ features. Renaming the file to .c halved the compilation time.

I don't believe you, I measured compile times in c compilers and my own. If you provide more information I'd be more likely to believe you

On some compiler toolchains (IIRC MSVC was the main offender) you get a lot more code pulled into your source file when including a C stdlib header (like ) in C++ mode versus C mode. Basically a couple hundred lines in C mode versus thousands of lines in C++ mode.

Re: I write games in C (yes, C) (2016)

#238

Earlier quoted context omitted.

C++ reimplements a lot of the things we do in C with function pointers, while hiding what's actually happening behind topheavy syntax that implies a 1990s object oriented paradigm that's dead now.

Contrary to popular belief C++ isn't really object–oriented. I mean, you can write object–oriented code, but the language doesn't make assumptions about what goes into a class. It's really just a struct with associated functions.

> It's really just a struct with associated functions.

If that were actually true C++ would be a lot easier to accept as a 'C successor'. Instead you have the implicit this-pointer, complicated rules for which constructor or operator overload is actually called, a hidden vtable pointer (not to mention multiple inheritance), then you have public/private/protected, override vs final, const methods (which wouldn't be needed as a separate syntax feature if the this arg wouldn't be implicit) etc etc etc... that a lot of OOP-baggage which a lot of C++ coders probably don't even notice anymore.

A plain C struct with function pointers does indeed make a lot more sense than all the OOP-ism that C++ hides from you ;)

Re: I write games in C (yes, C) (2016)

#239
Before I even read the blog post, my first thought was: "Bullshit, this feels like clickbait. Simple DirectMedia Layer (SDL2) [one of the most popular gamedev libs for indy games] is written in pure C." I guess that the only backdoor to this clickbait argument in 2026 can be: "My graphics/audio libary is written in pure C, but I use bindings with language X (C++/Rust/Zig/etc)."

Re: I write games in C (yes, C) (2016)

#240
post #200

Earlier quoted context omitted.

C++ nudges you to think in terms of single elements. Operator overloading, ctors/dtors, references, etc. you pay that cost all over the place. C programs tend to nudge you into thinking in terms of arrays of data. For game development you generally want to think this way. The cost of vtables and all the cache misses doesn’t have to be paid. A game has to stream bytes. Many things at once. Rarely single elements at a…

Only if devs lack the skills to understand what to actually use. There is this anti-C++ bias that keeps forgetting that using C++ doesn't mean use every feature. Just like many keep using C as if C89 was latest, and never adopt anything added in the last 30 years.

I agree, there is a nice language buried in all the features trying to escape.

The struggle is that if you choose a subset of the language to use and you have dependencies… well you’re including whatever features they use into your subset.

I don’t think C++ is a bad language at all or anything. Just that it nudges developers into certain modes of thinking based on the features it chooses to focus on. Might explain why some developers still choose C.

Post reply on HN