Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!apple!agate!ucbvax!bloom-beacon!eru!hagbard!sunic!dkuug!diku!juul From: juul@diku.dk (Anders Juul Munch) Newsgroups: comp.object Subject: Re: Readability of Ada Message-ID: <1991Apr25.170356.21237@odin.diku.dk> Date: 25 Apr 91 17:03:56 GMT References: <3878@ssc-bee.ssc-vax.UUCP> <20245@alice.att.com> <1991Apr23.193715.23815@odin.diku.dk> Sender: juul@skinfaxe.diku.dk Organization: Department of Computer Science, U of Copenhagen Lines: 93 jls@rutabaga.Rational.COM (Jim Showalter) writes: >]>Now, I want to take a heterogeneous list of shapes, including triangles, >]>circles, and squares, and I want to iterate over the list and print >]>out all of the radii. >]Who wrote the heterogeneous-list code? The guy who supplied the shape >]classes? Of course not, because then he would have realized the need >]for a shape method to identify exactly what kind of shape it is. >Uh huh. Precisely the point made in "Emperor Strikes Lethe"--you DON'T >have any control over the guy who writes the class hierarchy upon which >you depend. Indeed, in my example I specifically said that the class >hierarchy is delivered in binary for security/monetary reasons, so you're >at the mercy of it completely. And you just want to add a simple little >class with some additional functionality--seems reasonable to me--but >you CAN'T. Apparently, while arguing *against* the usefulness of inheritance, at the same time you are demanding that inheritance be used to it's full potential. "And you just want to add a simple little class." In that case, inheritance can't possibly be a hindrance. >]That's why any C++ library programmer with just a little bit of sense >]adds such an operation. If the guy who wrote your binary collection >]of shape classes didn't do that, that's not a C++ problem >No? Then why do OTHER inheritance-oriented languages provide self- >identification of types automatically? I agree that self-identification should be a language feature, and as far as I know, it will be. But I still don't think it's a a C++ problem, because it's so easy to add an equivalent feature to any given class hierarchy. Provided you have the source code. Bjarne Stroustrup didn't include the feature originally, because he didn't want to encourage code like switch(aShape.Class()) { case CIRCLE: DrawCircle(aShape); break; case TRIANGLE: DrawTriangle(aShape); break; ... >]No language, >]not even Ada can protect you against stupid programmers. >Uh huh. All the more reason not to oversell the benefits of inheritance, >considering you said earlier that building class hierarchies was very >difficult. If it is really that difficult--and I argue it is--then >Joe Blow is going to shoot his foot off. Giving the run-of-the-mill >hacker the ability to screw up in increasingly subtle and grandiose >ways does NOT strike me as a Great Leap Forward. Who said object-oriented programming was for novices? On the contrary, the benefits of OOP show when developing larger programs, and designing a good class hierarchy doesn't come automatic, all of which makes OOP more suited for the professional. True, OOP programming is being oversold as a more natural way of programming. Personally, I don't consider adding 'a' and 'b' by sending the message '+(b)' to 'a' particularly natural. As for C++, the language is intended as the OOP upgrade for C programmers -- i.e. not novices. >]C++ has a built-in type-discriminating mechanism called "dynamic >]binding". >Yah, I know--my C++ compiler provides this. >]By the way, how about adding the tag method like this: >] >] typedef enum { CIRCLE_TAG, TRIANGLE_TAG, SQUARE_TAG } TAG; >Okay, so now add a rectangle. You're back to editing the tag enumeration, >and this is precisely how you'd do it in Ada. I never said anything else. The point is that the problem can be solved, and that it can be solved simply in just a few lines of code. Is this some kind of contest, where solutions are required not to make use of any language features also found in Ada? You designed the problem so that it would be difficult to solve it only by means of inheritance, so of course I grab into the bag of C++ features for something else that will solve the problem. And I find it. >]Still, this approach has it's problems, and I'm not claiming >]C++ to be superior to Ada. I am claiming, however, that >]dynamic binding is a valuable feature which Ada is missing. >You're claiming it, but I don't think you've proven it. That's right, I'm claiming it. And I'm not proving it, because I don't have the time for writing examples tenthousands of lines long. -- Anders Munch