home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / cplus / 16142 < prev    next >
Encoding:
Text File  |  1992-11-11  |  3.2 KB  |  110 lines

  1. Newsgroups: comp.lang.c++
  2. 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
  3. From: tim@gold.iss.nus.sg (Tim Poston)
  4. Subject: Just what is so great about streams?
  5. Message-ID: <1992Nov12.061942.16473@nuscc.nus.sg>
  6. Originator: tim@gold
  7. Sender: usenet@nuscc.nus.sg
  8. Organization: Institute of Systems Science, NUS, Singapore
  9. Date: Thu, 12 Nov 1992 06:19:42 GMT
  10. Lines: 98
  11.  
  12. This posting is a genuinely answer-seeking question,
  13.  
  14.   what _is_ so great about streams?
  15.   
  16.  
  17. The C++ books that I've learned from
  18. all have strong explanations of why C++ is a better C,
  19. and I am perfectly convinced about that.
  20. C++ makes it easier to program the way that I think.
  21.  
  22. But I have never seen any discussion of the merits of streams,
  23. versus functions like printf(),
  24. or even a pointer to such discussion.
  25. The books and manuals just described how to use them.
  26. Flushed with the elegance of C++ in general,
  27. I duly wrote my programs to use them.
  28.  
  29. The more I did that,
  30. the less I've believed I should.
  31.  
  32. Let me present a negative case:
  33. I stand ready to be corrected by those who know better.
  34.  
  35. From a coding standpoint,
  36. the << operator seems to be a case of `user-friendly disease'.
  37. Easier to write simple output
  38. without worrying about data types,
  39. and lesson 1 (the "hello, cruel world" program)
  40. is definitely easier.
  41. But when I want more output than that...?
  42.  
  43. I have to do
  44.  x << " " << y
  45. just to get a space between output numbers.
  46.  
  47. Typical user-friendliness:
  48. "don't worry about type,
  49. I'll look at it and do what's best",
  50. with no judgement needed by the programmer.
  51. But sometimes Mom does not know best.
  52. For instance, if the output is PostScript code,
  53. a number very near zero should _not_ be output as 1.472e-6
  54. It should be 0.0, or PostScript will barf.
  55.  
  56. So I have to use a function call to say
  57. "Please Mom, I want the next one decimal,"
  58. pass a number,
  59. say "Please Mom, I want the next one decimal,"
  60. pass another number,
  61. say "Please Mom, I want the next one decimal,"
  62. pass another number,
  63. say "Please Mom, I want the next one decimal,"
  64. pass another number,
  65. say "Please Mom, I want the next one decimal,"
  66. pass another number,...
  67.  
  68. and what could have been one line using printf() 
  69. becomes a far less readable slather of code.
  70.  
  71. That is typical user-friendliness.
  72. Easy to start,
  73. but painful and laborious to do things
  74. that need discrimination and power.
  75.  
  76. Last but not least,
  77. the stream stuff seems to be an absolute swarming
  78. ground for compiler bugs.
  79. I haven't (heaven forfend)
  80. tried all compilers extant,
  81. but the ones I have...
  82. ugh.
  83.  
  84.  
  85. All in all,
  86. my inclination is to go back to stdio.h
  87. and forget I ever heard about streams.
  88. I'm puzzled, though.
  89. If they don't have merits to balance
  90. the discomfort I've found,
  91. why are people using them at all?
  92. Either I've been doing very dumb things
  93. that brought the discomfort on myself,
  94. or there are pluses (pluspluses?)
  95. nobody has told me about.
  96.  
  97. I would welcome either
  98.   flames that make clear to me how I've been dumb,
  99. or
  100.   an explanation of those merits.
  101.  
  102. Tim Poston
  103.  
  104.  
  105. ____________________________________________________________
  106.  "Division is esteemed one of the busiest operations of
  107.   Arithmetick, and such as requireth a mynde not wandering,
  108.   or setled uppon other matters."
  109. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  110.