• 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: Why can't I name a property `tag'?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why can't I name a property `tag'?


  • Subject: Re: Why can't I name a property `tag'?
  • From: an0 <email@hidden>
  • Date: Fri, 11 Jul 2008 09:45:23 +0800

It is just simple as you said.
And it is cool just after I know what's on earthing happening there.
Thanks a lot.

On Fri, Jul 11, 2008 at 2:03 AM, Bill Bumgarner <email@hidden> wrote:
> On Jul 10, 2008, at 8:55 AM, an0 wrote:
>>
>> Sure.
>> I'm grateful that you tell me the internal truth instead of confusing
>> me even more by just saying it is my responsibility to tell compiler
>> more.
>> But if different return types cause different native code, how could
>> my program still work with the mistaken type(an NSString * returned
>> from the inner message is treated as an NSInteger at the first place,
>> then is passed as an NSString * to the outer message) guessed by
>> compiler?
>
> Whichever method the compiler sees first wins.
>
> While Objective-C is polymorphic, it does not support type based dispatch or
> type based method differentiation (like, say, Java).
>
> In Objective-C, the following doesn't make sense:
>
> - (NSInteger) tag;
> - (NSString *) tag;
>
> It won't compile if in the same class file and, as you have discovered,
> it'll cause no end of problems when the same method name -- the same
> selector -- has different argumentation across different classes in the
> class hierarchy.
>
> To put it more precisely:  Objective-C has a single, global, namespace for
> all methods.   Every method's name, every selector, is in a shared
> namespace.   The method's selector does not include any typing information
> and, thus, the type of the arguments and return value of the method are not
> used by the compiler to disambiguate invocations.
>
> As a result, the standard pattern is to *never* declare the same method name
> twice, but with different types of arguments or return values.
>
> For someone coming from C++ or Java, this may seem like a pretty nasty
> restriction.  It really isn't.  It is just different. And it has some very
> distinct advantages.   Two, in fact:
>
> - there is no name mangling
>
> - you don't have to figure out the types of the arguments to figure out
> which of N possible methods on your class, all named identically save for
> argumentation differences, were invoked
>
> I.e. it is dead simple.
>
> b.bum
>
>
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Why can't I name a property `tag'? (From: an0 <email@hidden>)
 >Re: Why can't I name a property `tag'? (From: Graham Cox <email@hidden>)
 >Re: Why can't I name a property `tag'? (From: an0 <email@hidden>)
 >Re: Why can't I name a property `tag'? (From: "I. Savant" <email@hidden>)
 >Re: Why can't I name a property `tag'? (From: an0 <email@hidden>)
 >Re: Why can't I name a property `tag'? (From: Jean-Daniel Dupas <email@hidden>)
 >Re: Why can't I name a property `tag'? (From: an0 <email@hidden>)
 >Re: Why can't I name a property `tag'? (From: Jens Alfke <email@hidden>)
 >Re: Why can't I name a property `tag'? (From: an0 <email@hidden>)
 >Re: Why can't I name a property `tag'? (From: Bill Bumgarner <email@hidden>)

  • Prev by Date: Re: looking for some help
  • Next by Date: Re: Quick look preview multipage rich text
  • Previous by thread: Re: Why can't I name a property `tag'?
  • Next by thread: Re: Why can't I name a property `tag'?
  • Index(es):
    • Date
    • Thread