The Daily WTF
We previously discussed some whitespacing choices in a C++ codebase. Tim promised that there were more WTFs lurking in there, and has delivered one.
Let’s start with this class constructor:
QBatch_arithExpr::QBatch_arithExpr(QBatch_unOp, const QBatch_snippet &, const QBatch_snippet &);
You’ll notice that this takes a parameter of type QBatch_unOp. What is that type? Well, it’s an enumerated type describing the kind of operation this arithExpr represents. That is to say, they’re not using real inheritance, but instead switching on the QBatch_unOp value to decide which code branch to execute- hand-made, home-grown artisanal inheritance. And while there are legitimate reasons to avoid inheritance, this is a clear case of “is-a” relationships, and it would allow compile-time checking of how you combine your types.
Tim also points out the use of the “repugnant west const“, which is maybe a strong way to word it, but definitely using only “east const” makes it a
To read the full article click on the 'post' link at the top.