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

Please, for the love of god, File::Find is bad enough, we don't need any more modules using this hideous interface.
  • Comment on Re^2: Iterator as a Class or Object Method

Replies are listed 'Best First'.
Re^3: Iterator as a Class or Object Method
by adrianh (Chancellor) on Oct 03, 2005 at 13:39 UTC
    Please, for the love of god, File::Find is bad enough, we don't need any more modules using this hideous interface.

    I agree that Find::File is foul - but that's more because of bad design rather than something bad with callback based APIs in general. If it passed named arguments rather than using evil globals it would be a fair bit nicer to use.

Re^3: Iterator as a Class or Object Method
by NetWallah (Canon) on Oct 03, 2005 at 19:59 UTC
    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!"

        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.