Live data from Hacker News

I write games in C (yes, C) (2016)

jonathanwhiting.com

221–230 of 288 posts

Re: I write games in C (yes, C) (2016)

#221

Earlier quoted context omitted.

> that guy asked Stack Overflow how to make gcc compile his .png Do you have a link to this? All the search results I'm getting are related to libpng.

I can't find it with a more specific search on SO, maybe it was deleted. The question was like: I wrote "hello world" but I get some compile errors, followed by an image embed of a handwritten hello world program, followed by a compiler command where the input file had a .png extension and an error related to the compiler not being able to read PNG files, followed by quoting the part of the standard where it says the…

I'll take things that never happened for $500, Alex

Re: I write games in C (yes, C) (2016)

#222
post #26

>I really dislike javascript, it is so loose that I marvel that people are able to write big chunks of software in it. I have no interest in trying. Because they use Typescript. >The stop-the-world garbage collection is a big pain for games There is a number of languages that allow manual memory management: Zig, Nim, Rust and few others

> There is a number of languages that allow manual memory management: ... Nim

Nim not only has support for manual memory management, but there're several gc modes that are not stop-the-world.

Also, since Nim 2, the stdlib now is using ARC by default, which is deterministic and has advantages over conventional garbage collection.

Re: I write games in C (yes, C) (2016)

#223

Earlier quoted context omitted.

> then end up reimplementing virtual interfaces manually C++ dynamic dispatch (your "virtual interfaces") is achieved by welding a vtable onto every type and providing a pointer to that vtable for instances of the type. If in 90% of your code you deal with specific types like Goose or Swan or Duck or Seagull, and only 10% needs to work with the broad Bird category well, too bad, every Goose, Swan, Duck and Seagull ca…

> by welding a vtable onto every type It's not true. Virtual methods table is present only for classes with at least one virtual method. Learn C++ properly before doing such claims.

The context you snipped is about dynamic dispatch, that is what you - as someone who has "learned C++ properly" apparently call "classes with at least one virtual method" and indeed the earlier comment calls "virtual interfaces".

Re: I write games in C (yes, C) (2016)

#224

> I like Go a lot. In many ways it is C revisited, taking into account what has be learnt in the long years since it was released. I would like to use it, but there are big roadblocks that prevent me. 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'm no Go fan, to be clear, but GC isn't the problem with Go. It has a pretty decent GC with…

The performance gains from bit-level control over memory come from managing the layout to ensure cache locality and do things like SIMD - and nowadays even GPU kernel offload. Enormous performance gains. I agree that it really isn't about garbage collection pauses, but I haven't heard people focusing on "eliminating gc pause" when they talk about low level languages, but they spend a lot of time talking about SIMD, G…

Go defines structs the same way C does, so it's already encouraging thinking about and optimising the physical data layout. It also recently added experimental support for SIMD intristics: https://go.dev/doc/go1.26#simd . Nothing on GPU side yet though, but I wouldn't be surprised to see it there eventually too :)

Re: I write games in C (yes, C) (2016)

#225
post #199

Earlier quoted context omitted.

> then end up reimplementing virtual interfaces manually C++ dynamic dispatch (your "virtual interfaces") is achieved by welding a vtable onto every type and providing a pointer to that vtable for instances of the type. If in 90% of your code you deal with specific types like Goose or Swan or Duck or Seagull, and only 10% needs to work with the broad Bird category well, too bad, every Goose, Swan, Duck and Seagull ca…

Except that C++ provides the tools to do just like C, Rust, or whatever one feels like doing for dispatching, even if it requires a few pages of template metaprogramming mixed with compile time executions, or writing exactly the same C code on the common subset across both languages. Now with reflection even more tools will be available. Which is why despite all its warts and security flaws, many inherited from C sou…

Because these are General Purpose languages you can do the same things, but the contrast here is what's provided in the box and how it is used idiomatically, because in practice that's what gets used, and that's what I explained above.

