Re:Cargo-cult typing, or: Objective-C's default type is id
by dep_b on Thursday March 06, 2014 @05:32AM
(#7352940)
Apple is wildly inconsistent with their example code and even the templates within XCode when you add a ViewController for example. Same line for the first accolade or the start or the next time in the same file. I always find myself correcting their code, that's just bad.
Re:Cargo-cult typing, or: Objective-C's default type is id
by mpweiher on Wednesday March 05, 2014 @06:32PM
(#7350764)
However,
-foo
is even better. :-)
Re:Cargo-cult typing, or: Objective-C's default type is id
by myko on Wednesday March 05, 2014 @08:32PM
(#7351257)
No, -foo is confusing and reduces readability.
Re:Cargo-cult typing, or: Objective-C's default type is id
by mpweiher on Thursday March 06, 2014 @02:42AM
(#7352415)
How so?
Re:Cargo-cult typing, or: Objective-C's default type is id
by myko on Thursday March 06, 2014 @09:26AM
(#7353797)
It is difficult to tell at a glance if -foo is returning something or just modifying state.
Re:Cargo-cult typing, or: Objective-C's default type is id
by mpweiher on Friday March 07, 2014 @04:37AM
(#7359301)
No it's not. If it didn't return anything, it would be
-(void)foo;
This is how C and by extension, Objective-C work: to indicate "nothing" you have to put in something, specifically "void".
- (id)foo
reduces readability, while
-(id) foo
is much better.
I realize the first one is more common in Apple and is probably more standard, but it begs the question why such a horrible convention ever caught on.