STL why's and why not's in game programming

Started by
28 comments, last by _the_phantom_ 19 years, 4 months ago
Quote:Original post by Koshmaar
Sorry, I meant: we want MORE profesionalls ;-)


OK, I'm a professional so I guess I'll chime in :)

First, I'll give you some background. Most of the projects I've worked on were console titles. On these projects using STL in game code was forbidden and the use of templates was kept to a minimum. However, the last project I worked on was a PC title and the STL was used a lot and templates in custom code were used quite a bit more, and in more exotic ways.

Before I get into talking about the details, I think it's important to note that when people say they do/don't use the STL they're mostly referring to the STL's containers. I don't think most people have a problem using the STL algorithms, for instance. So, effectively, when you choose to use the STL containers(or not) you're deciding how you're going to hold and access most of the data used in your game. Which is a pretty big deal.

Now, one of the big differences between these projects is that on the console titles we used multiple compilers(VC6, SN Systems, Code Warrior, etc) on a single project for the different platforms. This, by itself, is one of the big reasons that the console guys tried to avoid using the STL. Since the implementation of the STL is different with each compiler it means that the way you store and access your games data on each platform is going to be different. This makes development much harder since you can't do something on one platform and expect the same memory usage, performance, etc on all of the other platforms. Also, we did much of our development on the PC for quicker iteration times. On the PC we used VC6, which had horrible template support and a it's implementation of the STL wasn't very good. And that pretty much put the nail in that coffin.

In stark contrast, on the PC title we only had one platform to support and it was the same platform we worked on every day. This meant we could use the STL containers and see their effects on speed and memory use easily. Furthermore, we started with VC7 and upgraded to VC7.1 early in the project, which has really good support for templates and a pretty nice STL implementation.

In the end, like the use of any tool, I think it pays to be pragmatic. There's no clear-cut answer for anything. And I think the choice to use the STL or not on each of the projects I've worked on was probably the right choice.

On a final note, one thing to think about is that when it comes right down to it, 99% of the general container use in any game will consist of arrays and linked-lists. Sure, you might need the occasional map/hash-table, set, and maybe a queue here and there. But, the bread and butter are your arrays and lists. And, as luck would have it, if you find that the STL won't work well for most of your needs it's not very hard to make your own array or list class :)

-John
- John
Advertisement
I agree that you should stay away from STL when multiple compilers/platforms are involved, due to implementation issues. However, to not use things like std::string, std::map, etc just because you think you can do a better one and you think its too much overhead is just silly. I wonder how many java programmers refuse to use java.lang.String because they can do better?
Although I use std::string, I've implemented my own linked list and trees. I can't stand the syntax of most of the STL stuff. It's absolutely vulgar.
Quote:Original post by GroZZleR
Although I use std::string, I've implemented my own linked list and trees. I can't stand the syntax of most of the STL stuff. It's absolutely vulgar.


There must be a very fine line between vulgar and elegant...
Quote:Original post by GroZZleR
Although I use std::string, I've implemented my own linked list and trees. I can't stand the syntax of most of the STL stuff. It's absolutely vulgar.


You have to get over that. Are you going to rewrite OpenGL or DirectX because you think the "syntax" is vulgar? What happens if you are work on a team and another person writes vulgar code? Are you going to rewrite all his/her code? What happens if that other person thinks your code is vulgar? A war would break out and the project would never finish because it would be endlessly rewritten.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
Quote:Original post by JohnBolton
Quote:Original post by GroZZleR
Although I use std::string, I've implemented my own linked list and trees. I can't stand the syntax of most of the STL stuff. It's absolutely vulgar.


You have to get over that. Are you going to rewrite OpenGL or DirectX because you think the "syntax" is vulgar? What happens if you are work on a team and another person writes vulgar code? Are you going to rewrite all his/her code? What happens if that other person thinks your code is vulgar? A war would break out and the project would never finish because it would be endlessly rewritten.


I've been in the middle of wars like that, one guy has one coding standard, another guy has another, and no matter which I do, the other would be pissed about it. If you can't deal with reading code in a format that you don't like, you will never make it as a professional programmer.
In my private project I use STL a lot but I certainly don't use boost. The reason is that I have found that these open-source libs are mostly a pain in the ass more than a convenience. If I would have to move the project to a new computer I don't want to install 1000 libs and install another 1000 support libs.
just out of intrest have you even tried boost?
The part I use the most, boost::shared_ptr, doesnt need libs, its just a header file, hardly a hardship to set it up when you are doing any other libs etc

tbh, I think its foolish to dismiss a library, certainly one as usefull as boost simply because it might require alot of work to switch system... but then again, maybe ignoreance really is bliss.. *shrugs*
Quote:Original post by _the_phantom_
just out of intrest have you even tried boost?
yes

Quote:Original post by _the_phantom_
The part I use the most, boost::shared_ptr, doesnt need libs, its just a header file, hardly a hardship to set it up when you are doing any other libs etc

I wrote my own shared pointer which I can debug if there is a problem.

Quote:Original post by _the_phantom_
tbh, I think its foolish to dismiss a library, certainly one as usefull as boost simply because it might require alot of work to switch system... but then again, maybe ignoreance really is bliss.. *shrugs*
Well that's your opinion and I am entitled to my own without being called ignorant or rated down.
Quote:Original post by balla_the_king
Quote:Original post by _the_phantom_
just out of intrest have you even tried boost?
yes


ok, and which part of it was 'alot of work requiring 1000s of libs' to install? [smile]

Quote:
Well that's your opinion and I am entitled to my own without being called ignorant or rated down.


The ignorance thing was because you've made a claim which, frankly, is wrong, at worst boost requires python to be installed for the python bindings, but given they are optional thats a non-issue. Heck, you dont even have to compile the bits which are libs are libs, they can be just compiled into your project as needs be.
As for the rating comment, if you did get rated down it wasnt me [smile]

This topic is closed to new replies.

Advertisement