March 29, 2007
Bill Baxter wrote:
> kris wrote:
>> Andrei Alexandrescu (See Website For Email) wrote:
> 
>> - Tango is for D programmers; not C programmers.
> 
> D programmers sometimes like to call 3rd party code written in other languages, and pretty much any interop in D has to happen via C compatibility.  E.g. pyD.  So I'm guessing if my D code calls on some Python code that prints to the console that somewhere down the line that eventually ends up on C's stdout.  I could be wrong, but at least that's why I *think* Andrei and Walter keep saying that C compatibility is important.

Yes.

> Andrei -- by "compatibility" does that mean if I rebind stdio/stdout to something different that both D and C's output go to the new place?  Or is it still necessary to rebind them individually?  I did this once for some legacy code in C++, and found that I had to rebind 3 things: the C streams, the C++ old-style streams from <iostream.h> (was under MSVC 6), and the new-style C++ streams from <iostream>.    And then I had to do the interleaving myself, which didn't really work (because all the streams were just writing to output buffers individually).  If what you're talking about with compatibility would avoid that kind mess, that is certainly be a good thing.

Exactly. I'm hoping to save the D community from the iostreams mess, which requires the programmer to deal with two (or three as in your example) incompatible APIs. It's iostreams' amazing counterperformance that they managed to cut the speed so effectively in the process :o).

