[Box Backup-dev] Getting trunk ready for release

Martin Ebourne boxbackup-dev at fluffy.co.uk
Thu Dec 15 17:11:39 GMT 2005


Ben Summers <ben at fluffy.co.uk> wrote:
> Wonderful. So some stupid example in a textbook just to demonstrate  
> that operator overloading can be used to do things other than the  
> operations that the operators imply (with all the potential for  
> confusion, bugs, etc that that entails) is now going to pollute this  
> project with it's idiocy?

Ben,

I'm not sure I exactly understand your position on streams. I thought 
you meant you didn't want operator<< defined on box's own objects, but 
now it sounds like you don't want << used at all in the code for output.

While I fully agree with you on most operator overloading (I've worked 
on lots of C++ and seen a lot of evil operator abuse), streams is one 
of the places where it really is useful. It's not a stupid example in a 
textbook, it's the way the C++ libraries are designed. Because it is so 
endemic to C++ and so common the pitfalls are generally avoided. 
Everyone knows what it does, what it means, and how it works. Those are 
the main disadvantages of bad operator overloading.

Finding bugs in streams use (related to the operator itself) is 
extremely rare. About the only mistake is to forget that the precedence 
of << is higher than of some other operators. In that case it almost 
always fails to compile so there is no bug anyway.

I don't think anyone is going to ostream box and fill it with uses of 
<< if you say no, but hopefully that isn't the case. Streams is the 
only viable way of type safe output provided by C++.

The current use of printf is a significant issue. I've ported box to 
several platforms and making the format string match the arguments is 
impossible on all platforms due to the different use of types. For that 
reason we have a load of '#ifdef WIN32' code just to provide alternate 
format specifiers for windows.

Historically I've also seen more bugs with bad printf use than bad 
stream use. It's very easy and common to get the format specifier 
wrong, and almost nobody understands the implicit promotion rules of 
values passed to a varargs function, which creates quite a few bugs. 
There's no attempt at type safety with printf so a lot of problems are 
only run time detectable.

Cheers,

Martin.



More information about the Boxbackup-dev mailing list