September 04, 2011
On 2011-09-04 06:53:27 +0000, Jonathan M Davis <jmdavisProg@gmx.com> said:

> On Saturday, September 03, 2011 23:49:52 Walter Bright wrote:
>> I still use printf a lot. One reason is because it is lightweight - using
>> writeln blows up the size of your .obj file, making it hard to track down a
>> back end bug. This is a long standing gripe I have with writeln.
> 
> Well, while that may be a good reason to use printf, it really doesn't apply
> to very many D programmers. Your average D programmer really has no need to
> use printf.

That may be true, but the average D programmer will also, directly or indirectly, call C APIs which may use printf to write things to the console. I'm not sure it's much of a problem though. For one thing, C APIs generally don't print things on their own.

And also, I doubt using D IO by default will break printf that much: I mean if C IO is used to print lines, those lines will be flushed as they're emitted, with no possible weird interleaving unless the line is really too long. And if you use both D and C IO together, likely you're just logging things to the console line by line and not outputting things in a specific format where weird interleaving could cause major breakage. I'm making some assumptions here, so maybe I'm wrong, but I can't really see a use case where both IO system would be used and where the fidelity of the output is that important… please correct me if I'm wrong.

So in my opinion the default should be to use D streams, as I don't expect the drawbacks to be a major inconvenience, and the performance gain of being able to access the buffer directly would certainly be welcome.

-- 
Michel Fortin
michel.fortin@michelf.com
http://michelf.com/

September 04, 2011
On 2011-09-04 04:48, Steven Schveighoffer wrote:
> On Sat, 03 Sep 2011 18:57:06 -0400, Andrej Mitrovic
> <andrej.mitrovich@gmail.com> wrote:
>
>> Also, changing structs to classes is gonna *massively* break code
>> everywhere. Why inheritance instead of a predicate like isInputStream
>> = is(typeof(T t; t.put; t.close)), you know the drill..
>
> Because it breaks runtime swapping of I/O.
>
> For example, if you wanted to change stdin to a network socket, it's
> simple, just assign another InputStream.
>
> However, if stdin is a templated struct, you cannot do this at runtime,
> you have to decide at compile time what your stdin is. Believe it or
> not, this is not dissimilar to FILE *, except we have more flexibility.
>
> But I realize the implications now. I think I have to revisit this
> decision.
>
> We definitely need classes at the lower level, but I think we can wrap
> them with structs that are commonly used for RAII and for not breaking
> existing code.
>
> -Steve

Tango has added a new method to Object, "dispose". The method is called by the runtime when a scoped class exits a scope:

void foo ()
{
    scope f = new File;
}

When "foo" exits File.dispose will be called and it can close any file handles. I think it's quite clever.

-- 
/Jacob Carlborg
September 04, 2011
On 9/4/11 12:11 AM, Walter Bright wrote:
> On 9/3/2011 8:22 PM, dsimcha wrote:
>> However, at the time I actually thought he just hated
>> std.parallelism at a gut level and was looking for any excuse to keep
>> it out of
>> Phobos. (I apologize for having thought this and therefore taken a
>> much more
>> adversarial view of the review process than I should have.)
>
> I can vouch for Andrei's reviews appearing to be personal, but they are
> not. He's mercilessly ripped up some of my stuff, but I had to agree he
> was right and the resulting improvement was well worth it.
>
> I don't much care for blowing sunshine, flattery and false praise.
>
> Andrei sets a high bar, I'm glad he does, and we'll all be better off
> for it.

This is a bit of a surprise for me because I fancy (fancied...) to see myself as this emotionless, rational reviewer. Thank you all for putting up with me.

Andrei
September 04, 2011
On 9/4/11 7:10 AM, Michel Fortin wrote:
> On 2011-09-04 06:53:27 +0000, Jonathan M Davis <jmdavisProg@gmx.com> said:
>
>> On Saturday, September 03, 2011 23:49:52 Walter Bright wrote:
>>> I still use printf a lot. One reason is because it is lightweight -
>>> using
>>> writeln blows up the size of your .obj file, making it hard to track
>>> down a
>>> back end bug. This is a long standing gripe I have with writeln.
>>
>> Well, while that may be a good reason to use printf, it really doesn't
>> apply
>> to very many D programmers. Your average D programmer really has no
>> need to
>> use printf.
>
> That may be true, but the average D programmer will also, directly or
> indirectly, call C APIs which may use printf to write things to the
> console. I'm not sure it's much of a problem though. For one thing, C
> APIs generally don't print things on their own.
>
> And also, I doubt using D IO by default will break printf that much: I
> mean if C IO is used to print lines, those lines will be flushed as
> they're emitted, with no possible weird interleaving unless the line is
> really too long.

No, things are more complex; the interference will be major unless explicitly addressed.

Andrei
September 04, 2011
On 9/4/11 7:11 AM, Jacob Carlborg wrote:
> On 2011-09-04 04:48, Steven Schveighoffer wrote:
>> On Sat, 03 Sep 2011 18:57:06 -0400, Andrej Mitrovic
>> <andrej.mitrovich@gmail.com> wrote:
>>
>>> Also, changing structs to classes is gonna *massively* break code
>>> everywhere. Why inheritance instead of a predicate like isInputStream
>>> = is(typeof(T t; t.put; t.close)), you know the drill..
>>
>> Because it breaks runtime swapping of I/O.
>>
>> For example, if you wanted to change stdin to a network socket, it's
>> simple, just assign another InputStream.
>>
>> However, if stdin is a templated struct, you cannot do this at runtime,
>> you have to decide at compile time what your stdin is. Believe it or
>> not, this is not dissimilar to FILE *, except we have more flexibility.
>>
>> But I realize the implications now. I think I have to revisit this
>> decision.
>>
>> We definitely need classes at the lower level, but I think we can wrap
>> them with structs that are commonly used for RAII and for not breaking
>> existing code.
>>
>> -Steve
>
> Tango has added a new method to Object, "dispose". The method is called
> by the runtime when a scoped class exits a scope:
>
> void foo ()
> {
> scope f = new File;
> }
>
> When "foo" exits File.dispose will be called and it can close any file
> handles. I think it's quite clever.

What happens if f is aliased beyond the existence of foo()?

Andrei

September 04, 2011
On 9/4/11, Paulo Pinto <pjmlp@progtools.org> wrote:
> Hi,
>
> what is an "abstract interface" ?

I'm wondering the same thing.
September 04, 2011
On 9/4/11 4:30 PM, Andrej Mitrovic wrote:
> On 9/4/11, Paulo Pinto<pjmlp@progtools.org>  wrote:
>> Hi,
>>
>> what is an "abstract interface" ?
>
> I'm wondering the same thing.

A bug in ddoc. ;)

David
September 04, 2011
On 2011-09-04 12:57:06 +0000, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> said:

> On 9/4/11 7:10 AM, Michel Fortin wrote:
>> And also, I doubt using D IO by default will break printf that much: I
>> mean if C IO is used to print lines, those lines will be flushed as
>> they're emitted, with no possible weird interleaving unless the line is
>> really too long.
> 
> No, things are more complex; the interference will be major unless explicitly addressed.

That doesn't really help understand the issue, you're just making it more obscure.

-- 
Michel Fortin
michel.fortin@michelf.com
http://michelf.com/

September 04, 2011
Michel Fortin Wrote:

> On 2011-09-04 12:57:06 +0000, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> said:
> 
> > On 9/4/11 7:10 AM, Michel Fortin wrote:
> >> And also, I doubt using D IO by default will break printf that much: I mean if C IO is used to print lines, those lines will be flushed as they're emitted, with no possible weird interleaving unless the line is really too long.
> > 
> > No, things are more complex; the interference will be major unless explicitly addressed.
> 
> That doesn't really help understand the issue, you're just making it more obscure.
> 
> -- 
> Michel Fortin
> michel.fortin@michelf.com
> http://michelf.com/
> 
You are assuming each write flushes the buffer. That's not always the case.

-Steve
September 04, 2011
On 2011-09-04 14:59, Andrei Alexandrescu wrote:
> On 9/4/11 7:11 AM, Jacob Carlborg wrote:
>> Tango has added a new method to Object, "dispose". The method is called
>> by the runtime when a scoped class exits a scope:
>>
>> void foo ()
>> {
>> scope f = new File;
>> }
>>
>> When "foo" exits File.dispose will be called and it can close any file
>> handles. I think it's quite clever.
>
> What happens if f is aliased beyond the existence of foo()?
>
> Andrei

I'm not sure if this is what you mean but:

File file;

void foo ()
{
    scope f = new File;
    file = f;
}

void main ()
{
    foo;
    // file is disposed here
}

In the above example "dispose" will be called when "foo" exits. After the call to "foo" in the main function "file" will refer to an object that is disposed, i.e. an object where the "dispose" method has been called.

I don't know how bad this is or if it is bad at all. I would be the same as the following code:

File file;

void foo ()
{
    auto f = new File;
    f.close;
    file = f;
}

void main ()
{
    foo;
}

-- 
/Jacob Carlborg