Comment by wmu

9 years ago

It is written from the perspective of amateur. C++ exceptions comes at no cost. RTTI comes at no cost. C printf is unsafe; one can write perfectly safe printf-like formatters in C++ (did it, works well). Why one can use metaprogramming but not STL? A programmer can plug a custom allocator in STL containers, if an allocator is a problem.

C++ exceptions definitely come at some non-zero cost, albeit very small on the happy path, both in terms of runtime and code size. RTTI also comes at a cost of higher memory footprint, but more importantly relying on RTTI is a sign of bad design in most cases. C printf is unsafe, but most IDEs figure this out and show appropriate warnings. The biggest problem with C++ streams is not lack of printf-like formatters, but the fact that formatting is part of stream state and is not as clearly separated from the printed content as in printf.

  • It was comparison posted at HN -- exceptions were more efficient in case of deep stack unwinding, when compared to testing return codes. But of course, they are not totally free. RTTI memory footprint is negligible in practice; I work on a huge application, having thousands of classes. Nobody cares about the size of RTTI structures, it was never a problem. (Lack of standard API for RTTI is a pain in the neck -- GCC has nice non-standard solution, but MSVC has nothing.) I agree with you that overusing RTTI, like dynamic_cast, might be a sign of design flaw.

    Speaking of printf, I meant its counterpart, like boost::format; it accepts format strings but is safe. It can throw an exception in case of an error, and a programmer can react accordingly.

    I hate C++ streams, they're slow and cumbersome, one of the worst solution ever. I think lack of format string is their main problem.