Path: utzoo!mnetor!uunet!husc6!cmcl2!brl-adm!umd5!purdue!i.cc.purdue.edu!j.cc.purdue.edu!pur-ee!uiucdcs!uiucdcsp!johnson From: johnson@uiucdcsp.cs.uiuc.edu Newsgroups: comp.lang.smalltalk Subject: Re: Object Orientation and The Truth Message-ID: <80500028@uiucdcsp> Date: 17 Feb 88 03:43:00 GMT References: <2792@pitt.UUCP> Lines: 67 Nf-ID: #R:pitt.UUCP:2792:uiucdcsp:80500028:000:3659 Nf-From: uiucdcsp.cs.uiuc.edu!johnson Feb 16 21:43:00 1988 /* Written 10:02 am Feb 16, 1988 by jss@hector.UUCP in uiucdcsp:comp.lang.smalltalk */ >I will rephrase my observation: Inheritance is the major feature >that distinguishes "object-oriented" Smalltalk and C++ from other >languages such as CLU, ML, Ada, Modula-2, ... that support notions of >user defined types. A few days ago I was asked which feature of o-o programming was most important, message sending or inheritance. I instantly replied "message sending". I have thought about this question a lot, so I knew the answer. By message sending, I mean run-time binding of procedure calls based on the class of the arguments, or, more usually, the first argument. Inheritance can be simulated (with a bit of work) by delegation. O-o programming is data hiding carried to an extreme, not only does the programmer not know an object's implementation, but the compiler doesn't, either. ML, Ada, and Modula-2 do not have this kind of polymorphism. In these languages, each procedure call can be bound to the target procedure at compile time. (I leave off CLU because I don't know enough about it.) Late bound procedure calls ensure that the only thing a programmer has to know about an object is its behaviour, its class is irrelevant. >I consider data encapsulation a very important aspect of programming, >and both languages support it to some extent. But the static types >of C++ are so different from the dynamic types of Smalltalk that I >don't believe it is fair to say that they share data encapsulation >features. This seems a very odd comment. I program in both languages. Virtual functions in C++ let you do 99% of what you want to do in Smalltalk. Now that C++ has multiple inheritance, you can simulate the complete lack of type checking in Smalltalk with abstract classes. There is little practical difference between the way one uses classes in the two languages. (Note the word "practical", almost nobody makes use of the fact that classes are objects in Smalltalk.) >As for "multiple objects of the same abstract type" I can't imagine >a language that has a notion of user defined type that doesn't >support multiple things (objects or values) of a type. "Abstract type" means something different from "type". It means that the user of an object is only concerned with the operations possible on the object, not on its class. Try having an array of numbers in Ada, where one number is an integer, another a float, another a user defined type like a polynomial, etc. This is easy in Smalltalk, and doable in C++ if you create classes for integers and floats. >In C++ the "assignment operator" does value copy, while the assignment of >Smalltalk is pointer copy. While, each of these can be used to >simulate the other, they are so different that it is hard for me to >say that C++ and Smalltalk even share a notion of abstract type. I suppose it is because I am an unconverted Smalltalk programmer, but I always use pointers to objects, never variables that contain objects. Thus, my way of programming in C++ is isomorphic to programming in Smalltalk. Smalltalk is better than C++ because it has garbage collection, closures as first class objects, classes as objects (the tricks one can do!), an outstanding programming environment, and a huge library of mostly well designed classes. None of these have anything to do with its position as an object-oriented language. To forstall arguments, C++ is better than Smalltalk because it is faster, you can make standalone executables with it, and it is more portable, since it doesn't need graphics. I am writing an operating system in C++. Otherwise I use Smalltalk.