An interesting critical comparison can be found here.
C ++ FQA io
Not very polite, but makes you think ...
Renouncement
C ++ FQA (this is a critical answer to frequently asked questions about C ++) is often viewed by the C ++ community as "a stupid joke issued by a stupid guy who doesn't even understand what C ++ is or wants to be" (cit. From FQA itself )
These arguments are often used to flame (or exit) religious battles between C ++ believers, other languages, believers or linguistic atheists, each in their own humble opinion, convinced to be superior to the other.
I'm not interested in such battles; I just like to stimulate critical discourse about the pros and cons. C ++ FQA - in this sense - has the advantage of placing both FQA and FAQ one on top of the other , which allows you to immediately compare. And this is the only reason I referred to her.
Following the TonyD comments below (tanks for them, I make it clear that my intention needs clarification ...), it should be noted that the OP does not just discuss << and >> (I just talk about them in my comments just for brevity) but the whole set of functions that make up the C and C ++ I / O model.
With this idea in mind, think of other “imperative” languages ​​(Java, Python, D ...), and you will see that they are more and more consistent with the C model than C ++. Sometimes this even makes the type safe (that the C model is not, and that its main drawback).
What is my point about
At a time when C ++ appeared as the main one (1996 or so), the library <iostream.h> (note the ".h": pre-ISO) was in a language where templates that are not yet fully accessible, and, in essence, the "strong" safe support for varidic functions (we need to wait until C ++ 11 receives them), but with overloaded types of functions .
The idea of ​​oveloading << reconfiguring its first parameter again and again is actually a way to bind a variable set of arguments using only a binary function that can be overloaded in a safe manner. This idea extends to any “state management function” (for example, width() or precision() ) using manipulators (for example, setw ) as a natural consequence. These points, despite the fact that you can tell the author of the FQA, are real facts. And also the fact that FQA is the only site I have found that talks about it.
However, years later, when the D language was developed, starting to offer varadic patterns, the writef function was added to the standard D library, which provides the printf syntax, but is also completely type safe. (see here )
C ++ 11 currently also has varadic templates ... so the same approach can be put in exactly the same way.
Moral of history
Both C ++ and C io models look "obsolete" in relation to the modern programming style. C keep speed, security at the C ++ level and a “more flexible abstraction for localization” (but I wonder how many C ++ programmers in the world know about locales and faces ...) when it takes time (track jut with debugger <number number, passing stream, language standard and facet ... and all the virtual functions associated with it!).
Model C can also be easily expanded to parametric messages (the order of the parameters depends on the localization of the text in which they are located) with format strings such as
@ 1% d @ 2% i, which allows you to create scripts like "text @2%i text @1%d ..."
The C ++ model does not have the concept of a “format string”: the order of parameters is fixed and marked with text.
But C ++ 11 varadic templates can be used to support:
- can offer both local selection of compilation time and runtime
- may offer a parametric order of compilation time and runtime
- may suggest a compilation type parameter type
- ... everything using a simple form methodology.
Is it time to standardize the new i / o C ++ model?