discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is +[NSMutableArray initialize] completely implemented?


From: David Ayers
Subject: Re: Is +[NSMutableArray initialize] completely implemented?
Date: Sun, 22 Feb 2004 13:53:27 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040113

Richard Frith-Macdonald wrote:

On 22 Feb 2004, at 11:56, Philip Mötteli wrote:

and that [NSMutableArray+initialize] is called before any other method of the class, so I don't know how -initWithCapacity: could be called without NSMutableArrayClass being initialised.
or step through in debug yourself to find out what is going on?


I set a breakpoint in both +initialize, in NSMutableArray and NSArray and NSArray's initialize is clearly not called.


Then I guess for some reason the runtime does not think that NSMutableArray inherits from NSArray ... why not?


I found the problem: I have a +initialize method in a category of NSArray. So the runtime system called only this one.


Interesting ... it's worth trying to remember that problem because it's not at all obvious.

Perhaps we should have some coding hints somewhere to say things like ... 'don't override +initilize in a category'


This sounds reasonable... I also fell into that trap before because I believed to have read that +initialize would be called for every category. But I had confused that with +load which /does/ get called per category.

Actually, it's not clear to me whether the runtime should try to detect this situation and call the class implementation before calling the category implementation ... probably not , as I think that categories are generally supposed to be responsible for handling things like that. Also, what if two or more categories override +initialize etc. As far as I know there is no standard way to resolve the situation where multiple categories override a method.

The +load mechanism works because the runtimes invokes it directly (i.e. via implementation pointer when loading the category and not via message lookup.) I don't think we should try doing the same for the current runtimes wrt +initialize. Now whether a future unified runtime had similar mechanism that invokes a standardized method per Class/Category after all runtime initialization has been done, is a different issue.

Perhaps GNUstep should establish some conventions for this and perhaps provide a few runtime helper functions to assist in managing this sort of thing.
On the other hand, it's rarely an issue ...

That's something I think is worth pondering about.

Cheers,
David




reply via email to

[Prev in Thread] Current Thread [Next in Thread]