Notes from C++ static analysis

Jonathan M Davis jmdavisProg at gmx.com
Wed Jun 26 16:42:10 PDT 2013


On Wednesday, June 26, 2013 23:47:32 Paulo Pinto wrote:
> I have been an adept of iostreams since day one and never understood why
> people complain so much about them or the operator<< and operator>>
> for that matter.

I actually like them (particularly because I really don't like how primitive 
printf is with regards to types), but they fail completely when it comes to 
formatting, and you have to break up your strings too much. e.g.

cout << "[" << value1 << ", " << value2 << "]" << endl;

instead of

printf("[%d, %d]\n", value1, value2);

writefln fixes the typing problem that printf has in that it's not only type 
safe, but it allows you to just use %s everywhere (and you don't have to use 
c_str() on strings all over the place like with C++'s std::string), so I 
definitely think that what we have with D is far better than either iostreams 
or printf.

But with C++, which I use depends on my mood and the code, because both 
iostreams and printf suck. They just suck differently. But I've never actually 
minded that they used the shift operators for I/O beyond the fact that putting 
a bunch of values in the middle of a string with iostreams breaks things up 
too much (unlike with format strings).

- Jonathan M Davis


More information about the Digitalmars-d mailing list