[comp.sys.mac.programmer] C++ interface to Object Pascal, whyfor?

uucibg@swbatl.UUCP (3929) (11/13/89)

I'm not trying to flame, I just want to make sure I understand the nature of
the C++/Object-Pascal relationship.  Please correct my misunderstandings:


+ Object Pascal uses objects a la Smalltalk (methods and dynamic dispatch).
    (Side note: does this mean that objects in Object Pascal are weakly
     typed?)

+ Apple has extended the Cfront translator so that you can work with
  Object Pascal style objects.

+ While it's possible (apparently) to mix-and-match Object Pascal Objects
  and C++ objects in the same program, trying to do so within a class or
  class heirarchy is going to have significant limitations (which are
  essentially unavoidable due to the differing semantics of "object"
  in the two languages).
  NOTE: I only said "apparently" above because I've not spent the time to
  figure out how to do it yet... :-)

+ It's not possible to involve Object Pascal classes in a multiple inheritance
  heirarchy.

If this is correct, then it would seem that you can't use C++ to extend the
Object Pascal heirarchies in a fashion that takes advantage of weak typing of
objects (assuming that Object Pascal has weakly typed objects) or of the
Multiple Inheritance of C++ (which would make sense given the nature of the
dynamic-dispatch problem for mult. inheritance).

This would seem to indicate that the interfaces are primarily for providing
access to the power of MacApp.  This is certainly a worthwhile objective and
is valuable in and of itself.  However, I'm wondering: what other advantages
might this interface provide?

DISCLAIMER:
I wouldn't be at all surprised if much of the above is totally off kilter :-)

Thanks,
--------------------------------------------------------------------------------
Brian R. Gilstrap    ...!{ texbell, uunet }!swbatl!uucibg OR uucibg@swbatl.UUCP
One Bell Center      +----------------------------------------------------------
Rm 17-G-4            | "Winnie-the-Pooh read the two notices very carefully,
St. Louis, MO 63101  | first from left to right, and afterwards, in case he had
(314) 235-3929       | missed some of it, from right to left."   -- A. A. Milne
--------------------------------------------------------------------------------
Disclaimer:
Me, speak for my company?  You must be joking.  I'm just speaking my mind.

lsr@Apple.COM (Larry Rosenstein) (11/14/89)

In article <934@swbatl.UUCP> uucibg@swbatl.UUCP (3929) writes:

> + Object Pascal uses objects a la Smalltalk (methods and dynamic 
dispatch).
>     (Side note: does this mean that objects in Object Pascal are weakly
>      typed?)

Objects in Object Pascal are strongly typed.  Its dispatching mechanism is 
closer to that of C++ than it is to Smalltalk.

I'm not sure what you mean by "methods and dynamic dispatch" in this 
context.  In Object Pascal, you can write aView.Draw.  You can think of 
this as sending the Draw method to the object referenced by aView.  At 
runtime, the system looks up the Draw method for that object and calls 
that piece of code.

In Smalltalk, you can send a draw message to any object; even ones that 
don't understand draw.  In Object Pascal and C++ the type checking 
prevents this.  

