Live data from Hacker News

Why I Write Games in C (yes, C)

jonathanwhiting.com

31–40 of 556 posts

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

#31

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.

Implying that typing does not prevent bugs is the strangest programming meme I’ve ever heard, and its proponents push it so hard that I wonder if there’s somewhere I can sign up to be paid for it. We rarely are able to directly compare the cost/benefit of strict typings vs loose typings, but with JS vs TS you get a pretty direct comparison, and it is absolutely unsurprising that TS is eating the JS world; it does prevent bugs, it does improve productivity. Tests do too when done correctly, but both together are better than either individually.

When you go further, you can see that the core innovation of Rust is basically adding ownership to the type system and therefore making typing even stronger. Strong typing is a win for less bugs. Full stop.

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

#32
post #11

Very interesting point of view. I wish I had projects (like games) that could benefit to craft meticulously with C. The feel of coding closer to the hardware is great.

I'm not sure C is that much closer to the hardware, nowadays.

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

#33

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…

Writing game engines in C++ without using any OOP features, makes perfect sense to me. Other than the author likes C, he failed to show me why his approach is better than yours. I found it very light on details.

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

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

> 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.

This makes no sense to me.

By that logic, it would be difficult for me to create a scheduling system for classes being taught in factories with OOP, which it's not.

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

#35
I'm currently trying to decide if Nim is my C replacement.

On the one hand, it isn't C++, and it has real type safety, and it interfaces with existing C libraries very easily.

On the other hand, it is rapidly getting very complicated, and seems almost eager to become another C++ in terms of sheer volume of language features.

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

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

It's not 3D that's harder to grok, it's more that the nature of 3D games are often bigger with more environmental triggers and events that can quickly become very tightly integrated and difficult to make abstract compared to, say, C++ or other languages.

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

#37
post #25
post #17

Earlier quoted context omitted.

> 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

It's considered horrendous practice to typedef to a pointer of something. Not sure why this can be considered easy.

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

#38

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…

Handmadehero started as C but transition to C++ AFAICT ?

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

#39
post #31

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.

Implying that typing does not prevent bugs is the strangest programming meme I’ve ever heard, and its proponents push it so hard that I wonder if there’s somewhere I can sign up to be paid for it. We rarely are able to directly compare the cost/benefit of strict typings vs loose typings, but with JS vs TS you get a pretty direct comparison, and it is absolutely unsurprising that TS is eating the JS world; it does pre…

I too do not understand how anyone can complain about typing if they have used a statically-typed language for any real projects.

Your TypeScript versus JavaScript comparison is about as good as you can get. Many people I've met who think duck typing is the preferred way to go do so because they learned to program on JavaScript. That is more familiar to them, TypeScript is an extra burden to getting work done, and therefore is bad.

I am working on a large project that uses TS (Angular) on the front-end and I can't possibly imagine doing that in plain JavaScript. The lost hours to simple, avoidable bugs would be too great.

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

#40
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?

Yup. Quake 3 is basic. I remeber that the whole game had a "measly" 150.000 lines of code or so. It doesn't do a ton of things modern games do. The list of things expected from modern games these days in comparion is far too long to list here. These things have become elaborate world simulators. And all of these features add up.

The Unreal Engine is around 4 million lines without dependencies (e.g. PhysX, a proper audio engine, etc). You could try to do all that in C (good luck finding a good physics library with a plain C interface, btw.). But you need to have proper software design throughout the project and you will likely end up replicating some kind of inheritance or polymorphism scheme somewhere.

Post reply on HN