home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!jvnc.net!nuscc!gold!tim
- From: tim@gold.iss.nus.sg (Tim Poston)
- Subject: Just what is so great about streams?
- Message-ID: <1992Nov12.061942.16473@nuscc.nus.sg>
- Originator: tim@gold
- Sender: usenet@nuscc.nus.sg
- Organization: Institute of Systems Science, NUS, Singapore
- Date: Thu, 12 Nov 1992 06:19:42 GMT
- Lines: 98
-
- This posting is a genuinely answer-seeking question,
-
- what _is_ so great about streams?
-
-
- The C++ books that I've learned from
- all have strong explanations of why C++ is a better C,
- and I am perfectly convinced about that.
- C++ makes it easier to program the way that I think.
-
- But I have never seen any discussion of the merits of streams,
- versus functions like printf(),
- or even a pointer to such discussion.
- The books and manuals just described how to use them.
- Flushed with the elegance of C++ in general,
- I duly wrote my programs to use them.
-
- The more I did that,
- the less I've believed I should.
-
- Let me present a negative case:
- I stand ready to be corrected by those who know better.
-
- From a coding standpoint,
- the << operator seems to be a case of `user-friendly disease'.
- Easier to write simple output
- without worrying about data types,
- and lesson 1 (the "hello, cruel world" program)
- is definitely easier.
- But when I want more output than that...?
-
- I have to do
- x << " " << y
- just to get a space between output numbers.
-
- Typical user-friendliness:
- "don't worry about type,
- I'll look at it and do what's best",
- with no judgement needed by the programmer.
- But sometimes Mom does not know best.
- For instance, if the output is PostScript code,
- a number very near zero should _not_ be output as 1.472e-6
- It should be 0.0, or PostScript will barf.
-
- So I have to use a function call to say
- "Please Mom, I want the next one decimal,"
- pass a number,
- say "Please Mom, I want the next one decimal,"
- pass another number,
- say "Please Mom, I want the next one decimal,"
- pass another number,
- say "Please Mom, I want the next one decimal,"
- pass another number,
- say "Please Mom, I want the next one decimal,"
- pass another number,...
-
- and what could have been one line using printf()
- becomes a far less readable slather of code.
-
- That is typical user-friendliness.
- Easy to start,
- but painful and laborious to do things
- that need discrimination and power.
-
- Last but not least,
- the stream stuff seems to be an absolute swarming
- ground for compiler bugs.
- I haven't (heaven forfend)
- tried all compilers extant,
- but the ones I have...
- ugh.
-
-
- All in all,
- my inclination is to go back to stdio.h
- and forget I ever heard about streams.
- I'm puzzled, though.
- If they don't have merits to balance
- the discomfort I've found,
- why are people using them at all?
- Either I've been doing very dumb things
- that brought the discomfort on myself,
- or there are pluses (pluspluses?)
- nobody has told me about.
-
- I would welcome either
- flames that make clear to me how I've been dumb,
- or
- an explanation of those merits.
-
- Tim Poston
-
-
- ____________________________________________________________
- "Division is esteemed one of the busiest operations of
- Arithmetick, and such as requireth a mynde not wandering,
- or setled uppon other matters."
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-