/ :: bitbashing

Some C++ Libraries Worth Looking At

C++ is a horribly schizophrenic language. The infamous Stroustrup quote that "In C++ it's harder to shoot yourself in the foot, but when you do, you blow off your whole leg" goes a long way towards describing the issue - C++ is a language of surprising expressive power, but most of the time that power is aimed at feet. But when it's used well, it leads to some rather lovely pieces of code. Here's my rundown of some favorite C++ libraries. All of these libraries are freely usable in both open source and commercial applications; while that wasn't a precondition, it is a very nice bonus.

Boost

Boost is probably going to be on every list of C++ libraries worth using. While I haven't used all of the libraries in Boost, I can say that Boost.Python and the function/bind library are quite lovely to use.

Building it from source is a good reminder of how slow GCC can be, though. Install binaries if you can.

SOCI

SOCI provides a very reasonable interface to relational databases, with plugins for SQLite, Postgres, and various databases I never use and don't much care about (Oracle and MySQL). A quick example.

sql << "select phone from phonebook where name = :name",
       into(phone), use(name);

Downsides include the build system, which is less than enlightened, and the fact that some ways of using the library seem to leave applications open to SQL injection attacks.

OTL is another C++ database/SQL library. It seems interesting, though SOCI's syntax feels more natural to me, and OTL's database support is heavily biased towards Oracle and MS SQL; again, nothing against either of these databases, I just don't see myself using them often. Or ever, for that matter. Others are supported through ODBC, but are apparently somewhat beta-ish.

GTKmm

GTKmm is the first C++ GUI toolkit I've seen that I would actually want to program in. Partially, this is due to GTKmm's advantage over other libraries, which are typically much older and developed their own string/vector/assocarray/etc classes; which, of course, doesn't play very well with the rest of your STL-using code. One could drink the full glass of Kool-Aid and use the GUI toolkit types in all your code, but the idea of tying my entire application to the interface code doesn't give me good feelings. In contrast, GTKmm plays nicely with the STL, is cleanly designed, and seems significantly more extensible than I'll ever need. Support for Aqua would be really nice, but then again, I don't own a Mac, so what do I care?

Botan

Sheesh, what do you expect? I wrote the stupid thing. Anyway, I feel like the design is quite nice, much less due to my own brilliant coding ability (hah!) than my willingness to steal good ideas wherever and whenever possible. To provide some redeeming social value to this section, I'll mention that Crypto++ is the "other" C++ crypto library. They're very different in terms of style, so if you're looking for something in this niche I'd recommend trying them both and deciding which one feels more natural to your programming style.

Blitz++ and POOMA are often considered among the Tier 1 C++ libraries, but as I don't have much interest (or ability) in hydrodynamics, they have little practical use for me. On the other hand, work on these libraries has produced a number of interesting papers and new techniques - as a source of inspiration for writing high-performance C++ code, they can certainly be worth examining.

You might have noted a distinct lack of network libraries on this list. There are literally dozens out there, the best of which seems to be Netxx, which, aside from the fact that it's not maintained anymore, seems quite decent. It's not entirely perfect (perfect being defined as "how I would do it"), but having gone down that rabbithole once (see above), I'm willing to settle for a solid 98%. I'm not sure if I'm willing to settle for "maintain it yourself", though. A much heavier alternative is ACE, but the more I look at ACE the leerier I become of it. ACE is in much the same state as Qt; a good, interesting, solid state-of-the-art-in-1994-or-so design that hasn't been updated in a decade due to compatibility concerns. Right now I'm thinking of it more as a source of ideas than of code.

So what is missing from our box of C++ libraries? Most C++ applications could benefit from judicious use of the STL and the Boost libraries. GTKmm seems a solid choice for GUIs (assuming you don't just wrap your low-level code using Boost.Python or SWIG and then write the GUI in Python or Ruby). Networking is a bit of a hole, though you've certainly have a number of options there; there just doesn't seem to be a compelling choice right now.

I'd like to see an embedded language (ideally of a Scheme/Lisp flavor) that really got along well with C++ code. A decent P2P library (perhaps something interoperating with JXTA or OpenDHT) would be delightful.

For another perspective on some of this, I'd recommend this post by Graydon Hoare, which while somewhat dated (2004) is very much worth reading (I'm willing to attest that he is both smarter and a better programmer than I am - though I'm not sure how much that opinion is worth to anyone).

Posted 2006/09/25 in programming; no comments

< Finding Equivalences of Boolean Function | Wildly Expensive Toys >

Name:


E-mail:


URL:


Comment: