www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - File IO: C# streams VS iterators?

reply "DDD" <dcb854d0bfb1 f98b7c56a69c.anonbox.net> writes:
I was watching a dconf talk about porting C# code to D. One thing 
that came up was there isn't anything like C# streams for D. 
Walter said he thinks iterators (unless I remember wrong) is 
superior. The speaker agreed but said it isn't a drop in 
replacement so that is an issue if you want to port.

I haven't access file in D and i'm completely confused. What are 
iterators in regards to file IO?
Nov 07 2013
next sibling parent reply Lionello Lunesu <lionello lunesu.remove.com> writes:
On 11/8/13, 8:57, DDD wrote:
 I was watching a dconf talk about porting C# code to D. One thing that
 came up was there isn't anything like C# streams for D. Walter said he
 thinks iterators (unless I remember wrong) is superior. The speaker
 agreed but said it isn't a drop in replacement so that is an issue if
 you want to port.

 I haven't access file in D and i'm completely confused. What are
 iterators in regards to file IO?
There are several ranges that can be used for file IO, for example http://dlang.org/phobos/std_stdio.html#.File.byChunk and http://dlang.org/phobos/std_stdio.html#.File.byLine . C# Stream has no such capability, which is why you have TextReader and TextWriter on top of streams, etc.. However, sometimes it's useful to have polymorphism for accessing streams, especially when porting C#/java code to D. In that case it would be pretty trivial to port the base classes to D and implement them using the D ranges. L.
Nov 07 2013
parent Jacob Carlborg <doob me.com> writes:
On 2013-11-08 04:22, Lionello Lunesu wrote:

 However, sometimes it's useful to have polymorphism for accessing
 streams, especially when porting C#/java code to D. In that case it
 would be pretty trivial to port the base classes to D and implement them
 using the D ranges.
For that, there's Tango: https://github.com/SiegeLord/Tango-D2 http://www.dsource.org/projects/tango/docs/current/ -- /Jacob Carlborg
Nov 07 2013
prev sibling parent Jacob Carlborg <doob me.com> writes:
On 2013-11-08 01:57, DDD wrote:
 I was watching a dconf talk about porting C# code to D. One thing that
 came up was there isn't anything like C# streams for D. Walter said he
 thinks iterators (unless I remember wrong) is superior. The speaker
 agreed but said it isn't a drop in replacement so that is an issue if
 you want to port.

 I haven't access file in D and i'm completely confused. What are
 iterators in regards to file IO?
he must have said ranges. A range is like a pair of iterators. It's heavily used in D. -- /Jacob Carlborg
Nov 07 2013