2

For a long time being a Java programmer and only hearing boost mentioned I thought it was so favoured because the Standard C++ language doesn't have any mechanism for threading. However, I then stumbled on the fact that there are libraries one can use on linux for threading. Therefore I am a little puzzled why the boost libraries are so popular?

From the perspective of someone deciding which parts of boost to get "stuck in" and learn, could programmers who use it please explain why it is so popular and the most favoured parts from the point of view of recruiters (preferably financial development)?

To make this more Stackoverflow-friendly, what are the libraries/features which make boost what it is?

user997112
  • 29,025
  • 43
  • 182
  • 361
  • 1
    Duck! Many here won't like your question :) – trojanfoe Nov 22 '11 at 18:01
  • Actually I think this has a reasonable technical answer. But then, maybe it's a better fit for programmers-dot. – Andres Jaan Tack Nov 22 '11 at 18:02
  • 2
    have you ever converted a std::string to a int in c++? – Alessandro Teruzzi Nov 22 '11 at 18:06
  • As a "programmer who uses it" in our flagship application I use asio, thread, GIL, range, smart_ptr, date_time, filesystem, CRC, dynamic_bitset, lexical_cast, iostreams, lambda, bind, serialization, tokenizer, Spirit -- off the top of my head. Not finance though. – Cubbi Nov 22 '11 at 18:10
  • 1
    At least a partial dupe of [this](http://stackoverflow.com/questions/125580/what-are-the-advantages-of-using-the-c-boost-libraries), but for me, this is too subjective for SO. – razlebe Nov 22 '11 at 18:10
  • Have you looked at the [Boost website](http://www.boost.org)? That would at the very least inform you of what Boost is besides the threading you mention. Usefulness and popularity can be discussed from there onward, but I'm not sure this is the right place. – Bart Nov 22 '11 at 18:13
  • I agree with @AndresJaanTack, this question contains at least some non-subjective answerable content. – SoapBox Nov 22 '11 at 18:16
  • @Soap The only non-subjective bit is "what are the libraries/features which make boost what it is?", which is a "list question". – razlebe Nov 22 '11 at 18:18

6 Answers6

6

I thought it was so favoured because the Standard C++ language doesn't have any mechanism for threading. However, I then stumbled on the fact that there are libraries one can use on linux for threading.

That's odd reasoning. There is a lot more to Boost than threading. Plus, just because there's a Linux library for threading doesn't mean it will work on your Windows code; Boost.Thread is cross-platform.

Allow me to hit some of the high points of Boost:

Smart Pointers

C++11 now has most of these (and improvements on them using C++11 language features). But for the past 8+ years, this was where you came for a good shared_ptr implementation. Use of these things should be mandatory where possible.

They make life in C++ so much simpler.

Regex

Not my cup of tea, and another Boost library incorporated into C++11. But if you want to do regular expression searching of strings, it doesn't get much more standard than this.

Bind and Function

Yet another thing that was incorporated into C++11, but unless you have access to a C++11 compiler/library, Boost is your best bet for this. Being able to store any kind of "callable" object in an object is incredibly useful for callbacks. And being able to adapt "callable" objects to different sets of parameters is incredibly useful, particularly with algorithms.

Filesystem

C++ has standard library facilities for opening and closing files. But nothing for looking for them or dealing with filenames. Boost does, and in a very nice API to boot. It handles platform-specific encoding through a platform-neutral interface. It allows Unicode support across those platforms that have it, etc.

Range

You know how the standard algorithms take a begin and end iterator, but most of the time you really just want it to walk the whole container? Range is here for you. It defines iterator ranges (which containers are), and it provides algorithm variants that take range objects explicitly.

What's great about Range is that the range algorithms are lazily evaluated. So you can do functional-style composition of algorithms, which works efficiently. Many algorithms return a range (which is really a range placeholder); if you feed one range into another range, you can get powerful effects with simple composition.

Variant

AKA: a type-safe union. Once you put an object of type X into it, you cannot get anything but type X out of it. Period. This is a useful tool for doing some light runtime-polymorphism work without having to use a derived class.

These are just a few of the libraries in Boost.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
3

Boost is in part, a staging arena for proposals for the standard template library. It has strong threads solutions. However, boost also provides a wide range of other things such as containers, expression parsers... It is famous because it is a central repository for C++ non-standard libraries.

perreal
  • 94,503
  • 21
  • 155
  • 181
  • 1
    +1, I think it has to do with threading, though, perhaps not only. Isn't std threading mostly based on work one in boost, the way you mention in the first sentence? (that said, I have to admit, I find boost overrated and don't really like it in its entirety). – Michael Krelin - hacker Nov 22 '11 at 18:12
  • But the way OP puts it sounds like boost is a threads library, which is wrong. Saying boost is a threads library is as wrong as saying a library is a threads library :D – perreal Nov 22 '11 at 18:19
  • I agree completely, but the way you put it it sounds like boost has too little to do with threads, whereas, I find it important to point out that even with this thread-centric attitude you can't dismiss boost. – Michael Krelin - hacker Nov 22 '11 at 18:22
2

These are the libraries/features which make boost what it is. Threading is not the only thing you want to do in an application... The most "favored" depends on what you are programming, all of the libraries are useful, otherwise it would be unlikely to have been included.

ronag
  • 49,529
  • 25
  • 126
  • 221
1

Boost is just a big non-standard library collection.

C++'s STL is getting better and better, yet it's not nearly as huge as Boost (and is not intended to).

Think of Boost as a collection of useful libraries (for various purposes from math thru parsers thru containers to metaprogramming, see the docs for the list) which is known to be of good quality and just happens to be packaged together.

Kos
  • 70,399
  • 25
  • 169
  • 233
1

"boost" is just a repository of high quality C++ libs. If you write a good C++ library useful for a lot of people and which meets boost quality standard, you can ask it to be added to boost.

It happened that influent C++ programmers who are working on the C++ standards are also writers of some boost libs. Some boost libs are now standard. That makes it a central place for the C++ community.

Concerning your question about threads, boost would offer portability over using a linux-only thread lib. The boost version works on windows, too.

Offirmo
  • 18,962
  • 12
  • 76
  • 97
  • Good answer, though it should be noted that, because several Boost contributors participate heavily in the standards committee, Boost works as a sort of spawning pool for future C++ library additions. As you mentioned, it has a very rigorous standard for admission, and libraries that are vetted and widely used by the community will often have enough popularity to be added to the standard. – matthias Nov 22 '11 at 19:14
0

As a Java program you're probably used to having classes available at your fingerprints for doing a wide variety of things, from threading to XML parsing to logging to regular expressions.

The C++ core language is sparse in this regard compared to most other languages. We've got containers and algorithms, but not a lot else. Boost fills some of the gap between C++ and other languages in terms of ready-made and test libraries that we can import and useo right away rather than spend time reinventing them.

In C++11, some of the best libraries in Boost (Regex, Unordered Cntainers, Smart Ptr to name a few) are becoming part of the language. That isn't a coincidence, it's a direct result of their popularity and maturity as part of Boost.

In terms of what is most attractive, I would say a cursory familiarity with every library would be most important. Be able to say "Yes I've used boost" and "Boost.Widget" would be a good fit for this problem. Most everything else is just API reference.

If I had to pick one: Boost.Asio has definitely changed the way I think about networking. (And it's use of shared_from_this() and Smart Ptr show me new ways to think about memory management. Sorry, I guess that's two.)

SoapBox
  • 20,457
  • 3
  • 51
  • 87