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

No comments: