Re: best practices for globals/identifiers in a Cocoa app
Re: best practices for globals/identifiers in a Cocoa app
- Subject: Re: best practices for globals/identifiers in a Cocoa app
- From: Alastair Houghton <email@hidden>
- Date: Mon, 10 Nov 2003 09:15:27 +0000
On 10 Nov 2003, at 01:50, John Clayton wrote:
>
Wow, that's cool. So a .m file with no implementation is fine. That
>
makes sense ... now. Thanks, Alistair.
>
>
Oh also, would you also say that the general approach of storing
>
strings/keys in extern'd variables is the right way? I know some
>
people use macros, and I know extern'd variables like this need to be
>
careful of name collisions. But, the former approach seems to be more
>
in keeping with the Obj-C approach. Would you agree?
Yes, it's better than using macros. Three good reasons spring to mind:
1. The names of your strings are symbols in the debugger. This is very
useful as it lets the debugger use the same name for the string
constant that you did in your program.
2. If you use a macro, then each object file you use the string in will
contain at least one copy of that string. I don't know whether the OS
X build chain can merge duplicate constant data (like strings) during
the link phase (it certainly is possible, but I haven't checked),
however using this technique completely avoids the problem, as there
will be only a single copy of the string in your program.
3. If you use a macro, then any change to the string requires
re-compilation of all of the files that #include the header that
defined the macro. Using extern variables means that only the strings
file needs recompiling.
Also, take a look at this thread:
http://cocoa.mamasam.com/COCOADEV/2003/10/2/75775.php
Kind regards,
Alastair.
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.