Live data from Hacker News

Why I Write Games in C

jonathanwhiting.com

201–210 of 303 posts

Re: Why I Write Games in C

#201
post #96

You don't really get rid of complexity by using a simple language. You just move the complexity into your own code. Say if your language doesn't have dynamically sized containers, you will end up writing your own. You hack it so you can store different types in it. You have reinvented polymorphism. And then you need sort functions, and everything else that is missing from the language. And it wont be simple any more.…

I believe that there are actually some third-party libraries for C, which evolved in the open-source ecosystem since K&R, which potentially provide quite much interesting stuff. At some point I've stumbled upon some string library for example, I believe it might have been http://bstring.sourceforge.net/. To respond e.g. to your specific concern about containers - some quick googling for "C containers library" seems to give e.g. https://code.google.com/p/ccl/.

So, I believe it might be interesting to do something of a thought experiment, and imagine that C itself is just the language; and for a moment, imagine that it does have some modern standard library; only its modules are unfortunately somewhat scattered over "teh Internets", but probably just a quick googling away. And to see what comes out of that, and how "modern" one could actually make it feel.

Please bear in mind I'm not up to date with modern C. But this thread reminded me of some stuff I've glanced over here or there at some point, and made me wonder. Personally, I believe the result would not reach 100% high-level-ness of Go or the likes, but I have a feeling it might come uncomfortably near...

Re: Why I Write Games in C

#202
post #66

How about Nim? [1] [2] To me it is in many ways a "nicer and safer C". Sure it's not as mature as C, but what is? What it does have going for it is portability (it compiles to C so it shares C's portability), a soft real-time GC which can be manually controlled [3], generics, AST macros and much more. 1: http://nim-lang.org 2: https://github.com/nim-lang/nim 3: http://nim-lang.org/docs/gc.html#realtime-support

I wanted to recommend Nim elsewhere in the thread, too. For a lot of serious game devs, a language with a forced GC is often a no-go, for good reasons or bad, so that immediately eliminates a lot of potential candidates to replace C or C++. The only objections I frequently see people have with Nim once they look deeper into it are on syntax (not so much on indentation as on the symbol identifier rule -- case and underscore/dash insensitive except for the first character), current usability (not being 1.0), and expected longevity. Basically the same objections to Rust. (I think Rust can convert a lot of C++ game programmers eventually, I'm not so sure it can convert a lot of C game programmers because of the additional mental complexities in the name of safety, a low priority on a game dev's list.)

Re: Why I Write Games in C

#203
post #190

Earlier quoted context omitted.

[deleted]

Ah, now you've spoiled it! Somehow I have the feeling this game is even more effective when you think of it as a retro game, until you discover by yourself that this world is… not right .

Fixed. :)

Re: Why I Write Games in C

#204
post #170
post #105

>Even more than that I care about the speed of the compiler. I am not a zen master of focus, and waiting 10+ seconds is wasteful, yes, but more importantly it breaks my flow. I flick over to Twitter and suddenly 5+ minutes are gone. Quick suggestion, has really helped me: take that 10 or 20 seconds waiting for compilation, and stare out a window. This gives your eyes much needed break from focusing on a computer moni…

10 or 20 seconds waiting for compilation .. but more importantly it breaks my flow Luckliy the OP doesn't build for microprocessors etc. There you wait for compilation (of C, for instance) but than the damn thing has yet to be flashed.. Thing is, it actually learns you how to not let it break your flow. Which is a valuable skill.

Agreed. Now that I'm not doing things where I have to build and then flash memory, my workflow seems to fast!

Re: Why I Write Games in C

#205
post #171

Earlier quoted context omitted.

Maybe in ten years. Great thing about old mature technology such as C is that all gotchas have been tripped over innumerable times and are all well known and codified. Meanwhile new exciting technology like Rust contains unknown number of bugs like http://www.wabbo.org/blog/2014/22aug_on_bananas.html , undiscovered antipatterns and subtleties. My comment is not meant to bash Rust, on the contrary it is very promising…

That bug was almost a year before Rust 1.0 was released. At this point, Rust is being used in production outside of Servo- for example Dropbox is even using it for their core data storage code. It's certainly not as old-and-boring stable as C, but it's a lot closer than you'd think.

And that bug was less than a 1.5 years before now. And Rust is at version 1.5 now. And all changelog entries since version 1.0 (which was released 8 months ago) mention "multiple bugfixes". Of course, that's all subjective, but for me these facts all scream "rapid pace of development, expect multiple annoyances and a couple of major bugs for your particular use case".

Dropbox is using Rust in production? Great news! But I'll wait when a thousand of organizations use Rust in production before advocating its use in my own organization. Also, judging by this comment: https://www.reddit.com/r/programming/comments/3w8dgn/announc... they had incredible rapport with the language core team. That is a luxury not every team using Rust is going to have.

