Skip to main content

C++ and its major Boost

C++ has some major shortcomings. The STL doesn't include a hash map using custom keys, its string to number converters make it hard to detect errors, and there just seem to be so many languages that are bundled with better standard libraries (look at Java and its support for Time/Date, atomic type conversion).

However, I am a huge fan of C++. I like the fact that there are unsigned types (unlike Java), type safety makes code less error prone (unlike python, ruby, and perl), it is polymorphic and inheritable (unlike C), its reference types provide speed, and it is ported more often to embedded platforms than any other language besides maybe C. So, how are these strengths leveraged by overcoming the obvious weaknesses?

Enter Boost. It has solutions for many of the shortcomings of C++ and some very useful utilities as well. In a recent development project, I used Boost as a supplement to C++ within the Windows environment because I wasn't sold on the .NET framework, and I wanted to be platform compatible with Linux. Boost provided this cross-platform capability with several utilities:
  • lexical_cast, a cast function that allowed for easy translation between string and numeric types,
  • command options, a library that takes command line arguments and parses them against registered available options,
  • unsorted map and hash function, which allowed for custom key types for maps that allowed for faster lexicographical comparisons than something like a string key,
  • bimaps, a bidirectional map that allows for searching for a key-value pair in both directions,
  • time duration and posix time, which allowed for the representation and the arithmetic operations of microsecond-resolution time values,
  • progress timer, which provided a report of the elapsed time for a program operation as it finished,
  • progress bar, which provided a very simple interface to print out a progress bar to the command prompt,
  • macro processing, which allowed for easy comma-delimited expansion of arrays without having to write the code explicitly (think variadic macros like printf), and finally
  • foreach, which looped through a container by providing the actual reference to the object pointed by the iterator.

The command line options and progress bar were of real big help to me, but my favorite utilities were the lexical_cast and the time libraries. I liked lexical cast because I could literally take any string value and easily convert it to an integer, float, double, etc. with just one line of code that also provides for error checking. The time objects (time_duration and ptime) were indispensable, particularly when I started chasing down the rat-hole of trying to come up with my own operators and conversion functions for time since I was taking time stamps and trying to perform arithmetic on them. One does not truly appreciate the amount of time and effort that these code writers have put into the Boost package until one realizes just how much work is required to get things just right. And isn't that just what software development is all about.

Published with Blogger-droid v1.6.8

Comments

Popular posts from this blog

Software Design Principles - SOLID

The SOLID software design principles weren't called SOLID while I was in grad school, but the concepts were there in my Object Oriented Design course. They're worth mentioning here, primarily because I think once you start coding and become dangerous, it's one of the best ways to stay organized once you incorporate it into your daily coding routines, and it even changes your way of thinking for the better: https://en.wikipedia.org/wiki/SOLID

Best Documentation of a Free Software Package

One oft overlooked artifact in software development is the documentation. An API that is not well documented is no API at all when time is of the essence. That's why I think it is important to discuss some of the tools I have used and their documentation. AutoIt - I love how you simply press F1 within the AutoIt editor and boom, the reference to the particular syntax or function pops up in the help window. This help file is well written, self-contained, and chock full of examples that can be opened up in the editor right from the help, a fantastic symbiotic relationship. After installing AutoIt and giving it a try using their examples, I was able to create client/server scripts, GUI scripts, and window management scripts in no time. Overall, AutoIt is tops in this competition. A+ MySQL - At the bottom of each page of documentation that discusses a particular statement, users are able to post comments containing code snippets for that particular statement. This is great... M

Matlab and MySQL

I had a lot of data in a MySQL database that I wanted to analyze. I had a copy of Matlab, so I figured the best way to look at this all would be to plot this data and use some GUI elements to go through various combinations. After some Googling, I found this database connector that seemed to do the trick. I downloaded the files, configured mex to use MSVC 2008, built the connector, then I was able to successfully connect over the network! I ran into two problems, though: The connector does not support fetching columns of type TIMESTAMP, and With the magnitude of data (about 180k rows), access times were really slow. I was able to solve problem #1 by changing my columns to DATETIME, which was supported. I'm still trying to figure out problem #2. It may come down to importing all the data directly into Matlab.