[comp.lang.c++] A C++ revelation/question...

dld@f.gp.cs.cmu.edu (David Detlefs) (08/23/88)

I recently had a misconception that I had held about C++ corrected.  I
am writing here to 1) save other people the embarassment of insisting
that C++ is X, when it is actually Y, as I did, and 2) get some
clarification on the example in The (Stroustrup) Book that caused me
to think Y was the case.

C++ is of course an object-oriented language.  However, some OOL
literature makes a subtle distinction between languages that are
(truly) "object-based" and those that are "type-based."  The
distinction is that in an object-based language, a member function
(method) of a class only has access to the private members of the
object it is invoked on.  If we neglect some hacks used for debugging,
Smalltalk is an example of a language that is object-oriented in this
way.  "Type-based" languages allow a member function of a class access
to the private part of any object of that class (type) that it has
access to.  CLU and OWL are examples of languages that are type-based
in this sense.

Well, my reading of The Book gave me the impression that C++ fell on the
object-based side of this distinction.  Well, lo and behold, I'm wrong
-- it's type based.  My error is obvious in hindsight -- the "tiny"
example on page 175 can be explained in no other way.  However, I'm
still a little confused.  On page 174, in the "complex" example,
and again on page 178 in the "matrix" example, "operator+" is declared
as a friend instead of as a member function.  This is what originally
led me to believe that C++ was object-based (having missed the
importance of the "tiny" example) -- I thought that these operator+'s
were friends so that they could have access to the private parts of
the second argument and the return matrix or complex.  Well, this
works just as well as a non-friend member function (I just compiled
it.)  My question is, then, why were these friends?  Does it have
something to do with operator overloading name resolution?

By the way, don't get me wrong -- I think the type-base approach is
far superior.
-- 
Dave Detlefs			Any correlation between my employer's opinion
Carnegie-Mellon CS		and my own is statistical rather than causal,
dld@cs.cmu.edu			except in those cases where I have helped to
				form my employer's opinion.  (Null disclaimer.)

anders@suadb.UUCP (Anders Bj|rnerstedt) (08/25/88)

In article <2767@pt.cs.cmu.edu> dld@f.gp.cs.cmu.edu (David Detlefs) writes:
>
>
>C++ is of course an object-oriented language.  However, some OOL
>literature makes a subtle distinction between languages that are
>(truly) "object-based" and those that are "type-based."  The
>distinction is that in an object-based language, a member function
>(method) of a class only has access to the private members of the
>object it is invoked on.  If we neglect some hacks used for debugging,
>Smalltalk is an example of a language that is object-oriented in this
>way.  "Type-based" languages allow a member function of a class access
>to the private part of any object of that class (type) that it has
>access to.  CLU and OWL are examples of languages that are type-based
>in this sense.

I dont agree with your terminology ! 
Sure, Smalltalk is untyped and enforces encapsulation. This does not 
say anything about whether or how a strongly typed language should 
enforce encapsulation. Thus the distinction "object based" vs 
"type based" is misleading.

Wegner has done a lot of work on the classification of programming
languages. Look up one of the folowing:

***************************************************************
#2920      Date: Dec. 1985       Type: Journal article    

   * On Understanding Types, Data Abstraction and 
   * Polymorphism

Journal:   ACM Computing Surveys
Volume:    17
Number:    4
Pages:     471-522


AUTHORS
L. Cardelli
P. Wegner  
***************************************************************
#3035      Date: Oct. 1987       Type: Proceeding article 

   * Dimensions of Object-Based Design

Journal:   Object-Oriented Programming Systems, Languages and Applications
City:      Orlando, Florida
Pages:     168-182


AUTHORS                   
P. Wegner                                                   
***************************************************************
#3339      Date: 1987            Type: Article within book 

   * The Object-Oriented Classification Paradigm

Issuer:    The MIT Press
City:      Cambridge, Massachusetts
Booktitle: Research Directions in Object-Oriented Programming
Pages:     479-560


AUTHORS                                                     EDITORS
P. Wegner                                                   B. Shriver
                                                            P. Wegner

------------------------------------

  Anders Bjornerstedt
  Department of Computer & Systems Sciences
  University of Stockholm
  S-106 91  Stockholm
  Sweden


INTERNET: anders@sisu.se    OR    anders%sisu.se@uunet.uu.net
UUCP:{uunet,mcvax,cernvax}!enea!sics!sisus!anders

eeartym@cybaswan.UUCP (Dr R.Artym eleceng ) (09/02/88)

>>C++ is of course an object-oriented language.  However, some OOL
>>literature makes a subtle distinction between languages that are
>>(truly) "object-based" and those that are "type-based."  The
>> .........

>I dont agree with your terminology ! 
>Sure, Smalltalk is untyped and enforces encapsulation. This does not 
>say anything about whether or how a strongly typed language should 
>enforce encapsulation. Thus the distinction "object based" vs 
>"type based" is misleading.
>

Perhaps Anders Bjornerstedt would be a little happier if the two forms of
OO were called "object-based" and "class-based".  I can see how the term
"type-based" would worry a lot of people, largely owing to the fact that
types tend to be associated with the way variables are used, whereas here
we're talking about visibility within encapsulations (values), and the two
are clearly not the same thing.  Whatever the terminology, no confusion will
result if we keep the word "encapsulation" in there somewhere;  eg. "Smalltalk
is untyped and object-oriented, with object-based encapsulation" is a lot
clearer than "Smalltalk is untyped and type-based" !!!
C++ is, of course, typed and optionally object-oriented, with class-based
encapsulation.
		Rich
-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Keywords:  Parallel, Applicative, and Object-Oriented Languages and Systems
---------------------------------------------------------------------------
Dr. Richard Artym,              +   UUCP   :  ..!ukc!pyr.swan.ac.uk!eeartym
Electrical Engineering Dept.,   +   JANET  :  eeartym@uk.ac.swan.pyr
University of Wales,            +   Phone  :  [(0792) or (+44 792)]  295536
Swansea, SA2 8PP,               +   Fax    :  [(0792) or (+44 792)]  295532
U.K.                            +   Telex  :  48358
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~