On 9/3/11 11:33 PM, Steven Schveighoffer wrote:
We have to break something in std.stdio, because it's fixated on FILE *.
We need something that allows FILE * to play the game, but is focused on
a D-based solution. Otherwise, we have no room for improvement.

I'm not 100% convinced of that. We can achieve a good deal of improvement by resorting to platform-specific code. Clearly that's not the best way to go but it's not difficult and it does have its merit.

Overall I think the design of std.stdio should be followed:

1. User opens a File (or whatever), which is a struct. The struct uses RAII.

2. Using the struct you can directly call primitives to read and write stuff.

3. You can also decide you want a polymorphic stream out of it, and you get to decide the parameters of the stream (buffering, chunking, synchronicity and whatnot). byChunk and byLine are good examples, although they aren't polymorphic. Once you have such a stream you're in polyland so you get to use all of its goodies (look ma no templates etc).

4. Once all copies of the struct is destroyed, all streams derived from it are automatically closed and will issue errors when used.

That's pretty much it! It's a simple design that does all we need.


Andrei



Reply via email to