Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!pasteur!ucbvax!tut.cis.ohio-state.edu!rutgers!att!ulysses!andante!alice!bs From: bs@alice.UUCP (Bjarne Stroustrup) Newsgroups: comp.lang.c++ Subject: Re: Smalltalk-80 like inheritance in C++ possible ? Summary: complexity Message-ID: <9108@alice.UUCP> Date: 27 Mar 89 15:15:50 GMT References: <110@honold.UUCP> <5481@rlvd.UUCP> <1411@sw1e.UUCP> <9174@claris.com> <1421@sw1e.UUCP> Organization: AT&T Bell Laboratories, Murray Hill NJ Lines: 65 Naturally, C++ is complex, but I don't think it is as complex as it is sometimes made out to be, nor do I think programming in other languages is as simple as it is sometimes made out to be for roughly similar problems and roughly similar constraints of the solution. An example: My paper on a proposed facility for a parameterized type facility was mentioned. It is about 20 pages long. It is not the easiest paper to read, though again I doubt you'll find a significantly simpler discussion of the issues in the litterature. The paper describes a proposed scheme, it describes alternative implementation strategies for the proposed scheme, it describes many features and variants of features - including many rejected ones. It is most certainly not a tutorial. It is a discussion about details of language design and implementation techniques. Of the 20 pages about 2 are devoted to the language feature itself and its use. A reference manual entry for parameterized types is about 2 pages. The feature itself is fairly trivial to learn and use. The complexity in the paper is in the discussion of alternatives and implementation details - not in the feature itself. Let me try to substatiate this statement by explaining the basics of the proposed parameterized type facility right here. The idea is simple: It should be possible to provide a user-defined type (i.e. class) with an argument left for the user of the type to specify. For example: vector vi(10); // vector of 10 integers vector vc(20); // vector of 20 complex numbers vector vs(40); // vector of 40 pointers to char The declaration of class vector looks like this: template // The class declared here takes // a type as an argument. // The argument type is called T class vector { T* v; int sz; public: vector(int s) { v = new T[sz=s]; } ~vector() { delete v; } T& operator[](int i) { return v[i]; } int size() { return sz; } }; Complex? Not really. The only difference from C++ as we have it today is the specification of the argument `T' in the template declaration and the use of the vector, vector, etc. to use it. Compare the complexity to what you will have to write to fudge this facility in a language that does not provide it or to use a similar facility in a language that does provide such a facility. I will not reinforce the appearance of complexity by discussing details, implementation issues, and alternatives here. My point is that if you understand the basics of C++ you now also understand enough about `templates' (the term chosen for parameterized types in C++) to use them. If you are interested details have a look at my paper: Parameterized Types for C++. You can find it either in the January issue of JOOP or in the proceedings of the Denver USENIX C++ conference. It might be worth pointing out that templates are not part of C++ as currently shipped nor is it part of release 2.0.