Re: How to choose different implementations of an object method at runtime?
Re: How to choose different implementations of an object method at runtime?
- Subject: Re: How to choose different implementations of an object method at runtime?
- From: Ken Thomases <email@hidden>
- Date: Thu, 23 Jan 2014 15:05:40 -0600
On Jan 23, 2014, at 2:38 PM, Michael Crawford wrote:
> On Jan 23, 2014, at 2:45 PM, Jens Alfke <email@hidden> wrote:
>
>> On Jan 20, 2014, at 12:27 PM, Michael Crawford <email@hidden> wrote:
>>
>>> As I'm sure you are aware, 10.8 now defines a method that does the same thing using the same name.
>>
>> That's exactly why you should unambiguously prefix the names of category methods you add to system classes. Collisions are dangerous. Change your method name to "mc_CGColor" or whatever, and this won't be an issue.
>
> Relax.
It's hard to see where Jens's reply was overwrought.
> I'm sorry but this is simply not where I want to go.
It's not clear what you're responding to here. Jens pointed out that using categories to add methods to framework classes and using names that _might_ collide is dangerous. He's right, it is. It hardly matters whether you want it to be or not.
If you had shipped an app that included a category that added a -CGColor method to NSColor, then when it ran on 10.8 or later your method would have replaced the original. If the frameworks themselves call that method (which seems likely), they'd start getting your implementation rather than the original. At the very least, we know that would have caused a leak because your method had different memory management semantics than the original. Your method might also have had other significant differences.
> I'm not interested in writing code that does something that the system already does. At the same time, I want to provide that missing functionality on older versions of Mac OS X without having two versions of source code, if at all possible. Consider it an academic exercise. It is not the end of the world and I am not the devil.
Seems like a non sequitur. Jens's comment was only about the naming, which isn't relevant to any of the above. Nor did he accuse you of being the devil.
> I do appreciate everyones responses, though. This is a nice place to learn new things. I reserve the right, however, to set my own policy with regard to what I will create and how I make use of our combined expertise in doing so.
Nobody tried to forbid you from doing so. They simply offered advice.
Regards,
Ken
_______________________________________________
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