Creating stream from stdout

Jonathan M Davis jmdavisProg at gmx.com
Sat Apr 23 22:37:29 PDT 2011


> On 04/23/2011 04:32 PM, Jonathan M Davis wrote:
>  >> On 04/23/2011 04:23 AM, Mandeep wrote:
>  >>> I have created a stream from stdout by using the following method.
>  >>> 
>  >>> new CFile(stdout.getFP(), FileMode.Out)
>  >>> 
>  >>> It works but is this the correct way or is there a better way to
> 
> achieve
> 
>  >>> this without FP.
>  >>> 
>  >>> Thanks&  Regards
>  >>> Mandeep
>  >> 
>  >> Consider streams gone from D. They are deprecated in favor of a "range"
>  >> interface. std.range and std.algorithm have examples of ranges that are
>  >> 
>  >> first introduced in this article (with different names in Phobos):
>  >>     http://www.informit.com/articles/printerfriendly.aspx?p=1407357
>  > 
>  > That's not quite true. You've misunderstood.
> 
> Which of my three statements are you referring to? Your use of vague
> words like "that" doesn't help.
> 
>  > Ranges are heavily used in Phobos, and most modules use them and are
> 
> going to
> 
>  > use them. std.stream is the current module for streaming I/O in Phobos.
> 
> What is "streaming I/O"? stdin and stdout are streaming I/O too. Do you
> consider them non-Phobos?
> 
>  > However, it is old and does _not_ use them. It probably has other
> 
> issues with
> 
>  > it that make it so that it's considered deficient anyway, but I
> 
> haven't really
> 
>  > used it much, so I'm not all that familiar with it. Regardless, because
>  > std.stream is old and does not use streams, it's going to be replaced
> 
> with a
> 
>  > new module (possibly called std.stream) which _does_ use ranges.
> 
> However, that
> 
>  > new module has not been completed or even completely designed as far
> 
> as its
> 
>  > basic API goes.
>  > 
>  > So, std.stream as it stands is going away. None of the current I/O
> 
> streaming
> 
>  > in Phobos will be sticking around in the long run. However, it will be
>  > replaced with new I/O streaming functionality which is range-based at
> 
> some
> 
>  > point in the future. As the new stuff is nowhere near complete, the
> 
> old stuff
> 
>  > is still there, but eventually it won't be.
> 
> I read the above multiple times. Unfortunately I can't understand more
> than what I already knew.
> 
> Let me get back to my three statements:
> 
> 1) Streams are gone from D. Since with "streams", I can only possibly
> mean what is already in D, I mean those streams are gone from D. I
> shouldn't need to disclaim that some module in the future may be related
> to streams.
> 
> 2) Streams that are currently present in D are deprecated in favor of a
> new interface that will use ranges, or be ranges.
> 
> 3) The seminal paper that I linked above is it.

stdin and stdio are _not_ streams. They're instances of std.stdio, and they 
are _not_ going away. As far as I know, nothing in std.stdio is going away.

std.stream as it stands (which _does_ using streaming I/O) _is_ going away. It 
will be replaced by another module which uses range-based streaming I/O.

You were saying that streams will be going away in favor of ranges, which is 
not true. While it makes a lot of sense to treat streams as ranges, they are 
definitely different concepts, and neither will be replacing the other. The 
current stream API in std.stream will be going away in favor of a new, range-
based stream API. But streams themselves as a concept will not be going away.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list