tags:

views:

885

answers:

9

Does it make sense to restrict yourself to the STL libraries when learning C++ and then tackle boost and its additions after you have become fairly proficient with vanilla C++?

Or should you dive right into BOOST while learning C++?

A: 

It depends entirely on whether you're going to be able to use Boost in all your work. I don't doubt that there'll be workplaces that will forbid its use (however silly that may seem).

But, if you think you'll be able to use it anywhere, then by all means concentrate mostly on it.

If there's functionality provided by the STL but not Boost, concentrate on learning those bits of the STL.

paxdiablo
There are indeed places that forbid (or make it impossible to use) boost and other open source libraries. Even though the source code is available, some shops (government, cough, cough) think there are security risks with using open source software. It really sucks.
Brian Neal
+1  A: 

First go with STL because that is what you will be using most of the time. Mastering all the boost is really hard, check with boost for any library that is not available with c++ out of box.Like parsing library,graph library

yesraaj
You don't have to master all of boost just to use it.
Tim Matthews
+7  A: 

I'd suggest getting a clear handle on STL, before looking at Boost. Boost is meant to build on top of STL and many of the libraries are slated to become part of the standard library eventually. Boost libraries are generally less mature and less standard than STL. Also, many boost libraries go too far, in my opinion, adding "features" that don't natively exist in C++ (leading to really insane syntax). In many cases there are more sane C++ idioms available for solving most programming problems without using these arcane Boost libraries.

postfuturist
Out of curiosity -- could you give some examples of the "many cases" where a more sane (portable) C++ idiom exists? I've only used a subset of the Boost libs, and haven't really found that to be the case, yet.
Pukku
+1  A: 

I'd go with learning STL first.

Once you're past the basics with C++, learning how to use parts of STL and then how it works will be better than tackling Boost. The Boost libraries tend to push the edges of C++ especially in combinations of highly-templated functions.

I like Matt Austern's Generic Programming and the STL which you can pickup cheaply secondhand.

Andy Dent
+24  A: 

The STL has some core concepts to it. Boost builds on and expands on them. If you understand them, then moving right on to Boost may be of use to you. If not, I would start with the STL.

  • The distinction between the various container types (sequences like vector, list and deque, and associations like map, set and their multi* and unordered_* varieties). Sometimes you can swap one for the other -- sometimes you can't. Know their strengths and their limits.
  • The role of iterators, and how they provide a bridge between containers and algorithms. (This one I find I use over and over).
  • Why there are standard algorithms: they are often tiny amounts of code, so it may not be obvious why they exist. Learn which containers they work with, and how to specialize them for particular cases (for example see how generic copy differs from copy specialized for const char *).
  • How and when traits classes are used.
  • How to use binders (bind1st, ptr_fun and mem_fun): the syntax can obscure their utility.
  • How to use string -- and when not to use it. (All string classes have tradeoffs: learning the pros and cons of the standard one is educational).
  • The difference between streams and streambufs: how to use the former to do formatted I/O (try reading a string from a stream: it's not as straightforward as it should be), and the latter to do low-level fast I/O.

The principles used to design the STL are built upon and expanded on by the Boost libraries. If you get them, Boost is manageable. If you don't, and Boost ends up hard to follow, you can go back to the STL to get your bearings.

(In general Boost really pushes the boundaries of the language. If you decide you want to really push your own knowledge of C++, and test if you really know what you think you know then it can provide an interesting challenge. I've used C++ for more than a dozen years, have taught other people how to use it, have acquired proficiency in many more high-level languages since then and Boost still surprises me. It's very useful, but its not trivial).

quark
+5  A: 

I think it's fine to use both straight from the start. Boost provides many powerful features, is widely used, and has a good reputation. Most of the things it provides share the same generic-programming concepts with which the STL was designed, so in that sense it should not be very confusing.

The best way to learn something is to use great code and then go and see how it was written. This worked well for me with Boost. Read a templates tutorial, and you're inspired by the new power you discovered for an hour. Then read a Boost header that you've been using for a bit, and you'll be inspired for weeks.

Of course, don't expect to understand those internals immediately - at first I just used the libraries without understanding how you would build any of that, and that's fine. But at some point you realise you want to write something with a similar design, and then you'll go looking.

If you'd do the opposite, and restrict yourself to "C++ as a safer C", then you wouldn't be exposed to all these powerful things, so you wouldn't be as tempted to look and understand them, and so you would write rather primitive code and learn more slowly.

EDIT: forgot that I had another thought - have a look at the upcoming C++0x standard too. It incorporates many features that originated in Boost. That is, students who start learning C++ a few years from now would be working with these concepts from the very start - you might as well do that today too...

yungchin
+1  A: 

Learn by programming and use the tools best suited. If you're programming something that needs a lot of parsing then you'll maybe learn some of boost spirit, but before you get that far you'll also have learned stuff about std::string and std::fstream. the next app you write will maybe need std::vectors and boost::accumulators.

Just remember boost is huge, you'll be a good quality programmer way before you've used even a quarter of it (personally I don't expect to ever use or learn most of boost because I don't need it...).

Patrick
A: 

Learn the STL first. If you learn C++ with Boost from the start you will have a hard time later in a job where Boost is not used (because of licensing reasons etc). Know the language standard first, and then expand it with Boost later if you need it for certain things.

+4  A: 

Ultimately, you should learn both. But STL can be learned in isolation, whereas boost won't make much sense until you understand the STL, since that's what Boost is modeled on, and designed to extend. So learn to use the STL as part of learning c++. And then you can move on to Boost, which is more or less the "second standard library" these days.

jalf