How many of you use C for game programming?

Started by
107 comments, last by Washu 13 years, 1 month ago

'francoispress' said:

Amazing how big this thread got. Anyways, here are some stats from a projects I did in the past, a level editor:

C: 400 lines of code
C++: 1200 lines of code


C++ being a superset of C (yeah… I know. Let's just pretend), 800 lines of your C++ program were superfluous, or you implemented additional features. :P
Even if you didn't mean to implement new features you probably did: Type safety, buffer overflow protection, …
Let me get this straight, I'm in no way a C++ fanboy but the neverending C++ bashing gets a little on my nerves. There is no such thing as a perfect language, only different tools for different jobs.


Someone's mad! Anyways, most of this extra code seems to be accessor functions and such. Not necessarily extra features.

Codeloader - Free games, stories, and articles!
If you stare at a computer for 5 minutes you might be a nerdneck!
https://www.codeloader.dev

Advertisement
Personally I do prefer C++ over C, even though the current project I'm working on is in C. Mostly because of C++ constructor and destructor mechanisms, but small things like passing by const reference, namespaces, encapsulation and exception features are a real treat. Also, perhaps I'm one of the few people on this world who likes C++ using templates. I use OOP, but I don't go overboard with it. I think OOP can become quite convoluted and detrimental at some level, especially when your inheritance graph becomes large. So I just stick with just a handful of design patterns that work well and don't complicate things too much.
Latest project: Sideways Racing on the iPad
I'm currently writing a bunch of software in C, chosen for political reasons. It is taking me weeks to write something that would take a couple of days for me to do in C++. Much of the time is taken up reimplementing stuff that is handy and available in the C++ standard library, which necessitates writing the accompanying unit tests and fixing plenty of bugs due to the lack of type safety and compile-time checks, and also due to reasoning on how to properly perform error handling and unwinding. This is professional low-level production-quality code, so I can't just do the usual C trick of ignoring errors and resource allocations. Keep in mind I have 30 years professional experience writing C code and only 20 years professional experience writing C++ code (and the latter language has changed a lot over 20 years).

I would never choose to write a game in the C language: it would never get finished. I would still be stuck reimplementing all the dynamic containers and tree traversal algorithms that come for free with C++ and boost.

Oh, and the frequent argument here that people write bad code in C++: heh, people write bad stuff in any language. That's not an argument against using the language, it's an argument against paying the writer.

Stephen M. Webb
Professional Free Software Developer

People only prefer C over C++ when they don't know how to write idiomatic C++ code. C++ provides constructs that address the most glaring and painful flaws in C, such as shared pointers and containers over manual memory management, standard types such as std::string over raw char arrays, type-safe variants of C preprocessor features, and constructors/destructors/RAII over manually calling Init()/Release() pairs, which is prone to breaking invariants.

The best way to write code is to design it so that there is no *possibility* of errors, rather than trying to ensure that you've accounted for all the things that might cause one. Rather than writing documentation, doing code reviews, and memorizing the fact that you *must* call Init() and Release() on your data, it's far easier and safer to utilize language constructs to ensure that there's no possible way to *not* call them. C++ provides features to make such programming easier than C. Of course other languages take it further than that, which is why I don't think C++ is all that great a language, but trying to argue that C is somehow better in any situation other than a few niche domains is simply foolish ignorance or willful stupidity.
Mike Popoloski | Journal | SlimDX
Linus Torvalds (somewhat angrily) on the subject: link

EDIT: Also here.
Will Miller | Game Designer | Big Huge Games

Linus Torvalds (somewhat angrily) on the subject: link

EDIT: Also here.


Um, I'm not an expert and lazy to copy that into google, but isn't that the Finnish idiot Linux guy?

Linus Torvalds (somewhat angrily) on the subject: link

EDIT: Also here.
There's nothing of value in those posts. It's a religious tirade by Linus and nothing more. he's stuck in his old mindset, and he's doing a different type of work than most programmers, who are writing user software, and not kernels, or anything at the system level. Also, the type of stuff Linus and other C++ detractors use as arguments against the language are really just arguments against bad programmers.

To the OP: There is nothing wrong with using C for your games. C is still a perfectly fine choice of a programming language, just like all others. But it may start to hold you back a bit once your skills progress, and you need to start re-implementing features that every other language will give you for free out of the box.

Also, implementing that stuff on your own will only result in something that is likely plagued with pointer and memory errors. It's a classic trap to fall into. The days when everyone was independently solving all these problems on their own were the days of horribly insecure and unstable software.

Almost everything in the old C standard library has been declared as insecure, and has been replaced with safer alternatives. Like strtok() is now replaced with strtok_s(). Most times when people say that they can handle these things on their own easily, they write software that is 95% likely to halt with a protection fault of other similar type of error.

Modern C++ (and other modern languages) give you all kinds of options to handle these problems so you don't have to. Then you can focus on getting your actual software done, and not have to spend time solving these problems that you shouldn't have had to even think about in the first place.
I talk for myself...Personally, I don't have much reasons to use C. I use C++ for my current project, for all the "goodies" that come with it, but have taken the decision to not bloat it with unnecessary meta-programming stuff that are hell to read(for me anyway). I use it for the SC++L, some of boost, RAAI and that sort. And I will probably use C# for some editor/GUI things. I just don't have any reason for C, atm.

People only prefer C over C++ when they don't know how to write idiomatic C++ code.


That's simply not true. There are plenty of us who both know C++ well, and still prefer C. In my case, in fact, I think it's *because* I know C++ well that I prefer C.

I've been coding in C since the early 80s, and C++ since around 1989 or 1990. I develop professionally using both (as well as other languages), and I can and do use C++ in an "idiomatic" way, including RAII, use of the stdlib, etc.

I still very much prefer C over C++. In fact, it's not even close.

Sure, there are things that I like about C++ in theory, but in practice, C++ is such a muddled and overcomplicated mess that I'd rather just avoid it.

but trying to argue that C is somehow better in any situation other than a few niche domains is simply foolish ignorance or willful stupidity.


With all due respect, that's a rather simplistic and close minded attitude. They're tools, and, as such, suite individuals better or worse in turn.

People only prefer C over C++ when they don't know how to write idiomatic C++ code.


That
is simply foolish ignorance or willful stupidity.




"You insulted me!" I did not say that in the private message Tom Sloper!

This topic is closed to new replies.

Advertisement