You can write C++ style OOP hierarchy code in Rust but that's not idiomatic, and you can write Rust style explicit dynamic dispatch in C++ but again it isn't idiomatic.

Re: I write games in C (yes, C) (2016)

#226

Earlier quoted context omitted.

> because the LLVM people called their frontend "clang" I can't even use that Said frontend is for the C programming language. Isn't that perfectly appropriate? I did a web search for "golang" and the first result was a download page for a Go compiler, so there is precedent.

What's the first result for "clang"? How about in private browsing?

A page about a C compiler. Not unlike the "golang" result, except without the same level of polish. The download link is similarly present, although due to the design choices doesn't stand out as the primary focus like it does in the "golang" case. I would consider the basic intent to be the same for both.

Which is the best one could hope for given that the search engine doesn't control the content. If I am searching for "golang", a Go compiler is the most likely thing I would want to find. Presumably someone who already has a Go compiler installed will have more specific queries. Likewise, if I am searching for "clang", a C compiler is also the most likely thing I would want to find. For all intents and purposes that is the entry point into using a language.

All in all the search engine did a great job and gave exactly what I would have expected.

Re: I write games in C (yes, C) (2016)

#227
post #199

Earlier quoted context omitted.

Except that C++ provides the tools to do just like C, Rust, or whatever one feels like doing for dispatching, even if it requires a few pages of template metaprogramming mixed with compile time executions, or writing exactly the same C code on the common subset across both languages. Now with reflection even more tools will be available. Which is why despite all its warts and security flaws, many inherited from C sou…

Because these are General Purpose languages you can do the same things, but the contrast here is what's provided in the box and how it is used idiomatically, because in practice that's what gets used, and that's what I explained above. You can write C++ style OOP hierarchy code in Rust but that's not idiomatic, and you can write Rust style explicit dynamic dispatch in C++ but again it isn't idiomatic.

Microsoft uses Rust like traits on Windows with C++.

Re: I write games in C (yes, C) (2016)

#228
post #206
post #201

Earlier quoted context omitted.

The question is the performance optimisations on top. 1990's compilers were also super fast, they only did optimisation for size, speed, constant propagation, and little else. Zero code motion, loop unroling, code elision, heap via stack replacement, inlining,...

Of course, but gcc with -O0 is still slower and there is no TCC for C++.

There are other C++ compilers to benchmark against, using the same common C subset for comparison, though.

Re: I write games in C (yes, C) (2016)

#229
post #20

I write mostly like I would in C, but use C++ features as needed. It ends up looking similar to Rust if you squint. All these "I write games in C" people complain about C++ features, and then end up reimplementing virtual interfaces manually with struct headers or massive switch statements, just to feel better about themselves. Writing games in C is not harder, you just have to implement modern language features by h…

> then end up reimplementing virtual interfaces manually C++ dynamic dispatch (your "virtual interfaces") is achieved by welding a vtable onto every type and providing a pointer to that vtable for instances of the type. If in 90% of your code you deal with specific types like Goose or Swan or Duck or Seagull, and only 10% needs to work with the broad Bird category well, too bad, every Goose, Swan, Duck and Seagull ca…

The convenience of having regular generics and dyn generics handled automatically is a great feature of Rust, sure, however you can write a template in C++ that directly calls a method, f.e. obj.Object::method(), which skips the vtable, achieving the same thing. Or you can keep manually writing everything in C because you refuse to learn C++.

Re: I write games in C (yes, C) (2016)

#230

Noble quest, but without operator overloading when dealing with Matrix*Vector you end up with an unreadable mess for physics, skeletal animation etc. There is a reason professional game dev is still 90% C++. (Funny enough, amateur gamedev is C# these days, students use what they learn at uni).

Funny enough, amateur gamedev using C# is a billion USD industry.

... because that's what ships with Unity.
Post reply on HN