Live data from Hacker News

Why I Write Games in C (yes, C)

jonathanwhiting.com

11–20 of 556 posts

Re: Why I Write Games in C (yes, C)

#12
The author despises OOP, and I agree with him there. I would add that OOP can be particularly bad for games, because often times the OOP vocabulary clashes with the game's own vocabulary: the game itself has objects (as in, things the player can pick up and put in their inventory), the game itself has classes (as in RPG classes). It might even have factories, depending on the game.

All support for OOP would vanish overnight if people realized you can do all the important OOP stuff using C structs.

Re: Why I Write Games in C (yes, C)

#13
post #10

There's one important question left out: what kind of games does the author make? I can see how 'vanilla' C can be more than sufficient for basic 2D games, but as soon as you grow in complexity it can quickly become an insurmountable task to grok.

Basic games like...Quake 3?

Re: Why I Write Games in C (yes, C)

#14
Quote: "I want to produce less bugs, so I want strict typing, strong warning messages and static code analysis".

Yeah, at strict typing you lost me buddy. Let's just go with somebody else reply, as in you like C and that's why you do your hobbies in. Nothing wrong with that in the end.

Re: Why I Write Games in C (yes, C)

#15

I get that this is not a popular opinion these days, but I like C. Quite a bit, actually. I can get stuff done reasonably quickly, don't have to futz around with multiple inheritance (C++) or where to call out to C anyway (python). There is so much more tooling behind C than Rust, or Go, or Zig (though I've been looking at Zig as a replacement). C isn't as bad as everyone makes it out to be, for personal stuff. I'd b…

It’s not unpopular to like C, and nobody ever said C is bad for personal stuff. Legitimate criticisms of a tool aren’t meant to be taken personally. I can say: “C happily lets you write off the end of arrays”, which is a valid concern, 100% true, and has no bearing on whether or not you should use the language.

Re: Why I Write Games in C (yes, C)

#16
post #10

There's one important question left out: what kind of games does the author make? I can see how 'vanilla' C can be more than sufficient for basic 2D games, but as soon as you grow in complexity it can quickly become an insurmountable task to grok.

What exactly is it about 3D that becomes harder to grok? You can still abstract things away by passing around pointers to C structs.

Re: Why I Write Games in C (yes, C)

#17
post #12

The author despises OOP, and I agree with him there. I would add that OOP can be particularly bad for games , because often times the OOP vocabulary clashes with the game's own vocabulary: the game itself has objects (as in, things the player can pick up and put in their inventory), the game itself has classes (as in RPG classes). It might even have factories, depending on the game. All support for OOP would vanish o…

> you can do all the important OOP stuff using C structs.

Such as having a safe, leak-proof string type? I think not.

Re: Why I Write Games in C (yes, C)

#18

I get that this is not a popular opinion these days, but I like C. Quite a bit, actually. I can get stuff done reasonably quickly, don't have to futz around with multiple inheritance (C++) or where to call out to C anyway (python). There is so much more tooling behind C than Rust, or Go, or Zig (though I've been looking at Zig as a replacement). C isn't as bad as everyone makes it out to be, for personal stuff. I'd b…

I didn't even realize C was so unpopular till recently. I kinda figured industry wise, C++ was much more common, but there seems to be a lot of stuff still written in C (i.e. many widely used kernels). I can understand was people would be apprehensive to C, but C++ just seems extremely bloated and I just haven't been able to get into it.

Re: Why I Write Games in C (yes, C)

#19
post #10

There's one important question left out: what kind of games does the author make? I can see how 'vanilla' C can be more than sufficient for basic 2D games, but as soon as you grow in complexity it can quickly become an insurmountable task to grok.

Looks like mostly 2D, but he's got some 3d games. I saw Knossu mentioned here once, it's pretty good.

And there's still plenty of life left in 2D anyway. Not everyone wants to crank out the next Fortnite or whatever the kids are into these days.

Re: Why I Write Games in C (yes, C)

#20
post #3

Write C code. Compile with C++ compiler. Catch lots of bugs at compile time.

> Write C code. Compile with C++ compiler.

What C only compiler were you thinking of? Most of the ones I can think of are toy compilers. If you're making a game, you're going to be using clang/MSVC/gcc.

For catching bugs early, at least as important as the compiler are

   * Enabling additional compiler warnings and -Werror
   * Checking for memory leaks with valgrind
   * checking for Undefined Behavior with UBSan
   * Using mix of static code analysis tools such as Coverity, PVS-Studio, and the Clang Static Analyzer
Post reply on HN