Live data from Hacker News

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

jonathanwhiting.com

161–170 of 288 posts

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

#161
post #150

As a hardcore C programmer and zealot myself... How in the hell can you be productive like that? C is a systems programming language, not an application programming language, let alone relevant to the levels of abstraction you'd want in game development. That said, "I am dead" is a very real video game indeed... and his arguments are very sound. I also can't stand C++. I disagree with him on Java though. The core lan…

> The core language of Java is actually super simple, like C. Not being facetious, but couldn't you say that about almost any language? What makes you say it about Java?

I'm not sure you could say it about C++, Scala (Java's C++) or Rust?

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

#162

Yes, C. Like all id games up to... Doom 3, if I'm not mistaken? Only then they switched to C++. There's absolutely nothing impressive about this fact.

Nobody claimed it was impressive. It’s a little unusual to use C instead of C++, but that’s about it.

It's impressive these days when software quality and craftsmanship is declining.

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

#163

I need RAII and refuse to debug ugly macros as a workaround. The STL isn't perfect but it's a good guiding principle.

You should try writing something serious in C just for the hell of it. And without RAII-like macros. Write all your allocs and frees.

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

#164

Plenty of people cycle on a fixie too. So what? C, especially modern C, does provide metaprogramming and abstraction facilities. In practice, you can even get things like the "defer" construct from other languages: https://lwn.net/Articles/934679/ The question isn't "Can I write a game in C?". Yes, of course you can, and it's not even that painful. The question is "Why would you?", and then "Why would you brag about…

If he doesn't use C++ features then there's no point of bothering with C++ at all. C++ is kinda but not really a superset of C. There are some nice features that are lacking in C++. The fixie example wants to make the comparison that using C instead of C++ is deliverately done just to brag about doing something in a way that is more difficult than in should be. In reality the issue is that C++ might not offer you any…

Usually you start with just one feature, like std::map instead of OpenSSL's abomination of a hashmap library or rolling your own.

Of course you should use std::unordered_map instead of std::map because the latter is actually a treemap, but you probably don't know that when you first learn it...

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

#165
post #149

Earlier quoted context omitted.

Nothing about a dopamine hit out of it, no. Something about _main being an undefined symbol. Are you familiar with that error message?

How did your equivalent assembly program without a definition of _main to? You're doing that thing. I think it's called "trolling". It goes like "hurr durr, they said take one, but they wouldn't let me take one plate" or "hurr durr, I filled my gas tank with nitrogen, which is a gas, but my car doesn't go" or "hurr durr, they said C++ features are all optional, but I don't want to use letters, how can I write C++ wit…

> your equivalent assembly program

Right now,

    hlt
    jmp $0
I intend to add more later, of course, but I until I get past this hurdle I am unable to start. Does that help narrow things down for you?

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

#166
I also use C, for games and other stuff. However, for many games it can be useful to have a game engine, which is written in C (and I might write it by myself) but other parts will be written in the game engine. I also sometimes program games on DOS, and will use BASIC or Pascal. You will then not need to have too many dependencies; if it is a DOS program then the executable file should just work (with emulation if necessary) without the mess that is common on modern computers.

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

#167
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 carries around that vtable pointer even if it goes nowhere near that 10% of the system. This way your Bird code "just works" in C++.

That's not the only way to crack this nut. Idiomatic Rust approach uses vtables only in the Bird code, elsewhere they don't exist, and thus don't take up space in a Duck or whatever that's always a Duck, but in exchange now you're spending more time thinking, because by default there aren't any vtables and so dynamic dispatch isn't possible at all.

So while that C programmer has to implement features by hand, they are at least able to specifically implement the feature they wanted, not whatever was easiest for Bjarne Stroustrup last century.

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

#168
this is refreshing. personally i do all my hobby stuff in C or Python. I could certainly use c++ if i wanted to but templates and cin/cout were such monumental jokes how can i trust the rest of the language? i too have contemplated writing my own language but to paraphrase the author, id rather make games than languages and C/Python are good enough.

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

#169

Earlier quoted context omitted.

Contrary to popular belief C++ isn't really object–oriented. I mean, you can write object–oriented code, but the language doesn't make assumptions about what goes into a class. It's really just a struct with associated functions.

That's an odd opinion about a language with a lot of class related features. I can only assume you have a very strong definition of OOP.

OOP doesn't mean that your language has a "class" keyword, nor dot notation for calling functions.

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

#170

I want to write general apps in C. Such as a raster image editor. I have some idea and C has exactly the right mix of simplicity and flexibility that I need. C is a constructor, and as a constructor it places few limits on what you can do. Other environments are way more rigid. E. g. I find Python way too rigid compared to C.

GTK apps can be written in pure C. GTK itself is.
Post reply on HN