lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Wed, Apr 8, 2015 at 11:48 AM, Sean Conner <sean@conman.org> wrote:
> It was thus said that the Great David Favro once stated:
>>
>> I sometimes superstitiously think that there may be some "advantage" in
>> creating a function that has no external references rather than one which
>> requires separate closures, but I honestly have no idea if this is true.
>
>   I can think of two advantages:
>
>         1) it's easier to serialize such a function, as it relies on no
>            external data.
>         2) it's easier to test such a function as it relies on no external
>            data.

and here are some disadvantages:

1) You force the caller to maintain references to data that is
ancillary or not useful.
2) The function parameters explode and any new data dependency may
require updating all calls to the function.
3) Data dependencies expressed using control structures (e.g. the loop
variable in a numeric for loop) require wrapping function references
with its dependencies. The Python analogue for this is
functools.partial (and they actually need this because Python does not
know how to do scoping/bindings).

-- 
Patrick Donnelly