Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Coding Perl With Style

by wog (Curate)
on Nov 27, 2001 at 06:31 UTC ( [id://127701]=note: print w/replies, xml ) Need Help??


in reply to Coding Perl With Style

"config.pm" is not a good name for a module. "Config.pm" is a built-in module to perl. Names beggining with lowercase letters should be considered reserved for pragmas; they are considered "special". "Something::Config" would probably be okay, however.

As for your actual question, you could probably make an object that encapsulated this configuration stuff , or (updated) and have your exsiting classes have it as an instance "variable". Or you could, as you suggested, just pass it as an argument to every function. I see no problem with either of these approaches; it is far cleaner then having your code not be so reuseable and modular.

If I declare a scalar as a constant in a module then export that scalar will it remain a constant?

"constants", as you are referring to, are actually functions that have a prototype of () (explictly no arguments), and thus are inlined by perl. You will get this optimization as long as the function is imported (so perl what to use and that it should inline it) when the relevant code is compiled.

Replies are listed 'Best First'.
Re: Re: Coding Perl With Style
by Dogma (Pilgrim) on Nov 27, 2001 at 07:13 UTC
    Actualy config.pm isn't the real name. It's Yaps::Config.pm so we're on the same page there. So your suggesting using Config.pm as a base class and having all classes inherit from it. Like a smalltalk-90 oo tree right? Thanks for the answer about inlining.
      I would personally think you want a "has-a" relationship. "Configuration" info is shared by many (instances of) classes; it is not something that each of the instances should maintain an independent copy of.

      (update: Nor do I think you should have one copy of it be held statically by a base class, of course. I would prefer to leave room to maintaining to independent sets of this data in one application, if need-be.)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://127701]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-25 08:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found