Exceptional coding style

monarch_dodra monarchdodra at gmail.com
Tue Jan 15 00:29:58 PST 2013


On Tuesday, 15 January 2013 at 07:38:01 UTC, Jacob Carlborg wrote:
> On 2013-01-14 22:40, H. S. Teoh wrote:
>
>> Stream operators are teh eviil. Overloading << and >> for I/O 
>> was a
>> horrible design decision. Operator overloading should be 
>> reserved for
>> numeric types. But then again, Stroustrup didn't have the 
>> benefit of
>> hindsight back then, and certainly, on the surface, 
>> overloading <<
>> and >> seemed like a cool thing to do. And C++ didn't (still 
>> doesn't?)
>> have typesafe handling of variadics, so the desire to not have 
>> to write
>> "cout.put(x); cout.put(y); cout.put(z); cout.put(w); ..." is
>> understandable.
>
> C++11 has variadic templates.

Let's not forget variadic templates are bleeding edge here.

C++ streams are 20 years old. They are inconvenient, ugly, and 
hard to use, *but* they are strongly typed *and* safe, both for 
read and wright. And they work. Just because there is something 
better today doesn't mean they were a mistake.

*Sure*, today, they can use "writeln(T...)", but not 20 years 
ago. On the subject of safety, I still prefer "writeln" over 
"writefln". While writefln is safe, you can still botch the 
amount of args, and or flag types, in which case writefln will 
throw. Writeln never throws (due to a code error).


More information about the Digitalmars-d mailing list