Live data from Hacker News

Why I Write Games in C

jonathanwhiting.com

231–240 of 303 posts

Re: Why I Write Games in C

#231
post #118
post #78

Earlier quoted context omitted.

I am in some ways the same, but the other way around. I like Python-like syntax more than C-like syntax. But not to the same extreme as you, I wouldn't mind using a language with a C-like syntax. What are your reasons for disliking Python-like syntax?

I want strong visual cues for the end of blocks most importantly. And I want the freedom to adjust indentation in ways that to me improve readability without consideration of whether or not it matches language expectations. But also because I've yet to work in any environment where broken indentation due to tools with different ideas about how to handle it has not been a regular occurrence - indentation is brittle.

I think Haskell gets whitespace-sensitive indentation right. It is a lot less strict than Python, and if you didn't know it was whitespace-based you wouldn't necessarily realize it. Thanks to the functional nature of the language, the "hanging block" problem you have in Python (where the lack of an explicit end construct has blocks indent but never "close") doesn't really exist.

Re: Why I Write Games in C

#232
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 is great for a certain class of games. But I've played plenty of games that were developed with Unity, where the dev quite obviously strong-armed the engine into doing what they wanted, and what you end up with is a slow, stuttering game that would likely run 10X better if they had used a different engine, or even just a renderer with some middle-ware.

Also, think of the most successful indie game ever made (Minecraft). It was written in Java (a much maligned language, wrongfully IMO), with a very thin framework (Lwjgl), and it's made its creator a billionaire.

If you're doing a game in a relatively mature genre, then yes, engines are great and will save you a ton of time. However if you want to do something completely outside the box, sometimes you save a lot of headache by just simply writing it yourself.

Re: Why I Write Games in C

#233
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.…

Yep. Then you can control the complexity.

It's not for everybody.

"Containers" are actually quite easy without bespoke libraries in 'C'.

And sorting is built-in.

A simple example: http://www.codeproject.com/Articles/108830/Inheritance-and-P...

Throwing languages at problems is in itself a Tower of Babel problem. We need to emphasize mechanism and not tools. But people gain reputation not by producing correct implementation but by leading revolutions against the status quo.

Re: Why I Write Games in C

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

Just make sure that nothing interesting is happening outside otherwise you will loose focus watching that :).

And if I remember correctly then focusing close for a long time doesn't affect your vision but can cause headache.

Re: Why I Write Games in C

#235
post #54

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…

BAH! 4. The "intrusive" containers, but of course. The one true way to do it in C. For one, you can keep items in multiple containers, all being on equal footing. None of that typical C++ mess, when this list is a primary storage for items, and those maps are secondary indexes, all sprinkled evenly with iterators. Intrusive containers don't own items, they merely organize them, which is exactly the right way to go ab…

I use this method but never heard that name before. Many uses are unfortunately not type safe, although it is possible to use a combination of macros and inline functions to get type safety with this method.

Re: Why I Write Games in C

#236
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.…

> their own private code framework that is too complicated for anyone else to make use of Well, to be fair, games are one place where code reuse and maintenance by third parties is less likely to be needed. The real sadness is when you get corporate websites, technology platforms, and the like that decide they need their own framework to make their own set of tradeoffs, and do a mediocre job of it, and end up with a…

I am relatively sure that we've lost the code reuse wars outright. The problem isn't Yet Another Framework. the problem is mediocrity itself.

Re: Why I Write Games in C

#237

He mentioned a bunch of languages, and I'm not sure why he doesn't look into something like Kotlin. It's the JVM so you get maturity and it's fast as hell (ran a few economics-related benchmarks on my machine, OpenJDK 8 beat both C++ and Fortran!), has great IDE support (Intellij IDEA - which will actually translate Java into Kotlin if you want to translate snippets), and it doesn't strong-arm you into an OO style. A…

Making games on the JVM is a lot of fun, but the garbage collector does limit what you can do (the OP mentions this as one of the drawbacks of Go).

Re: Why I Write Games in C

#238
To me lambdas justifies using C++ while still coding in a C style.

Although my wet dream would a C language with map, vector and other containers, a simpler build system (no more headers), more nice syntactic sugar, and an interactive mode... I'd gladly see a language that break C compatibility for this.

Re: Why I Write Games in C

#239
post #141

Earlier quoted context omitted.

When you drop the semantic silliness of C++, like having the container to take care of constructing, copying, moving, and destructing, not to mention exception safety, a basic implementation of a "templated" dynamic array implementation in C comes down to like 100 lines. Hash map will be a bit more, and is not so trivial to write. It's true that there should be no need to write these things yourself. The alternative…

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?

Hashmaps to the side ( that's more challenging in 'C' and one really compelling feature of C++ ) the rest can frequently be "faked" with arrays. Obviously, scale matters - having fifteen "vector" implementations in a given system means a little bit of library-ness is in order.

Much also depend on how much you really need dynamic allocation - it can be optional.

Re: Why I Write Games in C

#240

He mentioned a bunch of languages, and I'm not sure why he doesn't look into something like Kotlin. It's the JVM so you get maturity and it's fast as hell (ran a few economics-related benchmarks on my machine, OpenJDK 8 beat both C++ and Fortran!), has great IDE support (Intellij IDEA - which will actually translate Java into Kotlin if you want to translate snippets), and it doesn't strong-arm you into an OO style. A…

I've been meaning to get into Kotlin and building a game sure sounds like fun. Are there any Kotlin specific game programming frameworks (or any other resources for that matter) that you'd recommend?

Well Kotlin is basically a drop-in replacement for Java. You can literally create a Kotlin project in Intellij IDEA (Community Edition), drop in some jars (and compiled native lib if required), and you get full completion to every class, and everything 'just works'.

So the obvious choices would be LibGDX and Lwjgl 3 (which is written mostly in Kotlin). As for tutorials, it's close enough to Java that you can rewrite anything pretty much word for word (albeit with a slightly different syntax), and there's a Java -> Kotlin translator in IDEA. It keeps the semantics very close to Java, but with some sugar and niceties. It really is the 'Java replacement' that languages like Scala and Ceylon attempted to be.

Post reply on HN