14

I depend heavily on Python's standard library, both for useful data structures and manipulators (e.g., collections and itertools) and for utilities (e.g., optparse, json, and logging), to skip the boilerplate and just Get Things Done. Looking through documentation on the C++ standard library, it seems entirely about data structures, with little in the way of the "batteries included" in Python's standard library.

The Boost library is the only open-source C++ library collection I know of that resembles the Python standard library, however while it does have utility libraries such as Regular Expression support, most of it is also dedicated to data structures. I'm just really surprised that even something as simple as assured parsing and writing a CSV file, made delightfully simple with the Python csv module, looks to require rolling-your-own in C++ (even if you leverage some parsing library by Boost).

Are there other open-source libraries out there for C++ that provide "batteries"? If not, what do you do as a C++ programmer: hunt for individual utility libraries (and if so, how), or just roll your own (which seems annoying and wasteful)?

Community
  • 1
  • 1
gotgenes
  • 38,661
  • 28
  • 100
  • 128
  • 4
    If you don't mind a little overhead (and you rely THAT heavily on Python), you COULD always embed the Python interpreter into your C app :) http://docs.python.org/extending/embedding.html – Demian Brecht Dec 16 '10 at 21:03
  • 2
    @Demian That's true, however I will be completely perplexed if there's no direct C/C++ equivalent to many of these tools. If TIOBE, LangPop, and the quantity of Stack Overflow tags are any indication, C++ is still more widely used than Python, not to mention is a decade older than Python. – gotgenes Dec 16 '10 at 21:09
  • @gotgenes: "I will be completely perplexed if there's no direct C/C++ equivalent to many of these tools". No you won't. You'll be running Python. There will be no perplexity at all. Embedding Python in C means you're still using Python. – S.Lott Dec 16 '10 at 21:17
  • @S.Lott: I don't know if I follow. Are you implying that those kinds of utilities are frustrating to write in C++ and so they're left to be written in Python and other very high level languages? – gotgenes Dec 16 '10 at 21:36
  • @gotgenes: "you COULD always embed the Python interpreter into your C app". That means your C app uses Python inside it. You would simply use Python from within your C app. Your C app would contain a copy of Python inside it. – S.Lott Dec 16 '10 at 21:41
  • 3
    @gotgenes: The reason that there are still so many people/companies using C++, when there are alternatives like Python available, is 95% legacy. People have always used C++, and thus they will continue to use it. The smart thing however, is to acknowledge what each language is good at, and use a clever combination (C/C++ and Python interact beautifully). – Björn Pollex Dec 16 '10 at 22:33
  • 1
    @Space_C0wb0y: I see your point. I was motivated to ask this question because I have written a scientific application (using an MCMC method) in Python. It is too slow, despite profiling and optimizing in Python. My advisor said to just re-write it in C++. I would love to speed up the Python program with C or C++, but I don't understand how to go about that. (See http://stackoverflow.com/questions/4189328/tutorials-on-optimizing-non-trivial-python-applications-with-c-extensions.) Hence, I'm looking for C++ equivalents to known tools. – gotgenes Dec 16 '10 at 23:09

5 Answers5

5

The Poco library is more like other languages' standard libraries.

Actually the Poco web site's logo says "C++ now comes with batteries included!", which seems to be precisely what you're asking for.

I didn't like it when I tried because I found it too C-like and with too many dependencies between parts (difficult to single out just the functionality you want).

But there are many people & firms using it, so it seems I'm in minority and you will perhaps find it very useful.

In addition, as others have mentioned, for data structures, parsers, and indeed an interface to Python!, and such stuff, check out Boost.

Cheers & hth.,

Cheers and hth. - Alf
  • 142,714
  • 15
  • 209
  • 331
4

While C++ does offer many of the comforts extended by OO it keeps a very simple standard library. C++ has STL and Boost. These are very good, and have more then just datastructures.

If your needs are these sorts of higher order functions for prototyping or making application without intense (relative term) speed requirements then C/C++ is probably not the right choice for you. I believe you will find that for most projects that high level languages will be fast enough for your needs. If you are working on an application that requires C/C++ speed (and accompanying standard deviations) then you should probably invest your time carefully picking each individual library you will be using.

Alex
  • 6,843
  • 10
  • 52
  • 71
  • 2
    C++ does not "have STL". The STL, as an actual third-party thing, is very, **very** old (older than the C++98 standardization), and *almost all of it* is found in the C++ standard library (as of that standardization). C++ offers a much more extensive standard library than most people give it credit for. (Many pieces of Boost are found in the C++0x standard library, too.) – Karl Knechtel Dec 16 '10 at 22:06
1

http://beta.boost.org/community/sandbox.html

http://www.boostpro.com/vault/

also you can google for "boost+bar", eg

Anycorn
  • 50,217
  • 42
  • 167
  • 261
1

http://www.boost.org/doc/libs/1_45_0/?view=categorized

Boost isn't just about data structures - it has lots of the batteries you want - parsing, threads, collections, logging, etc.

Colin
  • 3,670
  • 1
  • 25
  • 36
  • Actually, as aaa pointed out, logging is not (yet) part of the Boost libraries. http://boost-log.sourceforge.net/libs/log/doc/html/ – gotgenes Dec 16 '10 at 21:23
0

With C and C++ you typically won't find a "do it all" library, instead you'll use individual libraries that do different things. You can use one library that does JSON parsing, one that does crypto, one that does logging, etc.

Boost and Qt are the only ones that would be more of a "do it all" type library.

jonescb
  • 22,013
  • 7
  • 46
  • 42