Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Should you use a module to hold configuration items?

by Your Mother (Archbishop)
on Sep 18, 2010 at 22:07 UTC ( [id://860659]=note: print w/replies, xml ) Need Help??


in reply to Should you use a module to hold configuration items?

whether this is considered good Perl coding practice?

It's bad practice and generally shows a lack of maturity in the developer which is why it seems to be pretty common. Though, as CountZero said, it depends.

The sniff test is something like-

  • Is the code all config? Something like a DBIx::Class::Result schema file is basically pure configuration which changes infrequently, if ever, so it should be code because moving it to config would gain nothing and would complicate its use.
  • Does the config make it hard to change, repurpose, deploy, or edit code? Then it should be in config files.
  • Comment on Re: Should you use a module to hold configuration items?

Replies are listed 'Best First'.
Re^2: Should you use a module to hold configuration items?
by mr_mischief (Monsignor) on Sep 19, 2010 at 12:43 UTC

    I'm not sure it's necessarily bad practice. If it's user-level configuration, there should probably be a user-level interface to change it. If it's really more a set of constants gathered together similar to a C header file that may change but only rarely and at the hands of a programmer, then I think a module is a pretty good idea.

    Package variables or constants can be very handy. Since it's older it might not have been written with the benefits of our, or the author may have wanted to be extra clear on where those values reside. IMO there's not much reason to bring in YAML, JSON, XML, Windows-style INI files, or some other non-Perl language to parse if they are just used as common constants unlikely to change.

    If the end user is not a programmer and is being expected to change the modules, that's asking for some level of frustration. That frustration could spread to many people by the end of it, too. There should be a well-documented interface from the user interface to do user-level configuration. Whether that's a very simple .rc file, command-line options, a separate configuration program, a menu in the main program, or whatever, it shouldn't be in the code if a less technical end-user is meant to change it. That's not always the case, though.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (2)
As of 2024-04-26 03:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found