Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!uunet!olivea!apple!marc From: marc@Apple.COM (Mark Dawson) Newsgroups: comp.sys.mac.programmer Subject: Re: C/C++ difference? Message-ID: <49114@apple.Apple.COM> Date: 13 Feb 91 15:39:07 GMT References: Organization: Apple Computer Inc., Cupertino, CA Lines: 124 In article jeffb.bbs@shark.cs.fau.edu (Jeffrey Boser) writes: >with all the postings complaining about THINK C not being C++, >i have a few questions: > >1) my think C manual says it is upwards compatable with c++, meaning > think C is lacking something in c++. what exactly is it lacking? C++ supports o data abstraction the data needed by that code is local to that code; if you want access to that data, you have to ask the code ("object") to get it for you) o inheritance you can derive a new user-defined type from an old one and make changes only where you need them--in theory this makes for easier code reuse) o polymorphism the actual creating of a new user-defined type that can inherit (or not) properties of the old type, plus add something. For example, you could have a type "oval" that draws an oval. Using polymorphism, you could derive a sub-type called "circle" that uses (inherits) all of "oval"'s drawing routines, but defines that the x & y axises (sp?) are the same. o Function overloading Allows you to define a function that takes different types--you could define x(double y) AND x(int y)...you would write two routines && the compiler would route the call to the correct routine, depending on the passed parameter. o Operator overloading Allows you to redefine how an operator works with a type--for example, if you used operator overloading when defining a Str255, you could do: x = x + "hello world" + "\phello world II"; it would concatenate both strings (using function overloading to concatenate first a C string and then a Pascal string. These are all used in the "object-oriented" concept. Obviously, this power allows you to write even worse code than in C; it can also help you write better (easier to read) code. > >2) from previous conflicts of similar nature (some people think that their > way of doing something is the only way), such decisions are usually > based on ignorance. (usually, not always. remember attitudes about > the mac when it first came out?) why is c++ so important that it > precludes all alternatives? and does it have anything to do with 1? > I assume this relates to Apple converting its MacApp over to C++. At the MacApp conference last week Apple (note that I work at Apple, but in these instances, I'm a 3rd party developer just like a lot of you) gave some reasons: (1) A lot of corporate development houses are very standards-oriented. They wish to use object-oriented languages and the only commercial standards are Smalltalk and C++. It sounded like it was getting hit with a "toy language on a toy computer" argument. Apple wanted to convince more programmers to develop; to do so I got the impression that they felt that they needed to start using a commercially standard langauge. (2) Apple's internal development is very quickly going to C++ (it was mentioned that the sys 7.0 finder was written in C++); the MacApp team didn't want to be constantly porting code that they'd like to use from C++ to Object Pascal, plus they'd like to take advantage (when they can) of some of the large body of C++ objects/classes that are available (they mentioned stuff like sorting routines). So it boils down to that Apple feels it needs to provide its next generation support in a more commercial language, C++. They feel that the development community (the whole one--MSDOS, Unix, etc world) is moving towards using C++ as its standard, so its in Apple's interest to provide support for it. Its not that C++ is better, its just more commercial && its hoped that it will attract more cross-developers (this could make it easier for Mac programs to be ported to other platforms, but since the Mac only holds 10-15% of the market, Apple is gambling that it'll see more programs moving the other way). _ >3) if the state of the art (in mac programming) moves toward that, what > will be the consequences? remember, the toolbox is based on a pascal > library. c is not a good initial language for the mac. > By using C++, you can actually make very Pascal-like calls to the toolbox, plus as readable code (examples taken from Object Pascal-C++ conversion talk at the conference ---- Pascal ----- PROCEDURE TView.Resize (width, height:VCoordinates); BEGIN IF (fSize.h <> width) | (fSize.v <> height) THEN SetVPt(delta,width-fSize.h,height-fSize.v); fSize.h := width; fSize.v := height; END; PROCEDURE foo(**); BEGIN saveIt : PenState; GetPenState(saveIt); SetPenState(saveIt); END; ----- C++ ------- pascal void TView::Resize(VCoordinate width,VCoordinate height) { VPoint pt {width, height}; if (fSize != pt) delta = pt = fSize; fSize = pt; } pascal void GetPenState (PenState &pnState); pascal void SetPenState (const Penstate &pnState); void foo() { PenState saveIt; GetPenState(saveIt); SetPenState(saveIt); } ---- So, you can see that C++ can allow you to more easily code toolbox routines; you don't have to worry about when to use C's '&' (address of) operator. Hope this helps, Mark -- --------------------------------- Mark Dawson Service Diagnostic Engineering AppleLink: Dawson.M Apple says what it says; I say what I say. We're different ---------------------------------