• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Future Objective-C changes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Future Objective-C changes


  • Subject: Re: Future Objective-C changes
  • From: Dietrich Epp <email@hidden>
  • Date: Tue, 20 May 2003 13:14:29 -0700

On Monday, May 19, 2003, at 09:30 US/Pacific, Martin Hdcker wrote:

Hi there,

I hear this coming up quite some times, so I thought I'd ask. :)

What about double dispatch?

As far as I know it's dispatching a method call on the type of both the argument and the receiver, thus effectively doing the (almost) same thing as name mangling does. So this would allow code like this to work:

- do:(id)anObject;
- do:(NSString *)aString;

I'd like to put my two cents in on C++ name mangling. The problem with C++ automagic name mangling is that it makes for unexpressive names. This manifests itself well with the constructor functions:

class Quaternion {
public:
Quaternion (float w, float x, float y, float z);
Quaternion (float x, float y, float z, float a);
};

I have two constructors that each take four floating-point numbers! The first one creates a quaternion from its components, and the second creates one from an axis and and angle. The reason C++ behaves this way is that lazy naming (Quaternion(...) vs. QuaternionWithComponents(...)) worked its way into standard usage. Think this shortcut wouldn't kill Objective C? Think again:

-[NSWindowController initWithWindowNibName:owner:]
-[NSWindowController initWithWindowNibPath:owner:]

If people start lazily naming methods with different types, then they'll start lazily naming _all_ methods. Pretty soon you have messages that are impossible to decipher without looking at a half dozen headers. I know I sound like a paranoid freak. Syntactic sugar causes cancer of the semicolon.

Well... am I right on this? If so, what's the difference from the effect created from name mangling? (apart from the technical difficulties that name mangling creates)

What about:

@class Matrix
-(Vector *)multiplyBy:(Vector *)vector;
-(Matrix *)multiplyBy:(Matrix *)matrix;
-(Matrix *)multiplyBy:(float)scalar;
@end

This is perfectly fine in C++... but in Objective C you'd have to do some pretty funky tricks at compile time and at run time, especially if you have to deal with id as well. Alas, our executable sizes and compile times skyrocket and we flee to the Ruby and Python bridges.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
  • Follow-Ups:
    • Re: Future Objective-C changes
      • From: Gerard Iglesias <email@hidden>
References: 
 >Re: Future Objective-C changes (From: Martin Häcker <email@hidden>)

  • Prev by Date: Serial CTS and DTS
  • Next by Date: Re: NSRectFill not supporting compositing?????
  • Previous by thread: Re: Future Objective-C changes
  • Next by thread: Re: Future Objective-C changes
  • Index(es):
    • Date
    • Thread