in reply to Re^2: Iterator as a Class or Object Method
in thread Iterator as a Class or Object Method

I'm hearing unsupported objections to passing coderefs to objects.

I will concede that this is not for the feint-of-heart - newbies find it difficult to fathom the concept, so, writers shouls probably provide an alternative interface for common goodies like File::Find.

The larger issue, as I see it, is that coderefs provide an elegant solution such as this one. Plenty of modules use filters as properties - either as regexen or coderefs.

To simplify caller understanding, I usually provide an alternative of pre-specifying the code-ref as an object property, then calling a method that will invoke the coderef.

Beyond personal preferences, and perceived complexity, is there a reason NOT to use coderefs ?

     "Man cannot live by bread alone...
         He'd better have some goat cheese and wine to go with it!"

  • Comment on Re^3: Iterator as a Class or Object Method

Replies are listed 'Best First'.
Re^4: Iterator as a Class or Object Method
by BUU (Prior) on Oct 03, 2005 at 21:26 UTC
      That was an excellent descussion by the gods (BUU++).

      Point conceded.

           "Man cannot live by bread alone...
               He'd better have some goat cheese and wine to go with it!"

      Re: Are you looking at XML processing the right way? (merge) says it far better than I could.

      That's tye (quite correctly) saying that callbacks are less flexible than iterators. That's not an argument for throwing the former away. C style for loops are more flexible that Perl style foreach loops - but I wouldn't want to do without the latter :-)

      If your iterating over everything in a Feed object 30 times in your code why not abstract that loop out?

      Iterators and callbacks are both useful interfaces. I wouldn't want to do without either.