On 12 Mar 2013, at 18:50, Jens Alfke wrote:


On Mar 12, 2013, at 9:44 AM, John McCall <rjmcc...@apple.com> wrote:

However, that wouldn't be an idiomatic implementation. The usual expectation is that allocating methods, like +new methods, construct an object *of type self* (at least).

Are you just quibbling about the prefix “new-“? The specific method +new is expected to create a new instance of the receiving class, yes. There may be a convention (I can’t remember?) that class methods prefixed “new-” are intended to do the same.

I'm not sure if its a convention, but it does make sense, for instance, I've been code like this before.

-(NSDictionary) newDictForSomethingWithInfo:(Info*) theInfo
{
// returns an dictionary allocated and initialized
}

somewhere else in the same class:

myDict = [self newDictForSomethingWithInfo:myInfo];

Which keeps the compiler/analyzer happy in non-ARC and works ok with ARC enabled. If this isn't a convention then it should be IMO unless there is another prefix used? allocDict would work, but this is as bad or as good as new in this respect.


However, it’s hardly unusual to have a class method that instantiates and returns some other kind of object. Dave’s use case of a dictionary that describes metadata about the class seems reasonable.

This is why I was talking about instance methods and fields: because, generally, people introduce new classes because they expect to create instances of them, and [[self superclass] newDict] bypasses that in a way that might not be obvious.

I don’t see the problem here. Presumably the class is going to be instantiated at some point,

This is the language I used, and is another source of confusion on this. Apparently the language technically should be:

"Presumably the class is going to be to be used to instantiate an Object at some point" which keeps everyone happy? lol

but the code Dave is working with is operating on metadata about the class, so only class methods are involved in it.

Exactly!

All the Best
Dave
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to