3 ms·
Gotta disagree with you on some of this. On point 1, I see nothing wrong with this: list<Puppy> cutelittlepuppies; ... BOOST_FOREACH(Puppy p, cutelittle
by yummyfajitas 19y ago
Gotta disagree with you on some of this.
On point 1, I see nothing wrong with this:
list<Puppy> cutelittlepuppies;
...
BOOST_FOREACH(Puppy p, cutelittlepuppies){
p.pet();
}
Use typedefs for more complex templates. My rule of thumb: if it's faster to read and understand the template than to find the typedef, don't use a typedef.
As for the allocations (point 2), not usually a big deal outside of games. The added safety is worth the performance hit.
- palish 19y agoBoost is nice, but it would require too much time for the original poster to set it up and to learn how to use it. He's almost completely new to C++ and would like to be productive within a month. Realistically, there about 22 work days per month. Since setting up Boost for the first time is an all-day affair, that alone is almost 5% of his time. Would that time investment really provide more than a 5% return? Not only that, but using Boost results in non-portable code. Boost could be the reason that your game cannot be ported to the PS3 or to the XBox 360 platforms. (Both STL and Boost can also consume a lot of precious memory on those platforms.) Also, there is still a huge market outside of games where it isn't necessarily a good idea to use STL and Boost. Embedded systems, flight simulators, so on. How do you know that STL and Boost compile to equivalent code when your compiler isn't GCC or Visual Studio? So Boost limits your options and it is debatable whether its productivity return is greater than its cost. In that light, why is it a good idea to train yourself to depend on it? If you take a job at a company where Boost is not an option, you will: - be forced to not use any code in your personal library that references Boost. - be forced to expand all of the BOOST_FOREACH() statements into for( std::list< Puppy >::iterator ... ). (Also, you left off the std:: on "std::list". I'd like to mention that "using namespace std" is a bad idea.) Because of that, typedef'ing each STL container before using it is a good idea. As for finding the definition of the typedef, the definition should almost always be within the same class that uses it. If you install Visual Assist you can use the "Go To Definition" feature (Alt-G) to warp directly to the typedef's definition. If you're forced to use C++, I assert that you can be more productive, portable, efficient, and reliable by avoiding Boost and most of STL.