Saturday, August 25, 2012

Book Review: Safe C++ by Vladimir Kushnir


Safe C++: How to Lower the Bug Count of your C++ codeSafe C++: How to Lower the Bug Count of your C++ code by Vladimir Kushnir
My rating: 2 of 5 stars

Safe C++ bills itself as providing ways of avoiding common programming mistakes in C++ through a set of rules. While the author makes a convincing case that these rules are better than other sets of rules (for example, his rules are supposed to be affirmatively stated, i.e. a set of things to do rather a a set of thou shalt nots), these are still only a set of rules which are combined to his own library (a mix of testing framework and some replacements for some modules in the standard library).  And as such was somewhat disappointing.

As a disclosure, I am primarily a scientific/technical programmer, and I spend most of my time in the Scipy/Numpy Python stack and R.  And freely drop from there into C/C++/Java/Fortran as needed for performance or other reasons.  And I have completely bought into the idea that depending on compilers to find bugs is foolhardy, to do it right means to unit test everything.

Coming from a dynamic language and unittesting background, I found the first chapter on the use of the compiler to catch errors to be eyebrow raising at best.  And after several pages of argument, the problems turns out to be type conversions and the the use of enums, which are integers in disguise. Which are not problems in dynamic languages where you don't make type assumptions, and if you use unittesting, you don't get caught by passing around values that do not mean what you think they mean (because you catch that during the unittest).

Going through the rest, much of it revolves around using his C++ library (available through github and also printed in the book).  And these have two major categories.  One is a testing framework, which is a pretty good start on a unittesting framework of the type I'm used to.  The other category are essentially replacements to parts of the standard library, which get around flaws that he sees.  Reading the first type I started wondering why he did not just pick a unittesting framework/library and make that his example instead of building a partial one of his own.  The second, what he says sounds right to me, and is a worthy statement to make and learn, but it gets lost in everything else.

Kushnir is not the only writer that discusses common problems in programming C++ along with some rules/guidelines for programmers to avoid them.  But I am not convinced by his assertion that his set of rules is better than others.  And I suspect that one would be better served by a version of this book that dealt with using more full featured testing frameworks and more intelligent use of the standard libraries than this book which is built around his library.

Note:  I received a free electronic copy of this book through the O'Reilly Blogger program.


Safe C++: How to Avoid Common Mistakes by Vladimir Kushnir


View all my reviews
I review for the O'Reilly Blogger Review Program

Sunday, August 12, 2012

Parenting 21 months: Mommy school is in session

Taking a look at a butterfly It is the middle of summer, and with two academics in the house that means mommy school is in full swing. The foundation of recognizing all the letters (upper case) and numbers (1-10) has been well established, now the task at hand are three letter words. In addition to the landing study area, T gets quizzed using the alphabet letters and number we have at bathtime and the letter mats we have in the bedroom. Kidding aside, we noticed that what T remembers are the ends of words and phrases. So when there are words that end in the same letter/sound he gets confused. First letters are not a problem. We also noticed this with letter (that end with the 'eee' sound) and songs (he says the ends of phrases).

Another scholarly activity is reading. He will work through a book and there is a clear correspondence with the words saying and the page that is open. Clearly, this is mostly a result of memorizing the book, but there is some actual reading going on. His favorite is "Brown bear, brown bear, what do you see?". This was also the first book where he did the page turning while we read, so it is apparently still his favorite book.

Thursday, August 09, 2012

Building PostGIS on Ubuntu from source

I wanted to revisit PostGIS for an update on a project.  In the current version, we built a data table of distances, but I really want to be able to build this table based on a road network, i.e. if I have a road shapefile, pick two nodes and calculate the distance.  And sending many thousands of requests of this type over the internet to build the distance matrix is not very practical, especially if there are multiple road networks that need to be considered as well.

There are pre-built installers for Postgresql for all the major operating systems (Windows, OS X, Linux), but they seem to be version dependent.  i.e. it matters what version of the operating system you have, because the pre-built versions make assumptions about shared libraries and such (I think that is what is happening).  Plain Postgresql does not seem to be that much of a problem, but when adding in extensions (like PostGIS) it is.  So instead of fighting it, I decided to build the PostGIS stack on Linux.

Some issues along the way.

1.  Using ./configure -> make -> make install seemed to work smoothly (Postgresql 9.1, PostGIS 2.0.  note that I already have GEOS and PROJ libraries on my system)  But I needed to take a careful look at the config.log, because then I would have noticed that it could not find GTK+, dblatex and CUnit.

2.  To build the graphical shp2pgsql-gui plugin for Postgresql pgAdminIII, configure requires a --with-gui option.

3.  For GTK+, I had this on my system, but it was GTK3, and the pgAdmin actually requires GTK 2 development libraries.

4.  For CUnit, it requires the CUnit development libraries.

5.  After it is installed, shp2pgsql-gui is in the /usr/lib/postgresql/9.1/bin/ directory, not /usr/sbin as some places suggest.  So I needed to make a symbolic link using
   sudo ln -s /usr/lib/postgresql/9.1/bin/shp2pgsql-gui /usr/bin/shp2pgsql-gui

6.  Then I needed to add appropriate entries to the plugins.ini file, which is actually in /usr/share/pgadmin3/plugins.d directory

I took the entry found at GIS Stackoverflow
http://gis.stackexchange.com/questions/16181/how-can-i-enable-shapefile-gui-loader-in-pgadmin3

Now after this, it builds, all tests pass and the PostGIS graphical loader is working.