in reply to Re: RFC: Practical closure example: Spreadsheet writer
in thread RFC: Practical closure example: Spreadsheet writer

Good point, and actually, while I was typing the node, I kept on writing $writer->write($value) rather than $writer->('write',$value). This made me ask myself the same question: why not OO?

And really, no reason - I would say (and I stand under correction) that really it is just a question of scale. A small job may be more easily (less verbosely) achieved with closures, while OO gives you more room to expand. Also, I would guess that using references to anonymous subs avoids most of the penalty hit of using OO (micro-optimization anyone?).

So I would say that it is probably a different technique to achieve the same thing.

I'd be interested in differing opinions though

Clint

Replies are listed 'Best First'.
Re^3: RFC: Practical closure example: Spreadsheet writer
by chromatic (Archbishop) on Aug 05, 2007 at 00:41 UTC
    Also, I would guess that using references to anonymous subs avoids most of the penalty hit of using OO (micro-optimization anyone?).

    There may be a tiny benefit from avoiding potential dispatch lookup, but the benefit is fairly small. If anything, you're more likely to see memory savings (in the order of a few kilobytes). (Closures save the same CV but use different lexpads. If you reuse the closure, all references share the CV rather than constructing their own.)