[OT] Programming language WATs
Jonathan M Davis
jmdavisProg at gmx.com
Mon Feb 6 22:02:15 PST 2012
On Monday, February 06, 2012 21:49:23 H. S. Teoh wrote:
> On another note, I find this divide between std.stream and std.stdio
> quite jarring. The C++ model is to use <iostream> by default, and
> optionally provide <cstdio> to those who prefer it. This, I find, makes
> sense, because streams are a much more powerful concept that subsumes
> the concept of a file, and having it as default makes sense. Having
> <cstdio> as an option is merely a concession for C programmers who
> migrated to C++ (and I'm one of them who still hold on to cstdio over
> iostream) -- so it's understandable that the two cannot be freely
> intermixed.
In my experience, most C++ programmers ignore streams for basic I/O, if not in
general. They're nice for some basic stuff and for object oriented stuff, but as
soon as you need formatting, they're a pain. So, for the most part, printf
gets used. I think that about the only place that I see streams used much is
binary streams which take advantage of an object knowing how to write and read
itself to and and from a stream. But even that's rare in my experience. I'm
sure that it depends on the programmers though.
> In D, however, I did not expect this stream/stdio divide to exist,
> though I suppose the name "std.stdio" is a kind of giveaway. In any
> case, std.stdio is used all over the place in D docs and tutorials,
> besides write/writeln() being a pet example motivating variadic
> templates, so it seems to hold the equivalent place to <iostream> in
> C++. As such, I found it strange that this divide between streams and
> stdio files still persists in D. I would have thought that D should have
> integrated the two seamlessly into a single subsystem (or otherwise
> redesigned it in a more logical fashion), rather than perpetuating the
> schizophrenic divide inherited from C/C++.
You end up with pretty much the same thing in C# and Java. println and its
friends are what's used most frequently (though it works better in D, C#, and
Java than it does in C++, thanks to toString), though streams do get used for
some stuff - usually not text though. It probably varies a bit from programmer
to programmer though.
Regardless, I wouldn't really consider a file to be specific to either the stdio
approach or streams. If anything, I find it bizarre that std.stream uses the
term File for a stream. That seems to me to be like making a container into a
range or an iterator, which really doesn't make sense. You have a range _over_
a container, not a container which is a range. One of the reasons that dealing
with dynamic arrays in D can be so confusing is that they're ranges and people
think that they're containers (though they really aren't, since they don't own
their memory). Mixing the concept of file and stream seems like a bad idea. But
it's probably just a case of a poorly named type.
In any case, std.stream is rather old and outdated and will be replaced at
some point with a range-based API. And its replacement may interact with
std.stdio better.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list