[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: local scope once again
- From: "Jerome Vuarand" <jerome.vuarand@...>
- Date: Tue, 12 Dec 2006 15:47:52 -0500
Leo Razoumov wrote:
> This behaviour means that all earlier local declarations of
> the variable become completely shadowed by later local
> declarations at the same scope. I am afraid it makes code
> less readable.
>
> local x="first declaration"
> local x="second declaration" -- the same scope
>
> The first line is now completely irrelevant, because its
> version of 'x' is not accessible by regular Lua means (except
> for debug library).
>
> Is there any particular reason to design Lua local scope
> rules this way??
I can't explain the initial choice for such a decision, but I personally
think this is a good thing. This gives a lot of flexibility to the
programmer, with the only drawback being some confusion for programmers
too used to C-like scopes. You can do what you want to do with the
syntax, but the syntax that you expected prevents me from doing some
things I want to do (like having multiple variables with the same name
in the same block). So that solution is the best since it allows all
features, at the cost of *some* readability for *some* readers not used
to Lua syntax (I think that in any experienced Lua programmer mind, the
local keyword is instantly spotted as a variable creation).