Live data from Hacker News

Why I Write Games in C (yes, C)

jonathanwhiting.com

401–410 of 556 posts

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

#401

> [C++] is high performance, and it offers but features I don't want, and at a great complexity cost. 1. Complexity of implementation is not complexity of use. Example: Take std::array vs a plain C array. std::array is a few hundreds of lines of code. But - it's about as inutitive to use; has more convenience features; easier for the compiler to optimize; and doesn't let you should yourself in the foot that easily. 2…

Also, the C++ committee is very serious about not paying for what you don't use. You can rest assured that there's no unused, hidden C++ bloat that is chipping away at your frame budget. This is not meant to be a strawman against the complexity cost argument, it's just a related feature of C++ that I thought might be worth explicitly pointing out in case anyone is misinterpreting. Also, if anyone has a credible dispu…

You are describing 'zero cost abstractions'. Except that they are anything but zero cost. Game developers and low level programmers shy away from them because of their impact in compile and build times, debug build performance and stack trace bloat, increased cognitive load, reduced refactoring ability. Even std::unique_ptr has runtime costs in release builds that a raw pointer does not.

In game development performance is a feature and anything that makes performance and memory usage less deterministic is frowned upon, like a GC. But iteration times are still paramount and things that make compile, load and link times longer and make it more difficult to debug are also frowned upon. Yes, we'd like to have our cake and eat it too :)

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

#402
post #5

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

Well, it is useful to know and like C.

It's useful to know C, you don't have to like C though (nor should you). At this point is a necessary evil.

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

#403
post #27

Earlier quoted context omitted.

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

My experience with Rust is that I have to fight the compiler a lot, but when the program compiles, it works . If it doesn't work, it means there's an error with my file/network paths or I did something in the wrong order, errors which no language can save me from. Rust also becomes a lot less verbose when you get better at it. The ? operator is especially useful.

From what I've seen if you fight the compiler a lot it means you're trying to write something that very non-trivial memory ownership. Just as RAII is a learned concept, so is understanding memory ownership. Hopefully it will be taught more in school along the lines of RAII and similar concepts.

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

#404

Earlier quoted context omitted.

So I dug some more, and it turns out that while he does have something to say about Rust, I'm not sure I'm convinced by his conclusion about safety: "Safety. Yes, Rust is more safe. I don’t really care. In light of all of these problems, I’ll take my segfaults and buffer overflows. I especially refuse to “rewrite it in Rust” - because no matter what, rewriting an entire program from scratch is always going to introdu…

Holy... Believe nothing that guy says. I'll just wait until he releases his first game with network connection and instantly gets a buffer overflow and his game becomes an entry for worms into people's systems.

Most of network services are written in C, not to mention kernels.

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

#406
post #258

I have similar frustrations using C++, but don't feel using C or even Rust would be an improvement, more of "side-grade" due to various tradeoffs those languages have for game development compared to C++. I am excited about the development of both Zig and Jai since they both are trying to fill what I believe is a much needed role of a C-like language with a few more nice language features like better compile-time cod…

imo it's worth pointing out that it's not called "Jai"

What is it called? I've followed a bunch of videos and never heard it referred to in any other way

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

#407

Earlier quoted context omitted.

I take it that scarcely anyone here has written software for video switchers, routers, DVEs, linear editors, audio mixers, glue products, master control systems, character generators, etc. etc. Missing a RT schedule rarely results in death, but you'd think so given the attitude from the customer. That's a silly definition for it. There's a whole world out there of hard real time, the world is not simply made up of st…

I actually have written software for video routers and character generators. We didn't consider them hard real time, though I wouldn't claim that such was standard industry usage. For example, if you're doing a take, you have to complete it during the blanking interval, but usually the hardware guarantees that. In the software, you want you take to happen in one particular vertical blanking interval (and yes, it real…

I currently work on software controlling the hardware like video routers, and this is definitely my experience. It’s all very much soft real-time.

In terms of customers and how much they care, the North American market seems to care less than Europe.

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

#408

Earlier quoted context omitted.

Disclaimer: I'm not a game developer; but, I've worked on a lot of projects with tight frame time requirements in my time at Netflix on the TVUI team. I also have no experience in Go so I can't comment on the specifics of that garbage collector vs. V8. I don't think it's necessarily that it "can't" work as much as it takes away a critical element of control from the game developers and the times you find yourself "at…

There's probably 500+ successful GC based games on the Steam store another 100000 to a million hobby games doing just fine with GC. I started game programming on the Atari 800, Apple 2, TRS-80. Wrote NES games with 2k of ram. I wrote games in C throughout the 90s including games on 3DO and PS1 and at the arcade. I was a GC hater forever and I'm not saying you can ignore it but the fact that Unity runs in C# with GC a…

Minecraft is the only Java based popular game I can think of. And damn did I love Subnautica.

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

#410
post #46

> The stop-the-world garbage collection is a big pain for games, stopping the world is something you can't really afford to do. I love this opinion from games programmers because they never qualify it and talk about what their latency budgets are and what they do in lieu of a garbage collector. They just hand wave and say "GC can't work". The reality is you still have to free resources, so it's not like the garbage c…

>> The reality is you still have to free resources, Not exactly. Here is how the early PC 3D games I worked on did that: They would have a fixed size data buffer initialized for each particular thing you needed a lot of, such as physics info, polygons, path data, in sort of a ring buffer. A game object would have a pointer to each segment of that data it used. If you removed a game object you would mark the segment t…

> So there were like 256 possible projectiles in Battlezone(1998)

Just have to say, loved that game to bits.

Post reply on HN