C vs C++ features

Started by
9 comments, last by freddyscoming4you 12 years, 7 months ago
Listening to the dotnetwrocks pod cast here: http://dotnetrocks.c...spx?showNum=695

Kate talks briefly how people are actually using C rather than C++ with things like using malloc rather than just newing an object or using smart pointers. Is using the older methods for these things preferred for game development or are people just being newbs and not realizing what tools they have at their disposal?
Advertisement
I think that a C# podcast is about the last place I'd go to find out what "most" C and C++ programmers are doing.

throw table_exception("(? ???)? ? ???");


I think that a C# podcast is about the last place I'd go to find out what "most" C and C++ programmers are doing.


This.

While it's true many "C++ programmers" do just use it as "C with classes" there is also some logic to using malloc to reserve large amounts of memory before doing placement new to put your objects in it.

Same with smart pointers; not every allocation needs them (and frankly most people are Doing It Wrong(tm) with their constant abuse of shared_ptr anyway) and if your classes are designed in certain ways you can completely forego them.

They are all just tools after all.
"Nobody knows what most C++ programmers do." - Bjarne Stroustrup

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

On 9/6/2011 at 3:03 PM, ApochPiQ said:

"Nobody knows what most C++ programmers do." - Bjarne Stroustrup

...nevermind, why they do it.

Maybe they're "noobs". Or maybe they know something we don't.

So it's like calculus... excellent. LOL
Maybe they're just following Google's C++ Style Guide which pretty much mandates using C-with-classes.

After all, if 1991 is Good Enough For Google, it should be Good Enough For You.

Stephen M. Webb
Professional Free Software Developer

On 9/6/2011 at 1:52 PM, freddyscoming4you said:

Listening to the dotnetwrocks pod cast here:http://dotnetrocks.com/default.aspx?showNum=695

Kate talks briefly how people are actually using C rather than C++ with things like using malloc rather than just newing an object or using smart pointers. Is using the older methods for these things preferred for game development or are people just being newbs and not realizing what tools they have at their disposal?

Disclaimer: I haven't listened to that podcast, so I don't know what they said, what they were trying to say, or what they meant. This is just some generalization in response to the OP...

C++ is a super-set of C, which makes malloc() a legitimate C++ feature. Ok sure, using malloc like this,


myClass * pMyObject = memset(malloc(sizeof(myClass)), 0x00, sizeof(myClass));

is likely just a failure to use the appropriate language feature, but then so is using new in this case:


void * pBuffer = new char[Buffersize];

While C++ provides a better approach in a lot of cases, those new options don't completely replace everything that already existed. Sometimes you really do just need a memory buffer (e.g. when loading a binary file, or in a memory manager).

That being said, that's probably not what you were getting at.

So to answer the question, I'm not aware of anything about video game development which would make it preferable not to use the standard language features. I can, on the other hand, think of some areas of general confusion.

  • There is the lingering doubt that game consoles might not support advanced template features. See my recent post about that here.
     
  • Game platforms don't generally supply "infinite" paging memory. This means that game developers need to be more careful than some about how they handle dynamic memory usage. Which in turn may lead some to manage all dynamic memory usage with custom allocators. And hence they might consider spurious uses of "new" to be a sin (although, obviously they'd have the same problem with "malloc").
     
  • Legacy code-bases and practices seem to make game development groups less likely than most to use STL. But it could also be argued that others over use it in ways that don't add value to their code-base. (Similar situations exist with RTTI and exceptions)

The other relevant issue is that management in the games industry tends to be abysmal (although perhaps I don't have enough experience outside the industry to appreciate how truly mediocre it actually is). Technical decisions are often made by people with no understanding of the issues at hand, which frequently results in hurried development on top of aging code-bases. There are undoubtedly many, many situations in this industry in which engineers are working with code full of outdated, sub-optimal, and uninformed techniques, practices, and conventions.

But back to your question, these are definitely not preferred.

As said before, I prefer the malloc... functions for dynamic memory. I use C++ as C-with-classes, and I think that's just perfect.

Ok, I listened to a little bit of the podcast and got the gist of what was going on. She was just trying to enumerate all the different types of programmers out there who still use Visual C++, and why the statistics show that, despite all the hype (from the likes of these podcasters), managed languages have yet to surpass its usage.

She mentions that there are people writing very small programs, for custom built embedded systems, who still program in C.

She mentions "C with classes". This was the precursor to C++ when people started writing custom precompilers for object-like support on top of C. The precompiler would recognize the extended features, and translate them to straight C and pass the result on to the C compiler. I think that when she refers to people doing "C with classes" now in C++, she's talking about not using class features at all and just trying to make code object-oriented-like by grouping together structure definitions with functions that perform actions on those structures. That's the type of coding that actually led to C with classes.

The only people who really do that now are the ones whose careers were well established before the proliferation of C++ and have somehow managed to stay insular enough for the last two decades (plus) to not have to change their ways to work well with others or execute really large projects. There are very, very few who can get away with that in this industry which has a relatively young demographic and typically sizable engineering teams. Anyway, I think she only mentions this as part of demonstrating the "many flavors" of C that exist.

Then she floats her opinion that C++ programmers who actually ever call delete on pointers rather than using some sort of smart pointer to hide/auto-delete the pointers, or who ever decide that C++ streams are not the right way for their program to interact with the outside world, are not "real" C++ programmers. I guess she was just trying to out-douche the podcast clowns.

Anyway, the only mention of the video game industry (that I heard during the part of the discussion I sat through) was that it's one of the reasons that C++ is still so relevant. I don't think there's any reason to infer a trend in the industry of not living up to her expectations of C++ programers. And if anyone doesn't, I don't think it would be fair to say that it's because an antiquated style is preferred in the industry.

This topic is closed to new replies.

Advertisement