Stream mixins?

Janice Caron caron800 at googlemail.com
Sun Nov 11 01:06:04 PST 2007


On 11/10/07, Kris <foo at bar.com> wrote:
> This is a fair example of why Tango does things differently.

Thank you, but since I don't use Tango that's not much help. Allow me
to bump my request.

Walter, please could you separate out the member functions of
std.stream.Stream into three mixins: ReadMixin, WriteMixin and
SeekMixin, so I can write

class MyOutputStream : OutputStream
{
   uint writeBlock(const const void* buffer, uint size) { /*...*/ }
   mixin WriteMixin;
}

? Without that, the interface OutputStream is impractical to implement
- I'd have to implement printf() and writef(); I'd have to implement
wunget() and opApply(); ... and not make any mistakes! It's too
daunting, and a mixin would do the trick nicely.

Also - a question. There are functions in the InputStream and
OutputStream interfaces whose definitions are implementation
dependent. For example, InputStream.readStringW(). The documentation
says "The file format is implementation-specific and should not be
used except as opposite actions to write".

Now - forgive me for being confused here, but shouldn't an interface
define what each function must do? Isn't that the whole point of an
interface? I mean if I published:

interface ConfusingInterface
{
    int f(void[] a);
}

but then documented that the content of the input array a is
implementation-specific, then I have an interface that doesn't mean
anything!

Moreover, the phrase "except as opposite actions to write" make no
sense, because InputStream has no write functions. The only way I can
make sense of this instruction is if I assume that every InputStream
must have a /corresponding/ OutputStream. But if that's true - why not
just do away with the separate interfaces and just have Stream?

So, it seems to me that

(1) All abstract functions whose purpose is not completely defined
should be removed from InputStream and OutputStream, and

(2) We need those mixins available.

Disclaimer. My goal here is make std.stream better. /Please/ nobody
turn this into another Tango-versus-Phobos thread. I'm so bored with
those.



More information about the Digitalmars-d mailing list