eliminate writeln et comp?

Denis Koroskin 2korden at gmail.com
Tue Mar 17 18:23:09 PDT 2009


On Wed, 18 Mar 2009 03:26:16 +0300, Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org> wrote:

> Denis Koroskin wrote:
>> That's not a very frequent operation. In most cases you should use  
>> Cout("Hello"); instead. An ideal design solution, imo (fast, short and  
>> clear).
>
> Interesting. Should I do the same in phobos?
>
> stdout("wyda");
>
> I'd like that particularly because write() is too common a name to place  
> at namespace level for my taste. So then we'd have:
>
> stdout("wyda"); // no newline
> stdout("wyda\n"); // newline but no flushing on binary stream
> stdout("wyda", newline); // write'n'flush
> stdout.writeln("wyda"); // same
>
> If we go that route I'll even drop writeln and rely on passing newline.  
> For formatting there'd be stdout.format and stdout.formatln or something.
>

This is funny because Tango has adopted exactly the same design.
The only difference is that Stdout is written in upper case:

import tango.io.Stdout;

void main() {
    Stdout("Hello, World\n"); // no flushing
    Stdout("Hello, World").newline; // new line appended, flushs
    Stdout.format("Hello, {}!", "Andrei").newline; // formatting
    Stdout.formatln("Hello, {}!", "Kris");
}

It would be great if the two libraries share the same interface.

BTW, since you are in process of redesigning of Phobos IO/stream system, it would be great if you take a look at the Tango IO system, first. I recall you telling that you didn't give a good look at Tango, so now is the time. I particularly insist on talking to Kris about it; perhaps, he has some ideas on the topic. He may also share experience with you (errors he made etc). I'll give you a few ideas of mine in a separate post.

You shouldn't avoid looking on someone's code, especially if it may help D get better standard library. There's nothing wrong with borrowing ideas from others, too, especially if they give you a permission for that. Tango is dual-licensed under Academic Free License v3.0 and BSD License, so there might not be a need to, but anyway.

>> Back on topic, in most cases I use:
>>  debug writefln("hello");
>>  because I have no console in release version (and it throws when there  
>> is no stdout, look in the bugzilla for a bug report). It is already  
>> long enough, so I wouldn't like it to be even longer:
>>  debug stdio.writefln("hello");
>>  My 0.02 rubles.
>>
>
> Got them.
>
>
> Andrei






More information about the Digitalmars-d mailing list