On May 25, 2014, at 3:18 AM, 2551 <2551p...@gmail.com> wrote:

> That's what I understood from the stackexchange discussion I linked to. As I 
> said, those issues aren't relevant in this case, so I was wondering if there 
> were others. From the replies thus far, it seems not, and I'm inclined to go 
> to style 2 for reasons more or less outlined by Quincey.

I’ve seen people use style 1, and to be honest it looks nuts to me, a ‘code 
smell’ of a newbie programmer. It’s identical to style 2 to the compiler, but 
harder for a human to read and understand.

The SO answer is a typical case of over-answering the question. The linker will 
combine all instances of the same string literal in one binary into a single 
object, so it doesn’t matter how many times you put @"foo” in your source code. 
And it makes absolutely no difference whether that literal is assigned to a 
variable or used directly as a method parameter.

What _is_ important is the DRY principle (Don’t Repeat Yourself). If  @“foo” is 
an important string, like a key in a dictionary where you store some value, 
then you shouldn’t sprinkle it all over your code, but instead declare it once 
as a global constant. That way the compiler can catch typos, and it’s easy to 
change the string later if you every need to. This has nothing to do with 
performance, and everything to do with maintainability and reliability.

—Jens
_______________________________________________

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