in reply to Module programming

You haven't said if you are the designer of these modules, or are just using these modules. If you're the designer, please redesign. Global variables are generally not a good idea, and you're starting to head down a treacherous area of heavy-duty coupling between these modules that will make life bad for you and your maintenance programmers.

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
RE: RE: Module programming
by (\/)(\/) (Novice) on Oct 31, 2000 at 05:01 UTC
    I realise that global variables are not a very good idea. But can someone sugegst a better design ??

    In the example above, I need to pass my Proxy details to each module B.pm and C.pm so that they can fetch individual docs. from the Internet. Now there are three ways of doing it, as far as I can see.

    1. Pass the value individually to each module.
    2. Insert the proxy value into a config file that is opened by each module.
    3. Set the proxy value for A.pm and then use it for B.pm and C.pm

    Now I do not like (1) so much because I need to pass the same value again and again to each module.

    I do not like (2) so much because I want to keep the config as simple as possible - Nothing extra other than the config needed for basic PERL modules.

    Thus I came down to (3).

    Any other suggestions ??
      Can you give real names to A, B, and C? What roles are they playing? Can B and C be specializations (subclasses) of A? Can B and C ask A what the current proxy setting is? If you had three people named A, B, and C, what would their job titles be, what would each of them know, and what would they have to get from each other?

      A global variable is like person B riffling through the desk drawers belonging to person A just to get some info he knows. It's better to ask, not steal from behind. Because what happens if person A no longer puts it in the same drawer?

      -- Randal L. Schwartz, Perl hacker

        Oh ok,.. What I plan to do a write perl modules to fetch headlines/news from sites and show on host website as dynamically generated pages. A = basic module that prints the HTML header and footer. B,C,D etc = module to print specific site's news (like /.) Each module B,C,D will need the proxy server name and port to access and retrieve the individual site backend file. This is the scenario.. (\/)(\/)