I think a wise thing that Tango could do is to offer a backward-compatible stdio, and a high-performance I/O class using the latest and greatest from each I/O (zero-copy (see http://research.sun.com/techrep/1995/abstract-39.html), asynchronous, threaded, kernelized, teleported, you name it).

The main desideratum is that fast/incompatible I/O is opt-in, not lock-in.


Andrei
March 29, 2007
Bill Baxter wrote:
> kris wrote:
> 
>> Andrei Alexandrescu (See Website For Email) wrote:
> 
> 
>> - Tango is for D programmers; not C programmers.
> 
> 
> D programmers sometimes like to call 3rd party code written in other languages, and pretty much any interop in D has to happen via C compatibility.  E.g. pyD.  So I'm guessing if my D code calls on some Python code that prints to the console that somewhere down the line that eventually ends up on C's stdout.  I could be wrong, but at least that's why I *think* Andrei and Walter keep saying that C compatibility is important.
> 
> Andrei -- by "compatibility" does that mean if I rebind stdio/stdout to something different that both D and C's output go to the new place?  Or is it still necessary to rebind them individually?  I did this once for some legacy code in C++, and found that I had to rebind 3 things: the C streams, the C++ old-style streams from <iostream.h> (was under MSVC 6), and the new-style C++ streams from <iostream>.    And then I had to do the interleaving myself, which didn't really work (because all the streams were just writing to output buffers individually).  If what you're talking about with compatibility would avoid that kind mess, that is certainly be a good thing.
> 
> --bb

That post noted the feasibility of hooking C into tango.io, which is a potentially realistic option
March 29, 2007
Andrei Alexandrescu (See Website For Email) wrote:
> I don't have an account on the Tango site, and in a fraction of the time it would take me to create one, you can submit the bug report.

We ask ppl to create tickets so that we can track and schedule the issue, have a potential ongoing dialogue with those involved, and so that we have something to detail the changes for each release. If you'd prefer to be kept out of the loop on this, that's a perfectly valid option
March 29, 2007
On Thu, 29 Mar 2007 15:19:40 +0900, Bill Baxter wrote:

> kris wrote:
>> Andrei Alexandrescu (See Website For Email) wrote:
> 
>> - Tango is for D programmers; not C programmers.
> 
> D programmers sometimes like to call 3rd party code written in other languages, and pretty much any interop in D has to happen via C compatibility.  E.g. pyD.  So I'm guessing if my D code calls on some Python code that prints to the console that somewhere down the line that eventually ends up on C's stdout.  I could be wrong, but at least that's why I *think* Andrei and Walter keep saying that C compatibility is important.


It's only important for those that are determined to use it, perhaps because of persistant programming style or unrelenting attachment to C++ methods (where C and C++ seemed to keep an unholy matrimony). I'd hate to see a D library infected with a C compatibility requirement -- support for ugly C design decisions would most certainly taint Tango for the worse. I believe Tango was made to help D step beyond that.

Tango based projects would turn into a big mess if some tasks were mixed haphazardly with C code for compatibilities sake. The decision, I believe, to make Tango distinct is a very good one.  This is what makes Tango original, performant, unencumbered, and readable.

At the same time, Tango certainly doesn't prevent anyone from using C
API's, if they so choose. But I think it would be wiser and cleaner to
separate such code into "well-marked" units and leave Tango to do
what it does best.  I've always had a distinct dislike for C++ source that
mixed "old" C API's with new "C++" ones.  I'd love to see the day when D
is completely unleashed, that is, literally unfettered from it's C
dependency (snn.lib and libc.a no more -- ok that's excentric, but I can
wish. :D )

Tango certainly has its own ideology that attracts certain types of programmers. For myself, I hope Tango continues to steer far clear of anything resembling C++/C mixing and matching.  C is certainly accessible through D, but use it wisely and certainly don't force a library design to be crippled by C compatibility.

Just an opinion.

-JJR
March 29, 2007
Andrei Alexandrescu (See Website For Email) wrote:
> kris wrote:
>> Andrei Alexandrescu (See Website For Email) wrote:
>>> kris wrote:
>>>
>>>> Andrei Alexandrescu (See Website For Email) wrote:
>>>>
>>>>> kris wrote:
>>>>>
>>>>>> Last week there were a series of posts regarding some optimized code within phobos streams. A question posed was, without those same optimizations, would tango.io be slower than the improved phobos [1]
>>>>>>
>>>>>> As these new phobos IO functions are now available, Andrei's "benchmark" [2] was run on both Win32 and linux to see where tango.io could use some improvement.
>>>>>
>>>>>
>>>>> [snip]
>>>>>
>>>>> On my machine, Tango does 4.3 seconds and the following phobos program (with Walter's readln) does 5.4 seconds:
>>>>
>>>>
>>>> On Win32, the difference is very much larger. As noted before, several times faster. Those benefits will likely translate to linux going forward.
>>>
>>>
>>> If I understand things correctly, it looks like the hope is to derive more speed from further dropping phobos and C I/O compatibility, a path that I personally don't consider attractive.
>>
>> Nope. That's not the case at all. The expectation (or 'hope', if you like) is that we can make the linux version operate more like the Win32 version
>>
>>>
>>> Also, the fact that the tango version is "more than twice as efficient as the fastest C version identified" suggests a problem with the testing method or with the C code. Are they comparable? If you genuinely have a method to push bits through two times faster than the fastest C can do, you may want as well go ahead and patent it. Your method would speed up many programs, since many use C's I/O and are I/O bound. It's huge news. 
>>
>> That's good for D then?
>>
>> There's no reason why C could not take the same approach yet, one might imagine, the IO strategies exposed and the wide variety of special cases may 'discourage' the implementation of a more efficient approach? That's just pure speculation on my part, and I'm quite positive the C version could be sped up notably if one reimplemented a bunch of things.
>>
>>> I'm not even kidding. But I doubt that that's the case.
>>
>> You're most welcome to your doubts, Andrei. However, just because "C does it that way" doesn't mean it is, or ever was, the "best" approach
> 
> I think we're not on the same page here. What I'm saying is that, unless you cut a deal with Microsoft to provide you with a secret D I/O API that nobody knows about, all fast APIs in existence come with a C interface. It's very hard to contend that. Probably you are referring to the C stdio, and I'm in agreement with that. Of course there's a variety of means to be faster than stdio on any given platform, at various compatibility costs. It's known how to do that. "Hot water has been invented."
> 
>>>>> Also, the Tango version has a bug. Running Tango's cat without any pipes does not read lines from the console and outputs them one by one, as it should; instead, it reads many lines and buffers them internally, echoing them only after the user has pressed end-of-file (^D on Linux), or possibly after the user has entered a large amount of data (I didn't have the patience). The system cat program and the phobos implementation correctly process each line as it was entered.
>>>>
>>>>
>>>> If you mean something that you've written, that could presumeably be rectified by adding the isatty() test Walter had mentioned before. That has not been added to tango.io since (a) it would likely make programs behave differently depending on whether they were redirected or not. It's not yet clear whether that is an appropriate specialization, as default behaviour
>>>
>>>
>>> What is absolutely clear is that the current version has a bug. It can't read a line from the user and write it back. There cannot be any question that that's a problem.
>>
>> Only with the way that you've written your program. In the general case, that is not true at all. But please do submit that bug-report :)
> 
> This is the fourth time we need to discuss this. Why do I need to _argue_ that this is a bug, I don't understand.
> 
> Let me spell it again: Cin.nextLine is incorrect. It cannot be used (without possibly some extra incantations I don't know about) to implement a program that does this:
> 
> $ ./test.d
> Please enter your name: Moe
> Hello, Moe!
> $ _

I must be missing something.  Why is the following not acceptable?

    import tango.io.Console;

    void main()
    {
        char[] name;
        Cout( "Please enter your name: " ).flush;
        Cin.nextLine( name );
        Cout( "Hello, " )( name )( "!" );
    }

> I don't have an account on the Tango site, and in a fraction of the time it would take me to create one, you can submit the bug report.

True.  But it's more effective for the person who understands the problem to submit the bug report.

> What Win32 primitives does tango use?

ReadFile and WriteFile.


Sean
March 29, 2007
Andrei Alexandrescu (See Website For Email) wrote:
[snip]
> Exactly. I'm hoping to save the D community from the iostreams mess, which requires the programmer to deal with two (or three as in your example) incompatible APIs. 

Save the D community? The sky is not falling; no need for you to save anyone from anything


> It's iostreams' amazing counterperformance that they managed to cut the speed so effectively in the process :o).
> 
> I think a wise thing that Tango could do is to offer a backward-compatible stdio, and a high-performance I/O class using the latest and greatest from each I/O (zero-copy (see http://research.sun.com/techrep/1995/abstract-39.html), asynchronous, threaded, kernelized, teleported, you name it).
> 
> The main desideratum is that fast/incompatible I/O is opt-in, not lock-in.

If you wish to be helpful, then let's try to forego the overt drama?

Here's an simple exercise you might indulge; let's do it in steps:

1) name every single C library that D programmers regularly use from D
March 29, 2007
John Reimer wrote:
> On Thu, 29 Mar 2007 15:19:40 +0900, Bill Baxter wrote:
> 
>> kris wrote:
>>> Andrei Alexandrescu (See Website For Email) wrote:
>>> - Tango is for D programmers; not C programmers.
>> D programmers sometimes like to call 3rd party code written in other languages, and pretty much any interop in D has to happen via C compatibility.  E.g. pyD.  So I'm guessing if my D code calls on some Python code that prints to the console that somewhere down the line that eventually ends up on C's stdout.  I could be wrong, but at least that's why I *think* Andrei and Walter keep saying that C compatibility is important.
> 
> 
> It's only important for those that are determined to use it, perhaps
> because of persistant programming style or unrelenting attachment to C++
> methods (where C and C++ seemed to keep an unholy matrimony). I'd hate to
> see a D library infected with a C compatibility requirement -- support for
> ugly C design decisions would most certainly taint Tango for the worse. I
> believe Tango was made to help D step beyond that.

I believe the current discussion is only about under-the-hood implementation issues.  So I don't think you have to worry about any D libraries exposing (good or bad) C/C++ design decisions to users.  Tango is going to expose the same D interface no matter how it's implemented under the hood.

--bb
March 29, 2007
Sean Kelly wrote:
[snip]
> I must be missing something.  Why is the following not acceptable?
> 
>     import tango.io.Console;
> 
>     void main()
>     {
>         char[] name;
>         Cout( "Please enter your name: " ).flush;
>         Cin.nextLine( name );
>         Cout( "Hello, " )( name )( "!" );
>     }


There used to be a tango/example like this variation:

    import tango.io.Console;

    void main()
    {
        Cout ("Please enter your name: ").flush;
        Cout ("Hello, ") (Cin.get);
    }
March 29, 2007
kris wrote:
> Sean Kelly wrote:
> [snip]
>> I must be missing something.  Why is the following not acceptable?
>>
>>     import tango.io.Console;
>>
>>     void main()
>>     {
>>         char[] name;
>>         Cout( "Please enter your name: " ).flush;
>>         Cin.nextLine( name );
>>         Cout( "Hello, " )( name )( "!" );
>>     }
> 
> 
> There used to be a tango/example like this variation:
> 
>     import tango.io.Console;
> 
>     void main()
>     {
>         Cout ("Please enter your name: ").flush;
>         Cout ("Hello, ") (Cin.get);
>     }

I think I'll take a look at Tango.
Is there a tutorial, or better an examples library?

Ciao
March 29, 2007
Roberto Mariottini wrote:

> kris wrote:
>> Sean Kelly wrote:
>> [snip]
>>> I must be missing something.  Why is the following not acceptable?
>>>
>>>     import tango.io.Console;
>>>
>>>     void main()
>>>     {
>>>         char[] name;
>>>         Cout( "Please enter your name: " ).flush;
>>>         Cin.nextLine( name );
>>>         Cout( "Hello, " )( name )( "!" );
>>>     }
>> 
>> 
>> There used to be a tango/example like this variation:
>> 
>>     import tango.io.Console;
>> 
>>     void main()
>>     {
>>         Cout ("Please enter your name: ").flush;
>>         Cout ("Hello, ") (Cin.get);
>>     }
> 
> I think I'll take a look at Tango.
> Is there a tutorial, or better an examples library?
> 
> Ciao

The website over at http://www.dsource.org/projects/tango has various documentation (and also a few tutorials). You will also find quite a few small examples in the downloads.

-- 
Lars Ivar Igesund
blog at http://larsivi.net
DSource, #d.tango & #D: larsivi
Dancing the Tango