Live data from Hacker News

Why I Write Games in C

jonathanwhiting.com

41–50 of 303 posts

Re: Why I Write Games in C

#41

Earlier quoted context omitted.

Is Rust available on consoles? (AFAIK, no) Is it going to be around? (Who can tell?)

https://twitter.com/rustlang/status/598945014824173569

And for any console other than PSX emulator you can place a SFF PC on a console and run Rust on it (as an added bonus you will get a better API than writing hex numbers into registers).

Re: Why I Write Games in C

#42
Simplicity of a programming language, and simplicity of programs written in it are two very different beasts.

I understand funny things happening under the hood (garbage collection) might not look attractive ; However you can't require everything to be explicit and, at the same time, keep your programs simple/small.

The more you want your code to be small, the more you're gonna need a programming environment (language/API/runtime/framework) doing things for you under the hood. And there's nothing wrong about it!

Re: Why I Write Games in C

#43
post #35
post #21

The article mixes up the virtues of a programming language with the quality of the environment. C might very well be the best language in our current environment, which says little about the language itself. One major point certainly is, that it is that good compilers are available everywhere and almost any library can be used from C. There are a lot of historic reasons for that. If he wants strict typing, C is actua…

The Google Go team lives in a completely different environment. Their perspective of performance is not the same as a game dev. Go 1.5 stated their goal was 10ms GC latency. A game loop is 16ms for a 60fps game. 10ms is not close to acceptable. Fast for a web server backend, but not fast for a game.

I have not experimented with the Go GC under heavy loads yet, but the important points of 1.5 are, that the GC pauses have an upper limit of about 10ms for multi-gigabyte heaps - previously they could be up to a second, and often are much faster (in a game environment with smaller heaps, they might actually as low as 1ms, which would be acceptable). I wrote, that there might be further tweaks required, i.e. having an API to call the GC for a set number of milliseconds. If your code isn't 100% using the time slice for each frame, it could use the remaining part of each time slice for garbage collection, eliminating the need for blocking stops. So, whether Go is acceptable now entirely would depend on some measurements. And if not, could be possibly tweaked. As I wrote, I would rather count this under "environment" where C might still win.

Re: Why I Write Games in C

#44
post #23

If by "strict typing" you mean strongly typed then you are factually incorrect. By virtue of casting C is weakly typed, as is Java, C++ et al. If your understanding of strict typing is statically typed, i.e. that types are checked at compile time then C still has some flaws as you could write a whole slew of C that is "typeless" using void * although that would be terribly misguided. I understand your intent, but I d…

> By virtue of casting C is weakly typed, as is Java, C++ et al.

Java's casts are dynamically checked, memory-safe and only work through the inheritance hierarchy, if you try to cast to an invalid type you'll get an error. Putting it in the same class as a C-style cast makes your usage of "weakly typed" as meaningless as it ever is.

For C++ — ignoring C-style casts — it depends which cast you use, dynamic_cast requires RTTI but IIRC it offers the same guarantees as Java's cast; static_cast should check that the types are related and the conversion is valid at compile-time, reinterpret_cast is the "weakly typed" one (essentially a simpler version of a C-style cast).

> I understand your intent, but I dislike the ambiguity of the phrasing.

Yet you use the expressions "strongly typed" and "weakly typed"?

Re: Why I Write Games in C

#45
post #11

I thought Lua was great for games development, the author does not mention it. http://www.lua.org

The author said that garbage collection and non-static-typing were problems. Last I checked Lua has both of those.

Yet Lua has been embedded in a large number of AAA games.

Re: Why I Write Games in C

#47

What about Rust?

I like Rust, but sometimes it is pretty difficult to convince the compiler that one's code is safe. And this does not mean that the compiler is preventing unsafety; there are many safe programs that the compiler rejects. Also, the OP said that compile time was a priority, and compiling Rust code is closer to C++ speed than C.

> there are many safe programs that the compiler rejects

It's often less about being safe currently and more about being resilient to breaking after further changes in code. I've worked with some C++ codebases that rely on complicated invariants to be safe (so the code looks safe now), and stuff breaks down when certain changes are made. Programming with a C++11 style greatly reduces but does not eliminate this.

It takes a while to get a hang of this, but once you figure out the "Rust way" of moving data/references around you tend to hit these errors very rarely. Of course, this takes time to learn which you may not have :)

But yes, there are things which Rust could improve upon here, like nonlexical scopes and SEME regions. Which may come soon.

Re: Why I Write Games in C

#48
post #40

The thing I miss most in C when I don't cheat and use a couple C++ features is templates. Specifically, a dynamically sized List implementation that is type-generic. If you do this in pure C, you have to pick your poison: 1. preprocessor abuse 2. void * 3. multiple redundant implementations of the data structure Dynamically sized lists are used so often, that this tends to be a problem in almost every C project. I wo…

Just use queue.h, as do all the BSDs. https://github.com/freebsd/freebsd/blob/master/sys/sys/queue...

There is also STB stretchy buffer, popular with game devs. https://github.com/nothings/stb/blob/master/stretchy_buffer....

Re: Why I Write Games in C

#49

The thing I miss most in C when I don't cheat and use a couple C++ features is templates. Specifically, a dynamically sized List implementation that is type-generic. If you do this in pure C, you have to pick your poison: 1. preprocessor abuse 2. void * 3. multiple redundant implementations of the data structure Dynamically sized lists are used so often, that this tends to be a problem in almost every C project. I wo…

I think it's GPL, so it's not for everyone, but the last time I did something in C, I came across Judy, which is totally awesome for what it does.

Apparently, the implementation is complex enough to drive an ordinary mortal like myself insane, but it is hidden behind a very simple interface, and it is blazingly fast. It only gave me problems when trying to use boehmgc, because it does not detect pointers stored in a Judy tree.

Re: Why I Write Games in C

#50
post #39

Earlier quoted context omitted.

If you're going to write a TL;DR for others, you should at least read the article yourself, don't you think?

I did, it is so abstract to pretend you can do better that there is no way to discern. He didn't even mention "unity" in his post, thats just ridiculous in 2016, but yeah, keep down voting, your implementation of 2d graphics, sound, collision, physics, plugins, marketing, sprites, menus is gonna be so much better than hundreds of engineers at unity withing 10 years straight.

Unity games I've tried seem to stutter often. Any idea why? GC cycles?
Post reply on HN