Slashdot is powered by your submissions, so send in your scoop

 



Forgot your password?
typodupeerror
×
Programming IT Technology

Downsides to the C++ STL? 1046

craybob queries: "I'm a developer for a small software group that will soon migrate from using Rouge Wave to using the C++ STL. I just left the week-long Software Developers 2002 conference, where I heard the great minds in software tell us all of the best ways to take full advantage of the STL. (I just wanted to give a quick thanks to Stephen Dewhurst and Scott Meyers) From this I came away with the feeling that this is the Holy Grail of C++. I'm sure these guys are right and that it is great, but the truth is that I'm a skeptic, so what are the downsides to the STL?"
This discussion has been archived. No new comments can be posted.

Downsides to the C++ STL?

Comments Filter:
  • by jsonic ( 458317 ) on Monday April 29, 2002 @02:18PM (#3430711)
    but the truth is that I'm a skeptic, so what are the downsides to the STL?

    It's written in C++? :)

  • by Anonymous Coward
    For one, any vendor can provide his or her implementation, which can lead to some amount of uncertainty in terms of performance..
  • Drawbacks (Score:2, Informative)

    by EEBaum ( 520514 )
    On the whole, the STL is fantastic. The only drawback I've found is a lack of standardization across implementations. Specifically, if you want to remove an item from a vector/map/list, and keep iterating through it afterwards, the end result is somewhat unpredictable.
    • Actually, like with most things, you have to understand the reasons and methodologies. In the cases where you are using the linked-list-like structures (e.g. not vector) you are warrented several things:

      1) any iterator will remain valid if it is untouched.

      2) any iterator not directly involved in an erase will remain valid across the erase.

      3) any iterator directly involved in an erase will be erased and so invalid (therefore MyList.erase(cur++) is always illegal)

      4) the only value that an iterator can legally have that isn't a valid member of MyContainer is MyContainer.end()

      The only/best not remove_if (e.g. NOT using the built in algorithms etc.) version of the remove on condition requires two iterators. That is:

      class something {...};
      // This typedef is your friend
      typdef std::set SomethingSet;

      void remove_matching(SomethingSet & MyContainer, something & value)
      {
      SomethingSet::iterator cursor = MyContainer.begin();
      SomerhingSet::iterator del_mark = MyContainer.end();
      while (cursor != MyContainer.end()) {
      // test for delete
      if (*cursor == value) del_mark = cursor;
      // Advance Cursor so it will remain valid
      ++cursor;
      if (del_mark != MyContainer.end()) {
      // do the erase
      MyContainer.erase(del_mark);
      // "re-zero" the mark
      del_mark = MyContainer.end()
      }
      }

      The above "seems" ugly but will execute in linear time and very efficently. It's uglyness though, is why the STL contains standard algorithms. Once you know how to write a function object correctly (and providing there is no prohibitive cost to copying your quanta) then the below which looks uglier:

      MyContainer.erase(remove_if(MyContainer.begin(), My Container.end(),predicate_function_object(value)), MyContainer.end());

      actually makes a heck of a lot of sense and optimizes down to something incredibly dense (8-) and effective.
  • by Anonymous Coward on Monday April 29, 2002 @02:18PM (#3430720)
    The current "problem" with STL implementations is the surprisingly wide variety of interpretations of the STL. If you are doing cross platform development you will run into incompatabilities. On the other hand if you are a single platform/compiler/STL shop then that should not be a concern at all. Be sure to have some Performance benchmark test programs though.
  • by adamwright ( 536224 ) on Monday April 29, 2002 @02:18PM (#3430721) Homepage
    Such as the one that shipped with VC6. It's much better in VC.net, but VC's was bug riddled and slow as hell. I can't first hand comment on many others (though I hear SGI's is good) - But do your research before adopting an implementation.
  • all the various implementations of the STL i've used have had different bugs in them. Granted, you need to be doing some pretty advanced things with it, but thats what its there for.

    And have you seen the actual code for the STL? Ugh. It demonstrates just how bad and obscure C++ syntax can be.

    • by baxissimo ( 135512 ) on Monday April 29, 2002 @03:00PM (#3431199)
      Your comment points to what I think is THE major downside to STL: debugging.

      If something's not compiling that you think should, you end up wading through the mile-long error messages. If it does compile but doesn't work right, you're going to find yourself in the debugger trying to step through some of that crazy obscure STL C++ code to try to figure out what the heck is going wrong. Neither is much fun.

      But when it does compile and run correctly STL is pretty nice!

      I'm looking forward to somebody starting over some day and coming up with a language that supports generic programming as well as C++, but which doesn't have the terrible syntax of C++ templates. It must be possible.

      Basically people have realized that templates can can be used to create programs that run at compile time to do some very clever optimizations (template meta-programming is what they call it see http://www.boost.org for one implementation. Blitz++ is the big example use of the stuff that everyone points too). But the code to make this stuff happen is ATROCIOUS!

      Yeh, you can make a template meta-program to calculate factorials at compile-time. Great! That sort of thing can come in handy. You can even write template meta-code that basically generates code at compile time. That's cool too! But the code to do it looks NOTHING at all like the equivalent run-time code. Why does it have to be that way? Why does compile-time code have to look SO different from run-time code, at at the same time look SO horrific?

      I think what is needed is a new language that will put compile-time and run-time code on equal footing. It would be great if they had the same syntax. Then you could just, say, change one line to turn some run-time code into compile-time code (only when there's no dependence on run-time data, naturally). But it doesn't necessarily make sense to put all the run-time efficiency restrictions on the compile-time language. Dynamic function lookup by strings is a pretty big run-time hit, for example, but you wouldn't care as much if it were used for compile-time function lookup.

      In general, the meta-programs seem work a lot more like functional languages -- so fine, I'd be willing to settle for at least a clean syntax for the compile-time language, say something Lisp-like, even if it looks different from the run time language. ANYTHING, as long as the syntax is clean and readable, would be better than the current situation of trying to do meta-programming in C++.

      I think the situation C++ is in today with respect to generic programming and meta-programming is a lot like where C was when OOP started to become big. People realized that, yeh, C can do OOP, but it doesn't really support it. C allows OOP, but it offers nothing really to facilitate its use. I think Stroustrup makes that argument in his C++ book. So Stroustrup created C++ as a language that would support OOP, not just allow it.

      Well folks, now we've got this handy meta-programming stuff, and yeh you can do it in C++, but it is not pretty. It's downright painful. Writing it is hard. Debugging it is hard. Testing it is hard. Reading it a week after you write it is even hard. Sounds to me like it's time for some new language stud to come and save us.
      • Check out BD Software's free message decryptor: "Freeware with Source Code, supporting: Comeau C++, g++, VC++6, VC++7 (Visual Studio.NET) and Metrowerks CodeWarrior"

        www.bdsoft.com/tools/stlfilt.html [bdsoft.com]

        The messages are still a bit odd until you browse the class which triggered the error, but it shortens them down to a readable, meaningful length.

        I'm a fairly recent STL convert and I find this tool utterly invaluable. I love STL because it provides a true standard for many of the structures and algorithms that are core to any project. I'll never have to deal with another crackpot programmer's homegrown, poorly commented dynamically-sizing array class again.

  • I think STL is great.

    About the only downside I've seen are old compilers bloating up the executable sizes if you use it a lot. I believe that's largely becoming an issue of the past, though.

  • STL downsides (Score:4, Interesting)

    by Hawke ( 1719 ) <kilpatds@oppositelock.org> on Monday April 29, 2002 @02:19PM (#3430733) Homepage Journal
    The header files you want to read to find out the API's are practically illegable. You'll probally want to get a book or other such better documentation.

    Depending on your compilier, you might end up with excessive binary-code bloat, as three different copies of "list" are created for list<foo*> , list<bar*>, and list<fred*> instead of using a single specilization for all three.

    I don't know how well the inheritance issues are nailed down, but I've never been tempted to make a class inherit from a container, I just have classes have containers.

    That said, I like STL and highly suggest using it. Never write a linked-list again.

  • Maybe someone can confirm this, but the latest .Net SDK does not seem to provide support for the STL.

    Otherwise, the STL is an excellent set of libraries to move the OO paradigm towards parameterized types.

    Of course like the rest of C++, you pay a price in comprehension...this language exposes everthing to you and you will pay a price in development and comprehension time.

  • by Avumede ( 111087 ) on Monday April 29, 2002 @02:21PM (#3430758) Homepage
    The fact that no compilers support all of STL is admitted by Stroustrop (sp?). However, in practice, most of it indeed works as advertised. You shouldn't have much problem.

    But the real bear is the compilation error messages, which can be pages long, and ultimately completely unreadable. This is due to template expansion, especially with STL classes (most of them) that take a large number of arguments, most of which have default values already.

    Also, as with all templates in C++, there is code bloat. But it is a tradeoff between having more code or having better type checking. You have to decide what is right for you.

    • by Mike Connell ( 81274 ) on Monday April 29, 2002 @02:46PM (#3431060) Homepage
      Just for the non C++ programmers, here's a (real) example of those STL template errors.
      readply.cpp:109: conversion from `_List_iterator<list<basic_string<c
      har,string_ch ar_traits<char>,__default_alloc _template<true,0> >,allo
      cator<basic_string<char,string_char_traits &l t;char>,__default_alloc_tem
      plate<true,0> > > >,const list<basic_string<char,string_char_traits&lt ;
      char>,__default_alloc_template<true,0> >,allocator<basic_string<char
      ,string_cha r_traits<char>,__default_alloc_template<t rue,0> > > > &,c
      onst list<basic_string<char,string_char_traits&lt ; har>,__default_alloc
      _template<true,0> >,allocator<basic_string<char,string_char _traits<c
      har>,__default_alloc_template<true,0> > > > *>' to non-scalar type `
      list<basic_string<char,string_char_traits&lt ; har>,__default_alloc_temp
      late<true,0> >,allocator<basic_string<char,string_char _traits<char>,
      __default_alloc_template<true,0> > > >' requested
  • Not many (Score:5, Informative)

    by Xentax ( 201517 ) on Monday April 29, 2002 @02:21PM (#3430765)
    In terms of usability, the STL is great. I've been told that it's not the be-all and end-all as far as performance goes, but it can handle most applications, even situations where there IS a performance requirement as long as it's not an especially stringent one.

    We developed a call-routing application for Solaris in C++ using ACE and the STL, and were able to meet a fairly hefty performance goal.

    The biggest downsides on the STL that we encountered were a few compile issues in terms of integrating ACE into the build (not a big deal), and the larger one of somewhat poor documentation of the STL itself. We used the MSDN STL documentation, and while Microsoft's implementation may agree with that API spec, Solaris' certainly didn't. See the signature of the map::delete method for an interesting example.

    Both the Solaris (actually SGI) and RogueWave implemementations DO NOT match the documented interface, even though Rogue Wave's documentation says it does! So make sure your intended usage is actually supported by the implementation of the STL that you're using.

    Xentax
    • Re:Not many (Score:5, Informative)

      by Xentax ( 201517 ) on Monday April 29, 2002 @02:27PM (#3430849)
      Oh, one other thing:

      Pay attention to which operations are expensive for the various data structures (map vs. list vs. vector, etc.).

      The fact that the operations' syntax for each of these is standardized is a double edged sword -- it makes for clean code and syntax, but it can mask poor-performing operations. Consider iterating over a map vs. over a list, for example.

      So, consider carefully what operations you perform on various structures, and (of course), profile where/when appropriate. Looking at the actual implementation of the STL you choose can go a long way in revealing such troublespots, if that's an option (SGI's implementation is pretty easy to get ahold of).

      Xentax
    • Re:Not many (Score:3, Insightful)

      by jkujawa ( 56195 )
      We used the MSDN STL documentation, and while Microsoft's implementation may agree with that API spec, Solaris' certainly didn't. See the signature of the map::delete method for an interesting example.
      SGI's STL documentation is excellent. I always have a browser window open to it while I'm coding. And, as it's the basis of the STL in g++'s libstdc++, it's quite accurate. SGI's STL is actually used by a number of platforms, and works pretty well.

      One think to watch out for is that the string class isn't thread-safe under linux.

      http://www.sgi.com/tech/stl/ [sgi.com]

      I also recommend Scot Meyers' "Effective STL".
  • Well.. (Score:2, Informative)

    by DCram ( 459805 )
    The thing that always bites me in the ass is the string class.

    string foo = NULL;

    This always gets me, segfault.

    I do a..

    string foo = "";
    where I define ""; as NULLSTR in some header.

    I dont know if this is a real problem or no its just that i have the habbit of initializing stuff to NULL.
    My bad style.

  • The big downside is executable code bloat if your compiler isn't good at optimizing away unneeded generated template code. The STL is almost entirely template-based. You could also call it a downside that you need a fairly current compiler because the STL makes heavy use of recently-introduced template features that even moderately old compiler versions won't understand.

    You also get a certain amount of lock-in, where stuff that deals with STL-using modules also tends to need to use STL to pass the right containers around, but you can deal with that in wrapper layers and IMHO the gains make the little extra work worth it.

  • by dutky ( 20510 ) on Monday April 29, 2002 @02:24PM (#3430809) Homepage Journal
    The biggest downside of the Standard Template Library is that it isn't very standard. The support for templating, across a range of compilers, just isn't very consistant, which makes using the STL in a portable manner almost impossible. Aside from that, the STL is, to my mind, just another giant complex wart on top the mind-numbing complexity that is ANSI C++ itself.

    As with OOP itself, generic programming is a Really Good Idea but its implementation in C++ leave something to be desired for simplicity and accessability. Due to C++'s dominance in the marketplace, the STL will likely be with us for many years, but this is far from a desirable circumstance.

    • by ivan256 ( 17499 ) on Monday April 29, 2002 @02:46PM (#3431059)
      As with OOP itself, generic programming is a Really Good Idea(TM)

      Be careful. It's generalizations like this that end up in the hands of managers and can lead to Really Bad Software(TM). There are plenty of cases where a small generalized solution is more apropriate. THere is no golden paradigm for software development.
    • by SLOGEN ( 165834 ) on Monday April 29, 2002 @02:53PM (#3431127) Homepage
      > The biggest downside of the Standard Template
      > Library is that it isn't very standard.

      No, but the C++ Standard Library is in ISO14882 ("Programming Languages -- C++"), and it "superceeds" and embraces the old STL. Unfortunatly most people (and tutorials) still refer to either the STL definitions or use the term STL about the standard library.

      > The support for templating, across a range of
      > compilers, just isn't very consistant, which
      > makes using the STL in a portable manner
      > almost impossible.

      Depends on what you use. Normally, it's not the containers themselves. that makes trouble, it's the functors and the algorithmic versions of operators (i.e. std::less and such), which most programmers don't use for the first few months.

      BTW: GCC-3 has EXCELLENT template-YOUR_FEATURE_HERE support as well as standard library support.

      > Aside from that, the STL is, to my mind, just
      > another giant complex wart on top the
      > mind-numbing complexity that is ANSI C++ itself.

      C++ is complex because of the possibilities it offers... well, and it's heritage. To the untrained even the simplest tasks are compilcated... think how long it took to understand (not just learn) multiplication :)

      > As with OOP itself, generic programming is a

      Hmmm.... I consider generic programming perpendicular to OOP (this is a nice analogy when explaining why using GP from OOP sometimes requires "multi-dimensional" programming... if you understand?)

      > Really Good Idea(TM) but its implementation in
      > C++leave something to be desired for simplicity
      > ans accessability.

      Agreed, as well as consistence in compile-time versus runtime versions of syntax.

      > Due to C++'s dominance in the marketplace, the
      > STL will likely be with us for many years, but
      > this is far from a desirable circumstance.

      The Standard library (not STL) is the best thing that happened to C++ for years. I doubt it could have been done cleaner and more flexible in C++?

      I would like to see optional garbage collection (with fitting restrictions to legal programs) introduced into C++. That's the no. 1 thing holding back (advanced/modern) OOP in C++.

      --
      Helge
  • Not many drawbacks (Score:5, Interesting)

    by emarkp ( 67813 ) <slashdot&roadq,com> on Monday April 29, 2002 @02:25PM (#3430823) Journal
    I've been happily using STL for about 3 years now. The biggest drawbacks (IMO) are:
    • Kitchen sink syndrome: There are a lot of features in STL, and to use some of them you need functors, etc. Sometimes it's just easier to read if you use a normal for loop instead of using for_each, etc.
    • verbose type syntax: When you use the containers, like (say) std::vector, you have to declare your iterators as:
      std::vector<int>::iterator i;
      If you change to a std::list container, you'll have to change your declarations. Of course, you can mitigate that by using typedefs, and then you only have to change the typedef, but it can still get a bit wordy.
    • unexpected results: Understand the difference between remove() and erase() in the containers.

    The benefits of using STL are wonderful. If you write your custom containers/streams/etc. using the STL interface, you can seamlessly use the algorithms portion of the library.

    I recommend reading the first part of Generic Programming and the STL. It'll help you undestand the thinking behind the design.

  • The STL is very effective. Most of the problems I've had with it involved cross-platform compatibility (as I tend to develop code that has to run on a variety of platforms). Depending on your various STL versions and compiler versions, you can have to deal with the vagaries of the presence or lack thereof of namespaces, the availability of default template arguments (which has led me to typedefs like typedef map<RWCString, RWCString, less<RWCString>, allocator> NVPairMap;), and some real headaches figuring out how to get the #includes just right to deal with the way that Microsoft has two different versions of the iostream headers in MSVC.

    Overall, I consider the STL well worth your while to learn and use.

  • by lkaos ( 187507 ) <anthony@codemonke y . ws> on Monday April 29, 2002 @02:26PM (#3430843) Homepage Journal
    The last book in Myers effective triology goes into a great number of details about the pitfalls of STL

    One thing to be wary of (as many have pointed out) is the different implementations of STL. GCC pre-3.x is pretty non-standard (although not necessarily bad). MSVC pre-6.x is absolutely horrendous (from what I gather, this is more of a legal issue than MS's fault).

    Some of the wackiest things though IMHO are:

    - Never use vector! It's a horrible specialization and is not even a container. Very, very bad.

    - Allocators are for the most part evil. Be very wary of them.

    BTW: There is a book Efficient C++ that says a lot of bad things about STL. This book absolutely sucks and is full of nothing but crap. While the examples aren't forged, they are examples of how not to use STL. Unfortunately, the book presents non-STL solutions that aren't even as fast as the proper STL solution. Long and the short of it is, make sure you (and your developers) are very familiar with STL and be aware of bad information about it.
    • I believe what you mean is never use vector<bitset>, which breaks certain semantics.
      vector is the most useful container in the STL, and is the basis for the STL string class.
  • For it being the 'holy grail' in software development, it seems like the poster could have dug up some sort of linkage for those not hip with exactly what STL truly is all about...

    For the ill-informed, please see the following links concern the C++ Standard Template Library (STL):

    *** Mumit's STL Newbie guide [wisc.edu]

    *** Standard Template Library Online Reference Home Page [rpi.edu]

    *** Another Informational Link [msoe.edu]

    There, I feel much better.... and hopefully you do, as well!!!

  • Partial List (Score:5, Informative)

    by Viking Coder ( 102287 ) on Monday April 29, 2002 @02:30PM (#3430887)
    Before you listen to any of us, go out and buy "Effective STL" by Scott Meyers, and probably "The C++ Standard Template Library" by Nicolai M. Josuttis.

    Now, I don't want to get off on a rant here, but in my personal opinion, the worst thing about STL is their string support. It's great, because it's standardized, but that's about the only thing going for it, from a programmer's perspective. (Yes, it's highly optimized, but the API isn't very rich. I like rich APIs!) In other words, build your own string class, and give it a Has-A relationship to the STL string.

    Also, I hate that Containers change paradigms on you, some places you can use integer indecies, sometimes you have to use iterators - and in my opinion, the line isn't very clearly drawn.

    Also, the methods are written along the lines of, "if it's not optimal, you have to write the code yourself." I'm sorry - that sucks. Sometimes I need to remove an element from a Vector. Maybe I should be using another Container. Or maybe the API should allow it, but make it clear in the documentation that it's not efficient. I vote for the latter.

    Get used to having your objects copied. STL Containers work by copying your objects. It's a different way of thinking for a lot of people. It has rammifications that are kind of hard to grasp, at first, if you're not used to it.

    Don't use Containers of AutoPtr's! It won't work right! (Read "Effective STL" for an explanation.)

    In my opinion, everyone should wrap every third-party library they use with an API that they can live with. STL is no exception. You might even expose every single member function, but you have the freedom to expand your API if you want. If you can't afford a stack push, then you probably shouldn't be using STL in the first place.

    If you end up really liking STL, take a look at Boost. Some parts of Boost are really cool and well written.

    Really, I think the best advice I can give is this : get to really know an API before you start to use it. Because, if you try to just use the parts of an API that you know and like, you're going to make horrible mistakes. Invest the time to get to know the library well enough to use it the right way. STL is no exception.

    Of course, that's just my opinion, I could be wrong.
  • by MobyDisk ( 75490 ) on Monday April 29, 2002 @02:30PM (#3430892) Homepage
    I am an avid user of STL, and I have worked on many projects, large and small, that make use of it.

    Advantages of STL:
    - Standardized, comes with every C++ compiler
    - Fast
    - Generalized (excellent use of templates)
    - Many different implementations freely and commercially available.
    - Source code available.

    Disadvantages of STL:
    - Large executable file sizes
    - Incompatibilities between implementations
    - Complex to debug

    STL is a very fast and powerful library. Ignore those who say "it uses virtuals, and is in C++, therfore it is slow" because none of them have ever used it. (C++ is in fact faster than C if coded properly, and STL is coded properly) Often, a good structure is much faster than using arrays, even if they have less overhead.

    Unfortunately, STL's use of templates and inlines can inflate the size of your code in exchange for raw speed. This can vary very much depending on your compiler. MSVC adds 200k or more just for the priveledge of using strings! Using STLport still requires that you link in the old 200k libraries ON TOP of STLPort!

    I do not recommend using STL on small projects where compiled file size is an issue. For anything else, go for it.
    • by Ars-Fartsica ( 166957 ) on Monday April 29, 2002 @03:36PM (#3431520)
      Every time someone trumps up the merits of their language, they always mention that it is (potentially) faster than C. This has been uttered so many times that I don't know why anyone uses C at all, it clearly has terrible performance (according to all the language advocates).

      I'm calling your bluff. Give me some stats for example programs.

      • I thought you might be interested in some counterexamples. I don't think Intercal or Befunge advocates have ever claimed those languages were faster than C. In fact, I don't think they claimed Intercal or Befunge was better than any other language.

        -Paul Komarek

      • Compare just about any use of C's qsort with C++'s std::sort. The fact that the latter is implemented as a template means that any specialised comparison functions can be inlined and optimised right in the sort algorithm, unlike the mandatory level of indirected required by qsort's call-via-pointer approach. I don't have any timings handy to give entirely objective evidence, but I've certainly done rough-and-ready timings on several compilers, and all the recent ones had std::sort way ahead. A quick glance at the generated assembler confirms the theory above.

      • by leshert ( 40509 ) on Monday April 29, 2002 @04:15PM (#3431791) Homepage
        The most well-known example is using the sort algorithm instead of C's qsort. Because all the comparisons are templatized, and you never end up casting anything to void*, all the comparisons are inlined, and sort shames qsort.

        When I tried it last, I didn't get the 6x difference some people claim, but it was about 2.5x faster.
  • by omnirealm ( 244599 ) on Monday April 29, 2002 @02:38PM (#3430969) Homepage
    I am on a research team that is developing a Bluetooth financial transaction system. One of the members of our team wrote an XML parser using STL components. When it came time to compile the XML parser using the embedded tools for a PDA, we found that Microsoft had not implemented the STL in the libraries they provide in Windows CE. We had to switch all our string processing to use Windows components like CString (which, admittedly, has more features that the STL's string). The moral of the story? Using STL may affect your portability, especially in the embedded systems arena.
    • by Jherico ( 39763 ) <.gro.saerdnatnias. .ta. .sivadb.> on Monday April 29, 2002 @03:06PM (#3431259) Homepage
      Using STL may affect your portability, especially in the embedded systems arena.

      That's the stupidest thing I've heard all day. You switched from std::string to the MFC CString and you say that STL isn't portable? You don't need MFC's handholding. You go out and find one of the many copies of the STL that's freely available out there and you compile it yourself. You don't switch to something thats even LESS portable.

  • too much time (Score:4, Interesting)

    by 0WaitState ( 231806 ) on Monday April 29, 2002 @02:39PM (#3430981)
    The biggest drawback of STL is finding something to do with all the extra time you'll have. Just think--you won't spend days debugging somebody's insanely API'ed String implementation he developed when wired to the gills on Jolt.

    You won't spend discouraged hours in meetings while ego-driven idiots argue over whose pet collection class hierarchy better suits the hypothetical abstractions of the project. You won't waste precious energy trying to reverse-engineer someone else's pattern building-blocks because now you immediately recognize STL method signatures.

    STL reduces job security for programmers who rely on obscure implementation. Some may see that as a drawback. IMHO, good code is maintainable code, and STL usage in any project is a quantum jump towards maintainability. Remember, the "maintainer" will probably be yourself revisiting the code six weeks after that all-nighter.
  • Vendor specific (Score:5, Informative)

    by Zathrus ( 232140 ) on Monday April 29, 2002 @02:40PM (#3430995) Homepage
    The biggest downside of the STL is when it doesn't work.

    Sure, the standard is >3 years old now, but a lot of compiler vendors are still working out bugs with either the STL, their compiler, or their linker still.

    Under AIX, we've run into relatively few problems with the STL itself, but the linker is pretty bad. Between it and the compiler compiles take forever (which is why I've been surfing /. more recently), and the executables are freaking huge.

    This is, obviously, an AIX-specific problem. And it's pretty much an old story - every vendor has their own quirks with the compiler and/or linker.

    Beyond that -- I've found a few things missing in the STL that would be really nice to have.

    First, the only smart pointer is std::auto_ptr. It's pretty useless, since you can't use it in a collection, and you can't have more than one thing pointing at an object/memory block at once. This can be worked around though, since there are libraries that have better smart pointers. Check out Loki [aw.com] or Boost [boost.org] for two.

    Second, there's no way to automagically ignore case on a std::string, or to upper/lower case it easily. Yes, I know, you can muck around with traits, but that's a PITA and renders your string uncopyable to other strings easily. Yes, I also know that you can use a transform() to do it. But this still isn't as nice as myString.lower().

    Third, there's no date or datetime classes. You have to fall back on C time functions for them. I haven't looked for a good C++ library to handle date/time, but I'm sure there's one out there.

    Fourth, there's no regular expression matching on strings. We use PCRE [pcre.org] with a C++ wrapper and it works fine for what we need though.

    Both 2 and 3 are due largely to internationalization issues... in the case of 2 there's a lot of languages in which upper and lower case are non-sensical. And after having thought about the i18n issues regarding dates, I don't blame the standardization committee a bit for running away screaming from them (what date range? which calendar? how do you change between calendars? what about date weirdness with some calendars (like the missing days in the Gregorian calendar)? etc).

    I used RogueWave prior to this job, so I tried to think of some of the things I was used to in RW and weren't in the STL. By and large I prefer the STL though. The container classes in particular are a lot more sane than RW's.
  • by MagikSlinger ( 259969 ) on Monday April 29, 2002 @02:42PM (#3431017) Homepage Journal

    First off: Why must you use STL? STL can be handy, but it can also be a terrible pitfall to the unwary. If your code is working and there is no compelling reason to re-write it, then don't/

    Secondly: Be very, very careful about using pointers to dynamically allocated objects. If you are copying pointers around, you could very easily get into a dangling reference. A smart-pointer template (which SHOULD have been part of the STL) is a handy thing to have.

    Third: Take the time to learn the Zen of STL. You must understand the rationale and mental model of the STL to get the most out of it. It doesn't take long (a week at worst).

    Fourth: Get a good C++ and STL implementation. If you don't, you could wind up with compile errors that will drive you insane. <Sounds like the voice of experience, MagikSlinger!>

    Fifth: Use STL sparingly. Don't go hogwild creating types made up of a dozen composited templates. When you get a run-time error or compile error, it becomes next to impossible to decipher what happened. Do not go more than two levels deep in an STL definition. map<string,MyClass> is OK, map<string,map<pair<T,X>,list< vector<int>>> is a very, very bad idea...

    Sixth: Use the simplest datatype to achieve your goal. Don't resort to multimap, etc. with fancy indexing/hashing schemes unless you prove emperically that it will speed something up a lot. Not a little bit, but a lot.

    Good luck, and have fun!

  • by cfulmer ( 3166 ) on Monday April 29, 2002 @02:42PM (#3431018) Journal
    I hope you're not talking about re-writing existing code to use STL instead of the equivilent C++ libraries. That sounds like a great way to introduce insideous bugs in your code. If it ain't broke, don't fix it.

    In our development team, we have people who prefer RW, others who prefer the STL and others who are agnostic. In general, we've had a very good experience getting them to work together. Sure, it tends to lead to larger executables, but that's not a particularly big issue for us.

    One thing that I haven't seen others talk about is that the two do not necessarily perform equivilent functions. The STL provides a bunch of templates, and RogueWave provides a bunch of useful classes, some of which are templates. RWTime, for example, has no equivilent in the STL.

    Also, if you want to use other RW libraries (such as their threading stuff), then you're going to need to use some of the base RW stuff anyway.
  • mostly downsides (Score:3, Interesting)

    by j09824 ( 572485 ) on Monday April 29, 2002 @02:44PM (#3431039)
    I think the STL has mostly downsides:

    • The STL makes no guarantees that it checks for errors (bounds checking, using a pointer into the wrong collection, etc.), and it is designed in such a way that error checking is quite costly. (Note that there have been a couple of attempts at making a safe STL; see here [horstmann.com]; it is unacceptable that this isn't part of the standard and isn't used by default).
    • It's hard to predict whether any particular data structure or algorithm is going to be fast. Sure, it makes asymptotic guarantees, but everybody does that; it's the constants that matter.
    • The library is too complex for most needs, and you can't easily just use "a little bit" of it. If you want to write efficient code using STL, you have to understand it pretty well.
    • STL's complex semantics also make thread safety hard to guarantee.

    The STL wasn't adopted because the committee liked it tremendously, it was adopted by default: it was the only serious proposal for collection classes for C++ that the committee had, and C++ needed collection classes in order to pass as a standard. I think what C++ should have gotten was a simple template array class, list class, and hash table class, with excellent error checking. IMO, STL has greatly damaged the C++ language.

    How can you live with the C++ STL? Your best bet is to pick a small, simple subset of concrete STL datatypes and operations (vector, stack, and map) and stick to those in your interfaces and most of your code. You can implement your own, safe and efficient versions of those for development and internal use and use the standard STL versions when you ship library code. Forget about iterators: they are a mess to debug. And use the STL algorithms only if you don't care about performance.

    Note that I have nothing against generic programming: generic programming is an old and well-established idea (and predates Stepanov and Lee by many years). C++ is just not a good language to push it to the extremes that STL pushes it.

  • by Henry V .009 ( 518000 ) on Monday April 29, 2002 @02:44PM (#3431040) Journal
    You've read Meyer's book, which is a good start. You probably also want to check out Josuttis.

    The STL is really as good as could be expected. Better even. There are problems. Some problems stem from the fact that it had to be approved by the standards committee. There was a lot of opposition to adding something that big to C++, so the size was cut down. Certain things are missing. (Heaps, general binders, good smart pointers) but versions are provided by many implementations. Check out CGI for one. They will also be added to the next version of the standard, along with a few other nifty things (As always check out boost.org for much of that stuff). The allocators are broken in my opinion. Using (different) customized allocators prevents interactions between your containers.

    The biggest problem is its complexity. Like any C++ feature, understanding the STL is not enough. You need to understand how it interacts with other parts of C++. When you use the STL, you are using a rocket launcher instead of a BB-gun, shooting yourself in the foot can be much worse.

    All in all the STL is god's gift to programmers. It really is. I can't imagine not having it to program anything serious with. I work everyday with AI and Image Processing algorithms -- stuff where performance really counts, mind you -- and I couldn't live without the STL. I barely use pointers anymore.

    To sum it up, C++ with the STL is the only language that meshes (not always prettily) performance computing with high level concepts. It is a truly beautiful technology.
  • by Waffle Iron ( 339739 ) on Monday April 29, 2002 @02:44PM (#3431045)
    The STL helps greatly to manage the scope and lifetimes objects vs. roll-your-own C datastructures and algorithms. However, once you put together a complex system it can still bite you if you're not extremely careful. STL data structures allow you to push C++ to a very high level of abstraction, but you should never forget that you're still using a relatively low-level language.

    You have to pay very close attention to where you are storing pointers or iterators, and to when the things they reference are freed or moved. It is very easy to misuse the automatic constructors and destructors in C++, especially if you don't understand exactly what the STL is doing "under the hood" for each operation you perform with it.

    "Smart pointers" help, but they have their own bugs and quirks, too. (I once did "bidirectional" smart pointers that were pretty idiotproof; all ends of each multiway link were aware of each other, but this had a lot of overhead.)

    You can minimize this risk to some extent by designing the code to pass around auto-constructed copies of data instead of references or pointers, but this will tend to impact performance, sometimes so much so that Java would be faster.

    Multi-threaded apps are even harder to get correct, since STL is not generally threadsafe.

    Oh yeah, looking at the mangled names when you debug your code will drive you insane.

    Nevertheless, IMHO, the STL is still the best thing about C++ and is just about the only reason I would use it instead of C. (Either one, though, is a last resort. I tend to develop and test all code in something like Python, and port portions to other languages only as needed.)

  • by IvyMike ( 178408 ) on Monday April 29, 2002 @02:53PM (#3431130)

    Trying to locate a bug in a program that makes heavy use of templates, and specifically STL templates, can be infuriating. Besides having your data stored in a obscure data format that's difficult to view through normal debugging commands, you've also got type names that can be hundreds of characters long. The Sun Workshop debugger used to actually SEGV on some of those long names; apparently a buffer in the debugger overflowed. (This problem was fixed a few years ago).

    Hiding the implementation of complex data structures makes for easier coding, but makes life hell when you're trying to vivisect a live process. At my work, we do use STL, but in small, measured doses.

  • by Tiger ( 9272 ) on Monday April 29, 2002 @02:54PM (#3431144)
    Unless there was a specific requirement and good reason for it, I wouldn't write C++ without STL nowadays. We've been using it for the last 2+ years on about 6 different unix platforms (mostly gcc2.95 over that time) and NT (using VC6.)

    In that time we' ve seen a lot of improvement as native compilers for HP, and possibly IBM are catching up and threaten to replace gcc for builds on those systems.

    VC6 is a real catch.. their STL implementation is only borderline usable. The solution to this was to introduce stlport [stlport.com] into the mix, at least for our win32 builds.

    Some issues we've had:
    - verbose syntax (once your finger macros catch up, it's okay)
    - EXTREMELY verbose compile error statements - especially when using a sufficiently complex STL object (vector of strings, or something) and doing something like attempting to use a const iter in a non-const way produces monstrosities like:

    passing `const string' as `this' argument of `class basic_string,__default_alloc_template > & basic_string,__default_alloc_template >::operator =(const basic_string,__default_alloc_template > &)' discards qualifiers

    (and that's a simple one.)

    - Bugs on various platforms, including the lovely uselessness of VC6 STL
    - Difficulty of examining data in debuggers - ddd+gdb gets a right ugly mess
    - Memory High-water-marks: Some things don't really free the memory you want them to free, just hold onto it for next time. We've discovered this when we create stupidly-large temporary maps, and then delete them.
    - Various little gotchas like the dangers of using remove() algorithms, being aware what map's operator[] does, etc.
    - Inconsistencies between std::string and the rest of the STL

    But to try and be less negative:
    - STL has made handling data within a C++ program much more pleasant. For us, STL is fast and efficient, and has probably saved us many programmer-months in the debugging and development time required to use traditional C/C++ data structures. Plus, once you get into the mindset used by STL, it gets more and more powerful every time you read another part of the documentation.

  • by Greyfox ( 87712 ) on Monday April 29, 2002 @02:56PM (#3431162) Homepage Journal
    The biggest downside is that it's easy for an innocent array index operator ([...]) can do Strange Things. Things like creating object instances which will then immediately be destroyed after a test is made. This can make a serious dent in the speed of your code. Most of the good STL books you can get from your favorite bookstore cover the ins and outs of these pitfalls pretty well.

    Folks complain about code bloat due to template usage but I think it's a reasonable trade-off for type safety. Especially if you were going to create all those classes one way or another anyway. By the by, for some really sick template usage, check out Andre Alexandrescu's "Modern C++ Design."

  • by eddeye ( 85134 ) on Monday April 29, 2002 @02:57PM (#3431171)
    Two words: Effective STL (ISBN 0-201-74962-9)

    This book does an excellent job of covering the strengths, weaknesses, and pitfalls of using the STL.

    Among the STL's (and C++ standard library's) deficiencies are lack of generalized functors, hash containers, smart pointers (the only type included, auto_ptr, is not very useful), and thread libraries. All these and more are addressed by third-party libraries such as Boost (boost.org) and Loki.

    All these features are under consideration for inclusion in the next C++ Standard (C++ 0x) being worked on now. The Boost libraries in particular are strong candidates for inclusion in the next Standard; if not, something very close to them should be in there.
  • by small_dick ( 127697 ) on Monday April 29, 2002 @03:06PM (#3431257)
    the syntax and readability are so horrible that it took several computer scientists years to decide exactly how butt ugly and unreadable to make it.

    STL is not, in any way, shape, or form, a step forward for programmers.

    people can write stuff with it that is totally incomprehensible to anyone who is not party to their school of programming style -- but this is true of C and C++ in general.

    I don't know what the solution to programming's difficult problems with reliability, reusability and maintainability, but I think Java has done a lot more to improve the state of the art in programming models, especially WRT these problems, than the STL.
  • by Animats ( 122034 ) on Monday April 29, 2002 @03:08PM (#3431282) Homepage
    The STL is a reasonably good collection library. I wasn't initially too happy with the iterator paradigm. The idea of generalizing pointer arithmetic, the most error-prone feature of C, seemed a terrible idea. But it's worked out moderately well, and STLport [stlport.org] can be compiled with iterator checking, which is very useful.

    In practice, the big problem with the STL is that Microsoft doesn't like it. It's one of those standards that Microsoft doesn't control, yet is so widely used that they can't ignore it. So they support it, but badly. (OpenGL gets similar treatment. So does C++ itself. Microsoft prefers their own dialect of C++, which is not fully compatible with the ISO standard.)

    The STL doesn't help too much with the big problem of C and C++ programming: keeping track of who owns what. auto_ptr and the STL don't play well together. That's a lack, and it's not easily fixed. There have been three iterations of auto_ptr semantics, all of which have some painful problem. See "comp.std.c++" for discussions on this subject.

  • Downsides (Score:3, Interesting)

    by Ken Treis ( 90058 ) on Monday April 29, 2002 @03:22PM (#3431403) Homepage

    Others have already pitched the positives, so here are a few of the negatives. There are a couple of things that I see as real problems with the STL. Having just gone through a small-scale STL development project, I've come away with a really bad taste in my mouth. Here's why.

    With the STL, C++ has finally aquired a part of what Smalltalk and Java have always had: a library of base classes. With these sorts of capabilities, you tend to start thinking about your system in more object-oriented terms. This is a good thing in itself, but C++ just doesn't go there with the ease that other languages do.

    For example, the OO notion of polymorphism goes completely against C++'s strong typing (and C++ is even more finicky in its type checking than C is). In a true OO system, I don't care what kind of object I have in my hands, I just care that it does a certain thing. This is where late-bound OO languages like Smalltalk and Objective C shine.

    Also, as your project progresses and you factor your code into neat little objects, file-based source code navigation becomes a real bear. IDEs like Source Navigator can help with this, but you still have to do double-entry bookkeeping for your prototypes and function declarations.

    Why didn't we see these problems before the STL? Because we never tried to use C++ as much more than a superset of C. With the STL, we had the opportunity to build things that were more like our other OO systems, so we did. And that's where we started to get bogged down.

    One other thing: We had more discussions about coding style in a few weeks of STL coding than we ever had in our non-STL C++ coding. Perhaps that was because more of us were involved in the project. But I think that, at the heart of it, the STL gives some people a feeling that C++ code can has a chance of being "elegant", and there is a real tendency to push yourself to try to achieve it. Without the STL, we all just knew that C++ was bubble gum and bailing wire. It happened to get the job done for us, and we didn't bicker about style.

    Perhaps your situation is different, but if I had to make the call, I'd say your time might be better spent learning something else.

  • by jvl001 ( 229079 ) on Monday April 29, 2002 @03:44PM (#3431580) Homepage
    I've been using the STL extensively in a multiplatform environment for the past 5 years, and I heartily recommend it. It certainly beats rolling your own, and execution speed is typically not an issue. Most of the pitfalls mentioned here are common to C++ in general. They can be summarized as follows:

    Learn who owns what. Learn how to handle pointers and references in an intelligent manner. Garbage collection is neat but is no substitute for good programming.

    Read Those Fine Manuals. See SGI STL Tech Pages [sgi.com] for a good online STL reference. Pay particular attention to stated efficiencies. You can use an iterator to loop through any container, but not all containers are created equal.

    Get a good compiler. Template and inline code bloat can be minimized by selecting a decent compiler and flags.

    You can use things like for_each, but remember you can also use a standard for with iterators.

  • Downsides (Score:5, Interesting)

    by Frobnicator ( 565869 ) on Monday April 29, 2002 @04:09PM (#3431760) Journal
    This is a longer post and has taken a while. Someone might have already said this, so please don't mod me as 'redundant'.

    If you are a good computer scientist there are no real downsides. If you are just hacking a system together and don't understand how the datatypes and algorithms work, and you don't have time or care to read the manuals, you will be in trouble using the STL.

    I have used several versions of the STL on several compilers and OS's, and find that as a whole, the STL has few downsides, **IF YOU READ AND UNDERSTAND WHAT IS GOING ON** If you don't understand the basics, it becomes a nightmare to debug. On the flip side, if you understand what is going on you can get very fast code at low development cost.

    Developers need to understand that certain operations invalidate iterators, and things like that. (That is the most common error that I see.) When you get an error in STL code, usually it shows up not as a single error but as a huge list of errors as it propogates through the template library -- but it is just one coding error. You might consider those as downsides, but they are typical in computer programming.

    A lot of people listed 'bugs', slow learning rate, and other problems, but in my experience the STL is easy to use if you consider the two aspects the STL covers -- data types and algorithms. I have seen other programmers struggle because they cannot separate the two. They think that string types should have string algorithms in the class, or sets have the set operations, and so on. The STL is an attempt to keep the two apart. It is easy to write new data classes that use the STL by implementing the few functions needed for all the algorithms, and it is easy to write new algorithms that use any STL object because they all implement the same small set of functions.

    One example -- It is easy to change the allocation method (swap portions of ram to disk) simply by writing a new allocator. A co-worker insisted that the STL wouldn't work outside of RAM, but a simple allocator class allowed everything to work on disk for huge data stores. The co-worker had spent years working on implementing a few slgorithms and data types on his own. The STL with a simple, custom allocator worked faster than his code, and took much less time to develop. Poor guy -- I really felt sorry for him.

    There are some problems with specific older compilers, but most are fixed. The older Metrowerks compiler didn't allow traits, the older Microsoft compiler didn't allow several kinds of nested types (use the service packs to fix them) and their debug info is terrible in VC6, GCC used to generate very bad STL code (it still has some quirks). The glitches are mostly fixed now. New, GOOD compilers will take longer to compile (downside) but will often generate either smaller code or significantly faster code (big benifit). I have seen cases where the executable doubled in size (the code bloat that people talk about), but the runtime decreased signficantly (not usually mentioned), and the code became much more readable. Since most of us (except embedded systems people) don't need to worry about size, the tradeoffs are acceptable.

    Another benefit/downside is that if you use optimizing compilers that know about the STL, you can do really incredible things. For example, if you are using a valarray (value array) type to perform operations, you can get massive speedups. I use the Intel Optimizing complier for x86 chips, and it uses MMX, SSE, and SSE2 optimizations to perform many loop, array, and STL operations. It is cool to see huge sections of code the the compiler message "foo@bar@PARAM@Z has been selected for automatic CPU dispatch", and reading the generated code shows that it uses the MMX or XMM registers, depending on the CPU type, or use the slow, loop based values on 486/Pentium chips. A bad compiler would probably just go to the worst case, the slow loop -- so get a good compiler.

    Itanium chips could do extremely well on many of the STL algorithms. (I have wondered if the Intel Optimizing compiler for Itanium would do massivly parallel ops with valarray classes. Does anyone have experience there?) Other parallel chips can benifit in this way as well, IF THE COMPILER IS SMART ENOUGH TO DO IT. The downside is that you have to know how things work and why. If the compiler doesn't do the optimization, perhaps another algorithm would work better in that case.

  • by LoveMe2Times ( 416048 ) on Monday April 29, 2002 @05:13PM (#3432266) Homepage Journal
    I just wanted to point out that asking about something like the STL here on /. will not give you much breadth of opinions on the matter. When it comes to programming and software development, /. has a high concentration of scripting language users for web site backends and administrative tasks, and a relatively small number of "application" developers. There are also a disproportionate number of systems programmers. From reading /., you might get the impression that C++ is not very widely used. While this is true in the Open Source world where there are many *many* more viable options, commercial software development is still pretty dominated by C++ with Java seeing use in some sectors. So what's the takehome message here? Even given /. bias, you're still getting a pretty positive response to STL. Anyway, here are a few things you should know:

    1) Get STLPort. [stlport.org] Use STLPort. STLPort addresses many, many, STL issues. They add extra nice classes like hash tables. STLPort is thread safe. STLPort has nice extra debugging features. STLPort has readable code. STLPort is PORTABLE (thus the name!). OpenOffice uses STLPort, in case you're still dubious.

    2) Get a couple of STL books. There aren't any really good ones (IMHO), but it's handy to have a printed reference with some examples.

    3) You wanted downsides, so here's one. You will have to learn STL. Not the library, but the techniques--the API is easy. You have to write your own C++ classes well to take really good advantage of STL. The way you leverage the STL for absurd productivity is through generic programming and STL's pluggable component architecture. Still, though, even you all you ever use is map, string, and streams (or some other subset), you'll probably become a convert.

    4) STL will keep getting better to use. Other people have mentioned it, but look at Boost [boost.org] for some ideas about where STL is headed. Also, the compiler people are aware of and are working on the error message and debugging problems. Both VC++.Net and gcc 3.x are making progress here.
  • I have been held to the java grindstone for 7 years and growing steadily despondant wishing I were back designing swift running systems of elegant templates... so this weekend I sat down for a personal STL refresher.

    g++ is just what i needed for a fun and relaxing weekend of random hacks.

    I was goofing off with a trivial c++ hack that provides a base64 iostream iterator. I've heard for a while about the relative bloat and performance hits on the IO side of c++ and wanted a peek for myself.. what I found was halting.. 50x performance increase from a simple C hack, all of it IO. Well, not to be defeated so easily, I plugged in STLPort with its spiffy optimized IO and gave a whirl. What resulted was not 1:1 with C but reasonably in the realm of hand tunable for IO buffering thereafter... this was after all, code that reads and writes a byte at a time vs. a c program that uses buffers...

    the relative results of this effort were as follows: test were conducted streaming 1 meg of data to >dev/null on an athlon 1800xp under debian sid dist.

    buildtimesize

    gnu uuencode, from gnu sharutils, compiled c code. ~0.12 seconds/meg binary 9k

    base64.h: using g++-3.0.4 -O6 -static
    ~3.5 seconds
    binary size 895k

    base64.h: using g++-3.0.4 -O6 (shared)
    ~4.8 seconds
    binary size 6k

    base64.h: using g++ and stlport -O6
    ~0.45 seconds
    binary size 10k&7k, static and shared.

  • by brdsutte ( 576841 ) on Monday April 29, 2002 @05:43PM (#3432456)
    Code bloat need not be a problem of using templates. If you look at

    http://www.elis.rug.ac.be/~brdsutte/squeeze++

    you can see that we are able to reduce the code size of real-life programs (e.g. LyX) using a lot of templates by 60%. This is done by compacting the programs after they are linked, applying aggressive whole-program optimization and code abstraction techniques. There is a specific manuscript on the page as well, on how to reduce the code bloat coming from the use of templates. An important technique is whole-procedure reuse: if several identical procedures are found at the assembly level, no matter what the source code was, the duplicates are eliminated from the program. If similar procedures are found (e.g. in sorting routines where only the called compare method is different), they are merged using a new parameter.

    Cheers,

    Bjorn De Sutter
    Ghent University

  • by technoCon ( 18339 ) on Monday April 29, 2002 @08:30PM (#3433217) Homepage Journal
    i've used STL and i love and have hated it. you do it right, and walla, all kinds of jizzy things are easy. OR make some teeny mistake and you get 5 lines of extremely dense and unhelpful error messages.

    I've found that the STL learning curve is steep at the outset. BUT if you've got some teammates who can help you along, good: get a copy of the Effective STL books and _Modern C++ Design_, and take a peek at the boost library.

    Once i started reading _Modern C++ Design_ and I started grokking "generic programming" better, funky games with templates, and the mindset of library designers, i mean GOOD library designers, woah! suddenly i got to understand *why* i'd see those 5 lines of unhelpful error/warning messages.

    When i taught C/C++, one of the least PC things I say is that the compiler issuing error/warning messages is like a girl saying "no when she means yes." The compiler will say one thing when it means another thing. Thus the ugly error messages. The coolest things in boost/loki/STL are done in spite of the language/compiler, thus when you get off track, you'll see goofball error messages because of those workarounds.

    Recently, we had a program that was running slowly. But a key data structure doing a linear search of a big array was done in STL. We changed 5 lines and suddenly a different more efficient search algorithm went in and walla, we saw a big speedup. if we had NOT used STL, we would have gone 'oh shoot, we picked the wrong data structure.' Just changing a vector to a multimap did all that.

    Flush from this success, we tackled another problem that was jsut perfectly solved by a functor object. Heck, i couldn't even spell functor 6 months ago, and i've been hacking C/C++ since 1984 and I think that getting into STL has opened up a whole new set of paradigms that every C/C++ programmer should have.

    In the old C days, i was a total weasel with the preprocessor, and that became wicked under C++. With templates, generic programming, and all those STL paradigms, you're exercizing the C-front parts of the C++ compiler, which may explain why I like STL weaselology.

    If you're unwilling to learn STL and climb that learning curve, pick up VB and wrastle with getting the right VBX/OCX components installed, OR sell your soul to the Dark Lord and use .NET components, C# and/or "managed C++."

    Or you could do Java. but i don't know how to do "generic programming" in Java.
  • STL Error Decrpyter (Score:3, Interesting)

    by ElJefe ( 41718 ) on Monday April 29, 2002 @09:49PM (#3433588)
    For those of you complaining about the huge error messages that the STL can sometimes cause, you might want to try this:
    http://www.bdsoft.com/tools/stlfilt.html [bdsoft.com]

    I haven't tried it because I haven't done anything with the STL in a while, but it seems pretty nifty. It's basically a Perl script that you can use to decipher the error messages into something useful. There's even instructions on how to make it work with VC++.

    This article [cuj.com] has a better description and an example, in which a 20-line error message is reduced to plain English.
  • Not OO, on purpose (Score:3, Interesting)

    by sohp ( 22984 ) <snewtonNO@SPAMio.com> on Tuesday April 30, 2002 @03:41AM (#3434466) Homepage
    If you chose to use C++ for its object-oriented abilities, you may be surprised to know that Alexander Stepanov (the inventor of STL) himself said he never uses what he calls "inheritance, virtuals - OO gook" of C++ [stlport.org], and says, "I think that object orientedness is almost as much of a hoax as Artificial Intelligence. I have yet to see an interesting piece of code that comes from these OO people."

    This may or may not be of any importance in your choice of language features and development practices.
  • by ChaoticCoyote ( 195677 ) on Tuesday April 30, 2002 @07:28AM (#3434842) Homepage

    In 2001, Bjarne Stroustrup [att.com] started a dialogue about the future of C++. As primary inventor of C++, Bjarne is giving interviews, visiting user's groups, and posting in forums, all with the intent of stimulating discussion about where C++ should "go." It's an important topic for software engineers, and everyone has a laundry list of features they'd like to see added in the next revision of C++.

    I'll buck the laundry-list trend and suggest some things I don't want to put in the next C++.

    In my experience, C++ iterators, algorithms, and containers are inefficient and unnecessarily complex. The actual source code doesn't look terribly confusing — it's the underlying mechanisms that obscure function with too much form. We heap template upon template, giving the compiler nightmares while obscuring what is really happening "under the hood."

    Is container abstraction akin to the hiding a car's pistons from its driver? No, because I'm not driving the car, I'm building it. And as any good engineer can tell you, hidden complexity and obfuscated parts have been the bane of many software (and hardware) projects. I have no problem with containers being part of the language — what bothers me is that the current set of containers is complicated and inconsistent. We need to refine the current standard before we begin adding new material; otherwise, we build new code on uncertain foundations.

    An official template library also leads to another question: Just what is a "standard" container? Some people argue that, for the sake of completeness, we should add hash-based containers to the standard library. But "completeness" means different things to different people; someone might want balanced binary tree containers, while others would prefer B-Tree or r-tree implementations. And then we get into the whole issue of graphical development — and you end up with Java, that tries to be everything to everyone but does few things particularly well.

    The current template library is much too heavy, prone to the "feature creep" inherent in a committee-based standards process. And when the standard includes an inconsistency, (list<>.sort() comes to mind), we're stuck with it. Should a list be sorted via its member method or the sort algorithm? And what constitutes a "required" container feature? I use about 20% of the vector<> template 80% of the time; it seems to me that C++ needs a functional hierarchy that stems from a set of concise "base" containers.

    We also have the entire realm of garbage collection and "smart" pointers, which is a nasty tangle of divergent opinions. The auto_ptr<> type has numerous logical and practical problems, as does the Boost smart_ptr<>. I don't believe one type of smart pointer makes sense for all applications — and C++'s experience with auto_ptr<> should teach us to avoid providing specific solutions to general problems. I'm still not convinced that automatic garbage collection is a good idea in most applications; it tends to make programmers lazy about controlling their resources.

    I've always preached that code should be no more complicated than necessary — and that includes the code I obtain from language libraries. The C++ container types are heavy and detailed, when what we need is a simple set of light, fast containers, with hooks for adding algorithms that fit individual application needs.

    Anything else is trying to be Java. ;)

Real programmers don't bring brown-bag lunches. If the vending machine doesn't sell it, they don't eat it. Vending machines don't sell quiche.

Working...