FROM : Mike Abdullah
DATE : Tue Mar 11 22:58:11 2008
On 11 Mar 2008, at 21:09, Stuart Malin wrote:
> Thanks Chris.
>
> You are right on -- I had more than one method signature with the
> same, generic style name.
>
> My rationale for departing from the canonical approach is because
> then I get a bit of extra type checking at compile time.
>
> Given the canonical approach of returning id, one can define an
> interface for a class with an ivar:
>
> classA *aIvar
>
> and in the implementation, assign any sort of object to it.
>
> aIvar = [NSString stringWithString:@"OOPS"];
>
> With my approach, when I define the interface for classA's
> initializer to be:
>
> - (classA*) - initClassA ......
>
> then if I inadvertently assign an allocation to the wrong ivar:
>
> NSString *s;
>
> // some code later ...
>
> s = [[classA alloc] init];
>
> the compiler will issue a warning. With the canonical approach of
> the initializer returning type id, it wouldn't.
>
> Now, I know this catches a puny amount of possible errors, but that
> is the reason why I deviated from the ordinary practice.
>
> Given this, I think it would have been beneficial if
>
> [className alloc]
>
> returned of the className type, rather than id. But I am certain
> there are numerous reasons against doing so, as otherwise it would
> likely have been implemented that way.
Well because you simply cannot do this. Somehow every single class
would have to declare their own version of the +alloc method that
returns an object of their specific type. Do you really want the
hassle of having to do that every single time you create a subclass?
This is not something that can be changed in the framework, but would
have to be a change to the language/runtime.
>
>
> That aside, your suggestion to use protocol declaration for the
> delegate is something I had planned to investigate. Thanks for the
> further tips.
>
DATE : Tue Mar 11 22:58:11 2008
On 11 Mar 2008, at 21:09, Stuart Malin wrote:
> Thanks Chris.
>
> You are right on -- I had more than one method signature with the
> same, generic style name.
>
> My rationale for departing from the canonical approach is because
> then I get a bit of extra type checking at compile time.
>
> Given the canonical approach of returning id, one can define an
> interface for a class with an ivar:
>
> classA *aIvar
>
> and in the implementation, assign any sort of object to it.
>
> aIvar = [NSString stringWithString:@"OOPS"];
>
> With my approach, when I define the interface for classA's
> initializer to be:
>
> - (classA*) - initClassA ......
>
> then if I inadvertently assign an allocation to the wrong ivar:
>
> NSString *s;
>
> // some code later ...
>
> s = [[classA alloc] init];
>
> the compiler will issue a warning. With the canonical approach of
> the initializer returning type id, it wouldn't.
>
> Now, I know this catches a puny amount of possible errors, but that
> is the reason why I deviated from the ordinary practice.
>
> Given this, I think it would have been beneficial if
>
> [className alloc]
>
> returned of the className type, rather than id. But I am certain
> there are numerous reasons against doing so, as otherwise it would
> likely have been implemented that way.
Well because you simply cannot do this. Somehow every single class
would have to declare their own version of the +alloc method that
returns an object of their specific type. Do you really want the
hassle of having to do that every single time you create a subclass?
This is not something that can be changed in the framework, but would
have to be a change to the language/runtime.
>
>
> That aside, your suggestion to use protocol declaration for the
> delegate is something I had planned to investigate. Thanks for the
> further tips.
>






Cocoa mail archive

