Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!ut-emx!slcs.slb.com!asc.slb.com!hargrove From: hargrove@asc.slb.com (Jim Hargrove) Newsgroups: comp.object Subject: Re: C++ vs. C Message-ID: <1991Apr25.213211.24114@asc.slb.com> Date: 25 Apr 91 21:32:11 GMT References: <1991Apr24.125926.5146@asc.slb.com> <18905@crdgw1.crd.ge.com> Sender: news@asc.slb.com Organization: Schlumberger Austin Systems Center Lines: 59 In-Reply-To: kornfein@azores.crd.ge.com's message of 25 Apr 91 12:56:59 GMT Nntp-Posting-Host: nobelium >>>>> kornfein@azores.crd.ge.com (Mark M. Kornfein) writes: >> In article <1991Apr24.125926.5146@asc.slb.com> hargrove@asc.slb.com (Jim Hargrove) writes: > >This note is prompted by several postings by Scott Guthery, beginning >with The Emperor Strikes Lethe. I am struck by how different SBG's >experience with object oriented programming differs from my own. I >began programming in C++ about 18 months ago. Prior to that, I worked >mainly in C, though I have used many different languages over the >years. > >I believe that I am writing better programs today after switching to >C++. Here is an example: >> [deleted C program and text] >Obj->Display(W); > >which is better both technically and aesthetically. >> This example shows both the power of object oriented programming and a >> drawback of it. The C example is somewhat easier to debug and test than >> the C++ example from my experience. This is especially true if I did not >> write the code originally. This is a telling argument. In fact, it is the single biggest argument against the use of C++. All I can say is that my experience in using C++ indicates that it is easier to maintain than C. >> From looking at the C++ I have no clear idea what method will be called without >> looking further into the Display method and seeing which display method is >> envoked for which object. If I needed to change the Display methods I do not >> even know which one's exist from this code. It is true that a good browser >> can help with this problem but in the real world one does not always have that >> or even always have access to the executable code. Yes, good tools would be a big help. The state of C++ tools today, especially in the Unix world, is pretty poor. Some stylistic conventions help. For example, we don't use much overloading of functions by the type of arguments. This makes it easier to find the routine to be invoked. And yes, we have occasional surprises, such as when you single step the Obj->Display(W) routine and wind up somewhere you don't expect. BUT, I think you are overlooking a major maintenance flaw of the C code. When I add a new class of object, I have to modify the DisplayObject routine coded in C. Even if I use a table of functions, I still have to modify the table. In C++, the compiler takes care of both of these tasks. AND, I think the technical superiority of the C++ implementation is significant. It isn't so important when there are only 4 cases. But what if there are 20 or so? Then the savings in memory and execution may be really important. -- -- jwh