home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 32,847 of 33,346   
   Bart van Ingen Schenau to Zeljko Vrba   
   Re: iostream replacement   
   02 Feb 13 05:22:19   
   
   From: bart@ingen.ddns.info.invalid   
      
   On Fri, 01 Feb 2013 10:01:02 -0600, Zeljko Vrba wrote:   
      
   > I'm bashing iostreams in particular because they overload arithmetic   
   > operators to have implicit side-effects.  IMO, side-effects and   
   > unspecified order of evaluation don't mix well.  I wonder whether K&R   
   > would have been so lax with evaluation order had they forseen the   
   > possibility of overloading which introduces side-effects.   
      
   I don't see what Kernighan and Ritchie have to do with it.   
   If an ancestor language leaves something unspecified (such as order of   
   evaluation in C), there is nothing stopping the designer of a derived   
   language from pinning it down, even if the derived language must be   
   mostly backwards compatible with the ancestor language (as with C++ and   
   C).   
      
   >   
   > What iostreams *should* have done was something akin to   
   >   
   >   cout.print(a).print(modify(b)).print(b).endl();   
   >   
   > More verbose than chained << but still shorter than   
      
   It is more verbose and does not give you any additional guarantees.   
   In particular, there are absolutely no guarantees about the sequencing   
   between `modify(b)` and `b` in the later print call.   
   Those chained method calls are exactly equivalent to   
     cout << a << modify(b) << b << endl;   
      
   which (for int a,b;) is identical to   
     cout.operator<<(a).operator(modify(b)).operator<<(b).operator<<(endl);   
      
   >   
   >   cout << a;   
   >   cout << modify(b);   
   >   cout << b;   
   >   cout << endl;   
   >   
   > and with the same sequencing guarantee.   
      
   No, that is not true. Chaining function calls does not give any   
   sequencing guarantee on the evaluation of the function parameters, not   
   even between the parameters for different functions.   
      
      
   >   
   > So, in short: IN GENERAL, due to unspecified order of evaluation, I   
   > think it's a bad idea to overload operators such that implicit   
   > side-effects are introduced.  IN PARTICULAR, iostreams go blatantly   
   > against that principle, and that's why I'm (in your opinion, unfairly)   
   > bashing iostreams.   
      
   If it is the unspecified sequencing you are concerned with, you should be   
   opposed to any chaining, regardless of whether it is (overloaded)   
   operators or functions. In that respect, C++ does not differentiate   
   between the two.   
      
   Bart v Ingen Schenau   
      
      
   --   
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca