🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #4187

Re: Modula2's godawful IO.

#4187
From: Dave Jones
Date: Tue, 19 Apr 1988 01:01
33 lines
1692 bytes
in article <553@m10ux.UUCP>, rgr@m10ux.UUCP (Duke Robillard) says:

...

  [ cout << foo << bar; // etc. ]

> 
>     However, I don't really see that this is any different than 
> overloading a print procedure.  all you're doing is overloading "<<"
> (i.e. making it handle strings, integers, reals, whatever), right?
> 

That's right.  It's just easier to type and to read than having a
jillion "print"'s.

For better or worse (*better* in my opinion), C++ classes don't tend
to "know how to print themselves".  Instead you overload the << operator
to print new classes.   Also remember that in C++, "int" is not a class!!  
So the function can't be a member of class int. Translated into 
Smalltalk, the class "int" does not recognize the message "<<".

"Print an int" _could_ be an external function, defined this way:

   ostream& operator<< (ostream& o, int a) {return o << (long)a;}

There is an argument to be made that it SHOULD be declared this way,
to reduce the number of member functions of ostream. That is to say,
to reduce the number of types which ostream "knows about".

But the way things are actually implemented, the function is a member of 
ostream, and has this declaration:

    ostream& operator<<(int a) { return *this<<long(a); }
Technical Details
Message-ID: <462@goofy.megatest.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!lll-winken!lll-tis!ames!pasteur!ucbvax!decwrl!megatest!djones
References: <553@m10ux.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!lll-winken!lll-tis!ames!pasteur!ucbvax!decwrl!megatest!djones
From: djones@megatest.UUCP (Dave Jones)
Newsgroups: comp.lang.modula2,comp.lang.misc,comp.lang.c,comp.lang.pascal
Subject: Re: Modula2's godawful IO.
Message-ID: <462@goofy.megatest.UUCP>
Date: 19 Apr 88 01:01:10 GMT
References: <553@m10ux.UUCP>
Organization: Megatest Corporation, San Jose, Ca
Lines: 32