> + While it's possible (apparently) to mix-and-match Object Pascal Objects
>   and C++ objects in the same program, trying to do so within a class or
>   class heirarchy is going to have significant limitations (which are

True.  MPW C++ can support several kinds of object representation and 
dispatching.  

(1) Standard C++ dispatching, which supports multiple inheritance, 
pointer-based objects, etc.

(2) Object Pascal style dispatching, which includes handle-based objects.

(3) You can use handle-based objects with C++ dispatching.

(4) CFront 1.2 style dispatching, which uses pointer-based objects, but 
not multiple inheritance.  (The reason for this alternative is that it is 
more space efficient than the standard dispatching, because it doesn't 
have to allow for multipl inheritance.)

The compiler figures out which run time mechanism to use based on the 
ancestor of the class.  The compiler has the built in classes 
PascalObject, HandleObject, and SingleObject, corresponding to 
alternatives 2-4.  A class can inherit from at most one of these, which 
prevents you from mixing different kinds of dispatching.  

> + It's not possible to involve Object Pascal classes in a multiple 
inheritance
>   heirarchy.

True.  If a C++ object inherits from PascalObject, then it is limited to 
what Object Pascal can do.  (Except, I think that you can use the C++ 
visibility declarations to make instance variables and method private, 
since these don't involve the runtime system, but only the compiler.)

You can mix different kinds of objects in the same program.  So you can 
write the guts of your program using multiple inheritance, while the 
objects that inherit from MacApp classes would be limited to Object Pascal 
semantics.

The special builtin classes will probably be useful to Macintosh 
programmers who aren't using MacApp.  

For example, it usually is a bad idea to allocate a lot of pointer-based 
objects, except in special cases.  Although you can overload the C++ new 
and delete operators, it probably makes more sense to use HandleObjects.

Also, C++ expands its method calls in line.  If you look at the generated 
code, you will see that a method call takes several 68000 instructions.  
Object Pascal's dispatching is a bit slower, but each method call takes 4 
bytes.  If you use the C++ dispatching mechanism, then your code size will 
increase.  So you might want to use PascalObjects to reduce your code size 
(at a cost in language features).


Larry Rosenstein, Apple Computer, Inc.
Object Specialist

Internet: lsr@Apple.com   UUCP: {nsc, sun}!apple!lsr
AppleLink: Rosenstein1

lsr@Apple.COM (Larry Rosenstein) (11/14/89)

In article <5162@internal.Apple.COM> lsr@Apple.COM (Larry Rosenstein) 
writes:

> (3) You can use handle-based objects with C++ dispatching.

When I tried this out, I discovered that HandleObjects use C++ 1.2 
dispatching, which means you can't use multiple inheritance with 
subclasses of HandleObject.  (If I had a copy of the MPW C++ manual, I 
would have known this, but I don't)

I don't know why HandleObjects are implemented this way; offhand, I can't 
think of a technical reason why this would be the case.  One should be 
able to overload operator new, operator delete, operator * and operator -> 
to implement handle-based objects with C++ 2.0 dispatching.

Larry Rosenstein, Apple Computer, Inc.
Object Specialist

Internet: lsr@Apple.com   UUCP: {nsc, sun}!apple!lsr
AppleLink: Rosenstein1

hammersslammers1@oxy.edu (David J. Harr) (11/18/89)

This doesn't have a LOT to do with the original question, but the subject
line brought it to mind, so... What, if any, difference is there between MPW
Pascal and Object Pascal? I thought that MPW Pascal supported certain object
oriented extenstions in order to allow the creation of neato-keeno things
like MacApp. Now, is this Object Pascal just a MPW pascal under another name
or does it constitute a separate product? The reason that I ask is because
when I got my informational mailing from APDA about C++ and MacApp, it lists
MPW C as costing $150, MPW as $100, and Object Pascal as _$400_! A bit of a
difference there! Anyway, I was just curious.

rickf@Apple.COM (Rick Fleischman) (11/21/89)

In article <62163@tiger.oxy.edu> hammersslammers1@oxy.edu (David J. Harr) writes:
>This doesn't have a LOT to do with the original question, but the subject
>line brought it to mind, so... What, if any, difference is there between MPW
>Pascal and Object Pascal? I thought that MPW Pascal supported certain object
>oriented extenstions in order to allow the creation of neato-keeno things
>like MacApp. Now, is this Object Pascal just a MPW pascal under another name
>or does it constitute a separate product? The reason that I ask is because
>when I got my informational mailing from APDA about C++ and MacApp, it lists
>MPW C as costing $150, MPW as $100, and Object Pascal as _$400_! A bit of a
>difference there! Anyway, I was just curious.

MPW Pascal v.3.0 and MPW Object Pascal v.3.0 are one and the same.  We are
in the process of changing the name to make it more obvious to people that
our MPW Pascal v.3.0 IS object-oriented.  In fact, all of MacApp, our
object-oriented class library for generating Macintosh applications was
written using MPW Object Pascal v.3.0.

Also, you misread the pricing in the mailing.  MPW Object Pascal costs
$150.00 when you buy the compiler alone.  The MPW Object Pascal Bundle costs
$400 and includes MPW, MPW Object Pascal, MPW Assembler, SADE, ResEdit, and
MacsBug.

Hope this clears things up a bit!

Rick Fleischman
Developer Channels/APDA
Apple Computer, Inc.
e-mail:  rickf@apple.com
AppleLink:  FLEISCHMAN@applelink.apple.com