Boost logo

Boost :

From: mfdylan (dylan_at_[hidden])
Date: 2001-12-19 18:42:25


--- In boost_at_y..., Ross Smith <r-smith_at_i...> wrote:
>
> Iostream formatting operations are designed for human readable
output.
> Writing an integer, for example, gives you the ordinary decimal
> representation by default, with ASCII (or whatever your local
charset
> is) characters and variable width. Getting a fixed-width or non-
decimal
> representation requires awkward work with manipulators; getting a
binary
> representation (native binary data, I mean, not binary digits in
ASCII)
> is impossible.
>
> You can write I/O operators that use a binary representation, of
course.
> But (1) you can only do that for your own types, not native types;
(2)
> you can only do that _instead of_, not as well as, human readable
> output; and (3) you still get all the runtime overhead of iostreams
even
> though none of it is needed.
>
> I'm convinced that iostreams should be reserved strictly for human
> readable text I/O, and not used for computer-to-computer
communication,
> such as sockets.
>
Well, er, most (if not all) common internet protocols are in fact
human readable. For a start they are easy to debug, and work
regardless of byte-ordering or floating point storage mechanisms.
In fact unless efficiency (in space or time) is a problem, ascii
based formatting is quite often the best way to go with any format
that must be platform independent (arguably it is the only format
that is totally platform independent). The main problem I have is
the lack of symmetry when dealing with delimiters, that is, you can't
write:

read (int a, int b, int c)
{
 stream >> a >> b >> c;
}
write (int a, int b, int c)
{
 stream << a << b << c;
}

instead you have to do something like:

write (int a, int b, int c)
{
 stream << a << ' ' << b << ' ' << c << ' ';
}

As it is I supplied a binary_stream class that uses a streambuf to do
binary I/O (based on the XDR format), so if you wanted to do binary
I/O there's no problem either.

And no-one's suggesting that iostreams should be _bound_ to sockets,
just that you SHOULD be able to use iostreams with them, which the
currently std library doesn't allow without deriving your own
streambuf class (which is what I did).

Dylan


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk