Live data from Hacker News

Why I Write Games in C (yes, C)

jonathanwhiting.com

21–30 of 556 posts

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

#21
The author's opinion is uncommon but not unique.

A few examples: https://handmadehero.org/ https://ourmachinery.com/post/physical-design/

Simple libs widely used in game dev circles: https://github.com/nothings/stb

This one is a full game engine with tools made for educational purpose: https://www.raylib.com/

I do write games and game engine code and tools in C++ without using any of the OOP features.

I know quite a few of other professional, experienced and talented developers doing the same, even full AA studios with up to 50 employees.

Some of them are going back to procedural C after a few years of disappointment with OOP madness.

I'll publish articles about this later, but for now, all I have to say is that it just works.

Newbies are often afraid of manual memory management and pointers, but there are simple ways to avoid shooting yourself in the feet with those.

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

#25
post #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.

SDS is a safe, leak-proof C string implementation. Obviously you can misuse anything, but SDS is easy to use correctly. It's robust enough for Redis.

https://github.com/antirez/sds

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

#26
post #6
post #3

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

Or even better, compile with a C compiler with proper flags set (like -Wall). Catch lots of bugs and also enjoy blazing fast compile time!

You'll probably find you're missing available warnings unless you add `-Wextra` too.

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

#27
post #5

So... essentially "I know and like C". Which is great! But as you say, that's not particularly useful for anybody else.

The guy should try Rust and then explain why he prefers either, that would be interesting.

Interesting.

I want to like rust but everytime I dive in it is getting more and more complicated and verbose.

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

#28
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…

Most modern C++ games use an Entity Component System (ECS)

https://en.wikipedia.org/wiki/Entity_component_system

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

#29
post #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.

Factorio, prison architect, papers please, FTL... lots of the best reviewed and most influential recent games are 2d.

Civilization.

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

#30

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.

I can see the value in C, especially for API wrappers and such, but it's entirely possible to just use a minimal set of C++ and avoid bloat. Simple templates, a vector math library with operator overloads, function overloads and std::vector alone are most of what you'll probably want to use from C++. Maybe std::unordered_map as long as you preallocate space for it. It doesn't have to be hairy.
Post reply on HN