in reply to How to initialize a Global in a module
One good way to approach things is to say that all of your modules will contain 'subroutines' or 'objects,' and if necessary maybe a subroutine that creates a singleton object-instance on demand. Now you have a well-defined way for things to be initialized, and while the methods of the object are executing they have a well-defined "place to put things," i.e. the object itself. This also naturally encourages you to put the logic where it properly belongs ... right there alongside the data that's being manipulated. Values can easily be initialized either in the "new()" method, or lazily, on-demand, and all of that plumbing-work is right there where you'd expect it to be, not scattered all over the application. It works out really well in practice.
|