C in game development

Started by
35 comments, last by frob 10 years, 8 months ago

I am big fan of C, not so much devoted to c++.

Does maybe someone know how much widely used is old good (and fast) c in game development (in relation to c++ usage) ? In big games?

[And besides that are here maybe fans of C who much prefer it than c++

like me, here? Asking for curiosity]

Advertisement

I am big fan of C, not so much devoted to c++.

Does maybe someone know how much widely used is old good (and fast) c in game development (in relation to c++ usage) ? In big games?

[And besides that are here maybe fans of C who much prefer it than c++

like me, here? Asking for curiosity]

Not much at all, C doesn't provide any advantages over C++ these days when it comes to performance and has several disadvantages when it comes to security and productivity, C99 and C11 compiler support is still awful on Windows. (MSVC only supports C89) and using C++ still allows you to write c style code in areas where it is beneficial to do so.

[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

I am big fan of C, not so much devoted to c++.

Does maybe someone know how much widely used is old good (and fast) c in game development (in relation to c++ usage) ? In big games?

[And besides that are here maybe fans of C who much prefer it than c++

like me, here? Asking for curiosity]

Not much at all, C doesn't provide any advantages over C++ these days when it comes to performance and has several disadvantages when it comes to security and productivity, C99 and C11 compiler support is still awful on Windows. (MSVC only supports C89) and using C++ still allows you to write c style code in areas where it is beneficial to do so.

c offers a 'different style' - the main points for example

- procedural

- not using templates

- static arrays way

it has some advantages for me

You can do that in C++ too, so that's no advantage.

You can do that in C++ too, so that's no advantage.

This is c-way, And if this is both c and c++ (as a c heritage) I call it a c not c++ (c++ would be oop, templates, constructors and such stuff - way of writing)

[so here if I am talkimg about c, I think about such "c-way" of writing against "c++/oop way" of writing (coding)]

after that jump to my first question, is such procedural "c - style" coding present in this day big games debelopment or not too much ?

I'm like you. I prefer the style of code that comes from C. C++ of course can be used for the same style, but as soon as you start taking advantage of its features, using inheritance, virtual functions, templates, smart pointers, RAII... it's like the language is herding you toward a particular coding style. Which is fine, and I do like it for windowed apps such as my map editor. But for games, I like C.

It's hard to quantify exactly why. I think it's the same flaw in my brain that makes me want to use hand tools in woodworking rather than power tools. I know I could probably get the job done about just as well in less time other way, but it's more direct and satisfying the old fashioned way. It feels more freeform, plus you can get away with more hackerly mischief tongue.png

I wouldn't want to use C on a large and complex team project though (say an MMORPG). It's ok for reasonably small teams (2-4 programmers), but mostly I like it for solo projects where I have absolute control over every detail..

I do still use OOP in C. Make a struct, and a set of functions that go with it. It's just the natural way of things a lot of the time. But I use static allocation rather than dynamic as much as possible, which feels less natural in C++ most of the time.

But one of the main things I miss when coding games in C is weak pointers. Just not elegant enough to try to implement them without templates, so I end up using "dead" flags and clean up the carcasses on the next run through a list or whatever, rather than just deleting something on the spot and knowing that anything referencing it will be nulled automatically. Not a big deal, but just more to think about, whether you need to check if something is dead before interacting with it or whatever..

C does have a few indirect advantages:

it is easier for "mere mortals" to write parsers and compilers and similar for it (whereas a "reasonably complete" C++ compiler is a much bigger undertaking);

it has a simpler set of ABIs which are more consistent between compilers, making it a little more reasonable to interface with C from ASM or dynamically-generated machine code, ...

granted, some of this can also be handled via 'extern "C"' as well (so the tools can mostly ignore that they are interacting with C++), or via a C++ subset, but this has a few other issues (now it is more necessary to qualify which sets of features are supported, ...).

this is not to say that everything is perfect in C++ land, as on the internet, one can usually run into lots of (usually pointless) arguments about elements of coding style.

in C land it generally tends to be a lot closer to a "whatever goes" mindset. granted, a person can do so in C++, but then get hated on a bit more than if they did so in C, where one mostly just gets looked down on for using the "archaic" C language.

...


I wouldn't want to use C on a large and complex team project though (say an MMORPG). It's ok for reasonably small teams (2-4 programmers), but mostly I like it for solo projects where I have absolute control over every detail..

There is at least one large and complex MMORPG engine that is programmed mostly in C.

In a way, C is easier for a large team than C++ because there are fewer ways to obfuscate behavior, intentionally or unintentionally. It is a much smaller shared language to learn than C++. There is an advantage in not having certain features.

There are certainly large games that are filled with C-style programming, even with a C++ compiler. First, there's all the legacy code still around from before studios switched over to C++. Second, there are plenty of game programmers who still use C-style a majority of the time. Third, there are often style guides that help deter against templates and virtual functions.

In my experience with large software projects, the C-based ones have been easier to read for me than C++ projects. Maybe it's just because I'm better with C (though I learned C++ first and then went back to C). I think that it's due more to how programming in C is relatively more explicit. People can get fancy in C++ doing things automatically in destructors, assignment operators, custom memory allocators, templates, and all sorts of other language constructs that have potential for hidden meaning. In C there are some clever tricks with macros but even then I haven't worked on any code that really goes nuts there.

In C++ I often have to use a debugger to step into code to know what's actually being called, before even reading through the code I need to work with. In C I am usually able to grasp what's generally going on in a text editor before diving deeper into a problem.

I don't mind elegance when everything works, but if I have to look at a piece of buggy or slow code, I'd rather it be as dull and procedural as possible.

The following is going to be a bit of a rant. Before I start, my intention is not to offend anyone, everyone is entitled to their own opinion. With that out of the way, here is my story:
I used to do all my game/engine development in C++, but switched over to C about 1.5 years ago. I can say with great certainty I will never go back to C++ (for indie work).
My reasons for choosing C have nothing to do with performance, dislike for OOP, or the need for a standard ABI. My reasons are purely social and empirical. Here are some of them:
The C++ Community:
I find the C++ community to be ridiculously divided on what is "proper" C++. I can't tell you how many times I've read posts criticizing the subset of C++ chosen for a project. "Oh, that's not C++, that's C with Class!", "Why aren't you using templates?", "Manual memory management is for grandpas, hipsters like me are using smart pointers!", and it goes on and on... Is proper C++ boost style with template meta-programming everywhere, IsItJustLikeJavaWith = new UsedEverywhere?, is it c_with_classes_style, etc... I think the chaos among the C++ community is merely a reflection of how large, divided, and diverse the design of the C++ language is.
Let me end this argument once and for all: If the code compiles with a standards compliant C++ compiler, then it is C++. Period. End of story. Just because you don't like the subset chosen, does not mean the code is not C++. There is no such thing as "Modern C++" or "Modern Java", "modern" is just a buzzword used to sell you on said individuals favorite subset.
C++ Design:
One of the philosophies of C is to trust the programmer. This rule is broken numerous times in C++. The fact you have to cast between pointer types just creates unnecessary noise in the code, nothing more. The fact you have to prefix the implementation of a class's method with MyClass:: is dumb. Objective-C got this right by allowing you to wrap your class method implementations in a @ClassName { } block. Seriously, prefixing the class on a method is data redundancy. It is not simple, it is not minimal, it is not DRY. I'm sure some developers think that because their typing more code their solution is better. This is not true and C's idioms encourage the complete opposite of this.
C++ requires lots of boilerplate. When I write C++, I end up spending about 40% of my time in the header file and/or writing boilerplate. With C its about 5%. Because of this, I do find myself developing faster in C than I do C++. If you find C slow to develop with, it could be because your using C for a task which would be better suited to another language or you just don't understand C idioms and are trying to apply Java/C++ idioms. For engine development, I never once felt the need for C++ features once I understood C's idioms.
Simplicity and the C community:
C is simple, small, and elegant. The C community encourage simple designs and solutions. This is one of the big reasons to not use C++. I see most C++ developers creating over-architected solutions. For a humorous example of this, check out enterprise fizzbuzz. I notice there is a lot of reinventing of the wheel among the C++ crowd, not so much with the C crowd. The majority of C++ libraries I have used proudly roll there own strings, containers, data structures, and often ignore the C++ standard library. In my experience, C programs and libraries tend to use the C standard library and 3rd party libs instead of rolling their own solutions.
C requires very little boilerplate. When I write in C++ I find my train of thought is constantly broken. When I write classes, I have to constantly switch between .h/.cpp files, I have to constantly repeat the class name in front of every method, etc... These interrupting tasks take my mind off the solution at hand. Contrast this with C where I can focus on solutions instead of boilerplate.
One more thing:
I am not Linus Torvalds, I do not believe that C should be used everywhere. You should use the right tool for the right job. I love using C for the low-level audio, graphics, and input handing (the engine) and a high-level scripting language for the AI and GUI (the game).
I hope this has given you some insight into my decision to use C instead of C++. I'm sure there are many C++ programmers who do not over-design, but my experience tells me they are the minority (either that or their not loud enough).
TL;DR The C community is abundant with simple libraries, simple APIs, and simple solutions. There is very little to no bickering over the proper language subset and very little reinventing of the wheel. C requires very little boilerplate allowing you to focus on solutions uninterrupted.


Does maybe someone know how much widely used is old good (and fast) c in game development (in relation to c++ usage) ? In big games?

In the United States, at least, the primary language used for AAA games right now is C++. If you want to make AAA games, you should be comfortable using C++. If you do not wish to use C++, this is going to really limit your options.

Many studios tend to favor the use of composition over inheritance, and Entity Component Systems are very popular (http://en.wikipedia.org/wiki/Entity_component_system). Some studios have, in recent years, moved towards a more "functional" style of C++ programming (http://msdn.microsoft.com/en-us/magazine/jj553512.aspx), so it is worth being conversant in recent innovations in that area.

However, many people are completely abandoning C++ for non-AAA projects. OO-languages are still fairly dominant, but really, your options are pretty wide open, if you're working on indie games.

This topic is closed to new replies.

Advertisement