Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I tend to believe that code golf and maintainablity are often at odds.

As do I. In fact, I would go a bit further and say that code golf and maintainablity are almost always at odds. Clarity is immensely important for maintainable code and concision or terseness is a very important element of clarity, along with many others. (Of course, terseness is the only consideration in 'golfed' code!)

So List::MoreUtils could be used to express the code this way:
help() unless all { $_ } $server, $user, $database, ...
or without List::MoreUtils:
help() unless $server && $user && $database ..
but I still think that the original code makes it very clear what is going on and provides future flexibility.  
[emphasis added]

The problem I see with either a solution like
    help() unless $server && $user && $database ..
or like the OPed code is that it is inflexible: if it becomes necessary to validate for a different condition or set of conditions, you're stuck making a change in who-knows-how-many locations in a file. The advantage of a test like the one in
    help() unless all { $_ } $server, $user, $database, ...
is that it is defined in one place: DRYSM.
(BTW: Both of these solutions differ from the OPed code in that they reject a variable with a  '0' string or numeric value of 0.)

In fact, if it was the case or if there was any likelihood that the group of variables involved in the OPed code or the condition against which they were being tested would occur again elsewhere in the code, I would, in the interests of maintainability, be strongly tempted to go for whole-hog generalization (even though some might criticize it as premature) with something like this:

use List::MoreUtils qw(any); ... my ($server, $user, $database, $password, ... ); ... sub IMPORTANT_STUFF () { return $server, $user, $database, $password, +... ; } sub importantCriterionForImportantStuff () { return $_ ne ''; } ... help() unless all { importantCriterionForImportantStuff } IMPORTANT_ST +UFF;

In reply to Re^4: checking values of variables by AnomalousMonk
in thread checking values of variables by fionbarr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-24 13:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found