Martin Pool's blog

Plumbing the depths of poor interface design

I hit a particularly precise example of Rusty's API quality spectrum today in some WBEM code.

What's wrong with this code?

member_kb.append(CIMKeyBinding("CreationClassName", "HP_Processor"));

Not much, on first glance. Looks pretty reasonable. But it turns out for some reason that CreationClassName is getting recorded as True, because the second argument gets coerced to a boolean (being non-null). The fix is

member_kb.append(CIMKeyBinding("CreationClassName", String("HP_Processor")));

Yes, this code has its own C++ String class, which is perhaps forgiveable in old code. What is less forgiveable is that C-style char* will almost, but not quite always get coerced into a String object; sometimes into something else. I could even cope if it gave an error and made me go back and check it ("compiler won't let you get it wrong"), but this is just bizarre.

This achieves a pretty high score's on Rusty's scale: The obvious use is wrong.

[This is not a reflection on OpenPegasus as a whole, which is actually pretty clean aside from being non-STL. That's just where I happened to find the example.]

Archives 2008: Apr Feb 2007: Jul May Feb Jan 2006: Dec Nov Oct Sep Aug Jul Jun Jan 2005: Sep Aug Jul Jun May Apr Mar Feb Jan 2004: Dec Nov Oct Sep Aug Jul Jun May Apr Mar Feb Jan 2003: Dec Nov Oct Sep Aug Jul Jun May