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

Re: File::Find considered hard?

by jonadab (Parson)
on Mar 15, 2004 at 17:57 UTC ( [id://336764]=note: print w/replies, xml ) Need Help??


in reply to Re: File::Find considered hard?
in thread File::Find considered hard?

Maybe they are complaining about the fact that File::Find does most of its communication through global variables.

Does it really use global variables (err, variables in the main package; I assume it doesn't use the truly global punctuation variables, other than for their intended uses), or does it use package variables in its own package? The former would be very messy; the latter isn't nearly so bad. It wouldn't make sense for an OO module (like DBI), but for a module with a function interface it seems reasonable enough to me.

I suspect the OP may be right, and that they may be complaining about passing anonymous functions around. Anybody with a solid familiarity with Perl (or any other language that supports the functional paradigm) will be reasonably comfortable with this, but a newbie coming in from another language (especially a procedural or OO language) may have trouble with it at first. This is not surprising; it's a different paradigm than the ones they're familiar with. They'll also have trouble at first with the list operators, and if you show them closures you'll want to have a camera handy to take a snapshot of the funny looks on their faces. This will pass with time, as they learn the different paradigms that Perl supports and why each is useful. (If they like OO, it may help to tell them that lexical closures are one way to achieve encapsulation. That may spark their interest enough to get them to learn something, instead of turning away in disgust.)


;$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$;[-1]->();print

Replies are listed 'Best First'.
Re: Re: File::Find considered hard?
by perrin (Chancellor) on Mar 15, 2004 at 18:43 UTC
    Does it really use global variables (err, variables in the main package; I assume it doesn't use the truly global punctuation variables, other than for their intended uses), or does it use package variables in its own package?

    Call them package variables if you want to -- they still meet the definition of "global variable" in most languages, i.e. they are read/write accessible by any code from anywhere. I'm not going to go into a whole explanation of why using globals to pass information, regardless of the use of OO or not, is a really bad design, because many other people have written about it at length. It's not as if these globals are being used internally only -- they are part of the public API for File::Find.

      One can also make the same claim about $DBI::errstr ... globals may be "Bad Things"(tm), but it's not as if they're unusable.

      ------
      We are the carpenters and bricklayers of the Information Age.

      Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

        Of course $DBI::errstr comes with exactly the same caveats. The fact that File::Find::find() is not reentrant because of its use of package variables f.ex can be very annoying, and the same goes for $DBI::errstr in modular code. Just like $_ clobbering issues and what other commonly encountered cases of being bit in the rear by use of package variables there are.

        Makeshifts last the longest.

Log In?
Username:
Password:

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

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

    No recent polls found