Still, great news. I guess I must implement some kind of little personal project in Rust and in the process help iron out a few more quirks.

Re: Why I Write Games in C

#206

Are GC pauses really significant? I can understand there being problems if you have to churn through gigabytes of world data, but the author's games don't appear to be on that scale.

They often are if specific care is not taken to minimize garbage in the game loop, particularly in resource-constrained environments like some console and mobile platforms [1]. In GC languages, this often means deliberately avoiding common idioms that perform allocation under the hood.

The threshold for a noticeable pause is much lower for action games than it is for general applications. 100ms is often used as a rule-of-thumb "instantaneous reaction" threshold for general UX [2], but that's a lot of time to a highly competitive player (e.g. this guy playing Super Punch-Out blindfolded [3]).

In fact, in high-reliability real-time software, even non-GC heap allocation is often avoided (or done once at startup and then left alone). Heap allocation is not a very predictable operation beyond "probably fast enough".

[1] https://stackoverflow.com/questions/5063190/game-jitters-on-...

[2] https://www.nngroup.com/articles/response-times-3-important-...

[3] https://youtu.be/vSr3aXd4XuQ?t=358

Re: Why I Write Games in C

#207
> I can't afford to spend my time dealing with bugs I didn't cause myself

It is very frustrating to deal with bugs introduced by others, a product or engine changes that you aren't aware of. But you have to balance that with how much you can get done in your own engine/tech with the time wasted from bugs, and how much time you want to spend on tech vs games.

For 2D games, building your engine is probably doable with lots of small kits like physics libs (box2D, bullet, etc), libgdx, sdl etc but for 3D games and certain titles, a single person working on an engine is difficult, tons of work on the tech side. So the balance is key, whatever makes you able to ship more often is probably the best choice.

Unity is used by many people and does have very frustrating releases that aren't solid many times. Recently 5.3, 5.3.1 [1] all have issues. For a long time in 2015 the IL2CPP iOS versions were broken. But doing it alone you get caught in a tech swamp instead of making games if you aren't careful and limiting. There will be times where your engine product or team or yourself is wading tech changes that are needed and take time away from game making. During the period of IL2CPP and Unity bugs, games could still be developed in parallel and for other platforms, so this is a benefit even though there are bugs.

Even when we do engine or platform based games it is a good idea to keep it as platform agnostic as possible. In Unity this might be keeping all source assets, using less MonoBehaviours, storing/loading data in JSON/web formats rather than in serialize prefabs. Anything that locks your game into one engine too much one should be careful of to limit your surface area of exposure to bugs by the engine. For a long time other UI libraries ruled Unity before they made their new UI, it is still a bit buggy but better. For a long time Mecanim was not very solid and many still use legacy animation. The newer Shuriken particle systems are awesome but not as accessible in code and had scale limitations for a long time. You just have to see where areas are solid and not venture into areas prone to bugs in your own engines or existing engine platforms for shipping games like Unity/Unreal etc.

[1] http://forum.unity3d.com/threads/unity-5-3-1f1-particle-syst...

Re: Why I Write Games in C

#208
The language wars get exhausting. Several years ago Ruby was the coolest thing ever, now I guess people think it's just boring. Also, PHP got really unpopular and all you heard about was how it would kill your dog and sacrifice it to satan. Now days it's still cool to look down on those who use it, but you shouldn't talk about it. Don't know know all "real" devs program in Python? Go was short lived, a year or two ago it was the greatest thing ever and now all you hear about is how much it sucks. The latest trendy thing is Rust. Rust is our new savior. I wonder how long that will last before something else comes along as the coolest thing ever. Maybe Brainfuck for it's simple syntax?

Re: Why I Write Games in C

#209

Earlier quoted context omitted.

Considering that vector, map, etc are widely used and expected features of software development, I would think that good libraries in C exist for these already, so you don't have to even write your own 100 lines. Are there any?

http://troydhanson.github.io/uthash/

This is one of the reasons why every time I get nostalgic about C I then immediately get depressed. Having to find the next level of functionality, libraries, all over the internet, just makes my brain turn to peanut butter.

I think this is one of the biggest disadvantage of a mostly standards based, no particular organization in charge type of language like C, as opposed to, say, python.

I am fortunate that, at the moment, my needs are mostly casual and very rarely performance focused. If I needed C I would just STFU and use C, accumulating my own workarounds for the dispersed nature of its resources.

Re: Why I Write Games in C

#210
post #169

Earlier quoted context omitted.

If Nim compiles down to C and then you compile/link that.. How in the hell do you debug that?

Nim seems close enough to C that you should be able to use the #line directive to map lines of C to lines of Nim source, keep variable and type names the same, and just use gdb.

Yep, that works well enough: http://hookrace.net/blog/what-makes-nim-practical/#debugging...
Post reply on HN