[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Unnecessary New Closures
- From: David Manura <dm.lua@...>
- Date: Sat, 8 Sep 2007 00:09:04 +0000 (UTC)
Javier Guerra Giraldez <javier at guerrag.com> writes:
> just a bit nicer:
>
> do
> local function comparison (a,b)
> -- whatever
> end
>
> function mysort ()
> table sort (sometable, comparison)
> end
> end
I tend to disagree with this practice. Such minimization of scope leads to
something that doesn't even look like a function:
local mysort; do
local function comparison (a,b)
-- whatever
end
function mysort ()
table.sort (sometable, comparison)
end
end
when it just can be written as
local function helper_compare(a,b)
-- whatever
end
local function mysort ()
table.sort (sometable, helper_compare)
end
or
local helper_compare
local function mysort ()
helper_compare = helper_compare or function(a,b)
-- whatever
end
table.sort (sometable, helper_compare)
end
You may follow the convention that anything prefixed by helper_ should only be
used by the thing following it (a type of apps hungarian notation).