The main problem with the code in your example is that, in some cases, the -init method returns an object other than the one you created with + alloc. If this happens, then your code will be incorrect, because you are not assigning the result [c init] to c, and you will end up working with the wrong object (and one that was not correctly initialized at the same time). This is why the standard idiom should always combine + alloc and -init on the same line:
id c = [[Facial highlight] init];
Now you may have written the Person class and gained first-hand knowledge that -init always returns the same object, but I donโt need to be familiar with Personโs internal work in order to read your code and whether it makes sense or not. . Your code is โbetterโ in the sense that everyone can say that it does the right thing if you follow the usual convention.
I don't think it's terrible to declare c as a type identifier, but in this case it seems silly. You know that c will be of type Person *, so why declare it as id and throw out useful information that the compiler can use to help you write code better? If there is a good reason to use an identifier, thatโs fine, but if you can be more specific by type, you should do it.
Caleb
source share