Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!hplabs!hp-pcd!hplsla!jima From: jima@hplsla.HP.COM (Jim Adcock) Newsgroups: comp.lang.c++ Subject: Re: Objective C: Flame Fodder Message-ID: <6590109@hplsla.HP.COM> Date: 28 Apr 89 17:19:14 GMT References: <5007@tekgvs.LABS.TEK.COM> Organization: HP Lake Stevens, WA Lines: 70 > In article <6590099@hplsla.HP.COM> jima@hplsla.HP.COM (Jim Adcock) writes: > > ... > >To me, C++ is object-oriented, and ObjC isn't. > > ... > > From my understanding of Obj-C (from reading Brad Cox's "Object Oriented > Programming"), there is no reason you can't add the [] messages to C++, > getting Objective-C++. Then you have the best (and worst) of both worlds. > [p.s. IMHO Obj-C is more like Smalltalk so "objected-oriented" but that > is by-the-by] ... cheers, matt. Well, as one who comes from an ObjC enviroment, with on the order of 100 man-years invested by my local organization in ObjC, many people here have certainly entertained the thought. And the answer is, practically speaking, you cannot do it. ObjC is a compiler that accepts straight-C plus ObjC [myObject with: junk andmore: junk] syntax for messaging and "compiles" the result to straight-C code. C++ is a compiler that accepts straight-C plus C++ extensions to the syntax. Neither accepts the other's extensions to C syntax. So to run one into the other you'd be restricted to using the straight-C common subset used by both langauges. If you're lucky. In which case you've gain nothing. My answer was to try to salvage ObjC code [where ObjC development gave us something actually reuseable] by writing a translation aid that turns ObjC's: [myObject with: junk andmore: junk] into a C++ myObject->with_andmore(junk, junk) [in real-world examples the name translation usually comes out prettier than this :-] To perform this translation reliably, you have to parse the language, textual substitution doesn't hack it. So the translation aid ends up looking a lot like the front end of a full compiler. Except my translator [at least] doesn't understand the semantics, typing, etc of objects, so the translator only saves maybe 90% of the effort one would have to put into a totally manual translation effort. Initially, coming from an ObjC environment, I felt: [myObject dosomethingwith: this and: that] was a prettier syntax than C++'s myObject->dosomething(this, that) but ObjC programmers [hackers?] write a lot of code like: [myObject dosomethingwith: this and: that and: thenextthing and: more and: more and: more] which really isn't object oriented programming -- its really functional programming. C++ syntax, and low messaging cost, encourages programmers to only use zero, one or two parameters to a method. So in C++, you "set up" your object, then ask it to perform a task based on its state, rather than passing in everything as a parameter. And the C++ syntax is proving to be much more flexible. People are taking C++ in an incredible variety of directions -- and for the vast majority of cases, C++ syntax is up to the job.