Re: Global variable for whole application.
Re: Global variable for whole application.
- Subject: Re: Global variable for whole application.
- From: Filipe Varela <email@hidden>
- Date: Wed, 18 Apr 2007 16:20:03 +0100
Well in that specific case, you're declaring constants for message
strings and assigning them values in the implementation file. Why not
use localizations instead? Or key value coding and store the strings
in a plist (key = kParticipantDB_Participant...., val = "Participant
Joined") even if you don't need localization? Sure, it works the way
it is, but why not fully separate code from data?
And, do you include that header in ALL your source files? Is it
really (like the original message mentioned) a global application
scope variable?
Just to clarify, i consider extensive use of global application scope
variables a bad design in Cocoa apps because you can end up having
different threads (some stuff just detaches automatically) and you
may not know beforehand (especially if you're taking your first steps
into the frameworks) which thread runs which piece of code. This can
cause thread synch problems unless you code some mutual exclusion
procedures and that does require careful planning and testing.
I realise you emphasised _constants_ (no synch blues there) but the
original post did mention both constants and variables.
Cheers,
Filipe
On 2007/04/18, at 16:02, Shawn Erickson wrote:
On 4/18/07, Filipe Varela <email@hidden> wrote:
no matter what you're trying to do, that's a very very bad design.
you can't possibly need an application-wide global variable. use
classes, accessors, notifications, delegation, etc
Global _constants_ are common and reasonable to do... just look at the
Cocoa.framework for countless examples.
For example I do things like the following in my code all the time
In .h file...
// Participant database notification name constants
extern NSString* const kParticipantDB_ParticipantJoined;
extern NSString* const kParticipantDB_ParticipantLeft;
...
In .m / .mm file...
NSString* const kParticipantDB_ParticipantJoined =
@"Participant_Joined";
NSString* const kParticipantDB_ParticipantLeft = @"Participant_Left";
...
Use of #defines for constants has its uses but it also has it limits
and weaknesses. I personally wouldn't recommend their use with any
type of generic statement.
-Shawn
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden