Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

(MeowChow) Re: DBIx::PearDSN

by MeowChow (Vicar)
on Apr 08, 2002 at 10:29 UTC ( #157406=note: print w/ replies, xml ) Need Help??


in reply to DBIx::PearDSN

It has the look of good code (I believe one can "sense" this from just a casual glance, based on the shape, aesthetics, and recognizable idioms, but that's a topic for another node). You did, however, hit on one of my pet peeves, which is to place a nontrivial, static data structure definition in the body of a subroutine (my %map in sub dsi_dsn). I would turn %map into a file-scoped lexical, or create a new enclosing scope to contain it outside of dsi_dsn.

   MeowChow                                   
               s aamecha.s a..a\u$&owag.print


Comment on (MeowChow) Re: DBIx::PearDSN
Re: (MeowChow) Re: DBIx::PearDSN
by Juerd (Abbot) on Apr 08, 2002 at 15:23 UTC

    You did, however, hit on one of my pet peeves, which is to place a nontrivial, static data structure definition in the body of a subroutine (my %map in sub dsi_dsn). I would turn %map into a file-scoped lexical, or create a new enclosing scope to contain it outside of dsi_dsn.

    I always try to scope such mapping hashes to the subs that need them. Only dsi_dsn needs the %map, so why make it available to other subs? There's also no point in having it global. When configurability is a goal, I make file-scoped lexicals and put those just after the globals, but this is merely a translation map, not something that should be configurable or available to other subs.

    It has the look of good code.

    Ouch. Most has been directly translated from PEAR's DB.php file (not because I like the code, but because I want to parse it in a similar manner for greater compatibility) - but I replaced most of the pos() and substr() ugliness by splits :)

    U28geW91IGNhbiBhbGwgcm90MTMgY
    W5kIHBhY2soKS4gQnV0IGRvIHlvdS
    ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
    geW91IHNlZSBpdD8gIC0tIEp1ZXJk
    

      I always try to scope such mapping hashes to the subs that need them. Only dsi_dsn needs the %map, so why make it available to other subs? There's also no point in having it global.
      This is exactly why I suggested the alternative of creating a new enclosing scope, as in:
      { my %map = (...); sub dbs_dsn { ... } }
      Even for a sub that isn't called very often, why do the work every time and throw it away, when you can do it just once?
         MeowChow                                   
                     s aamecha.s a..a\u$&owag.print

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (9)
As of 2014-12-25 11:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (160 votes), past polls