lua-users home
lua-l archive

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


On Tue, Aug 10, 2010 at 9:45 PM, Shawn Fox <shawnkfox@gmail.com> wrote:
> I'd go the opposite way and require a special sigil character for local
> variables.  One thing that seems to be forgotten here is that functions are
> also variables, so if you had to import all your variables in some way,  you
> would also have to import functions as well.  Having different rules for
> functions than regular variables would be a huge mess.  I have no issue with
> global variables, but it would help a great deal if it was easier to
> distinguish between a local and a global by directly looking at their
> usage... perhaps if local variables require the use of a sigil character
> instead of relying on a declaration such as "local"
>
> -- assign 35 to local variable x
> $x = 35
>
> -- assign global x + local x to local y variable
> $y = x + $x
>
> -- assign global y = local y
> y = $y

In my opinion, requiring a sigil for locals makes the situation worse.
At the moment, if you're expecting a local, but make a typo, then you
get a global. With your proposed change, if you make a typo *OR*
forget the sigil, then you get a global. A good editor should be able
to offer different colouring for locals and globals, which gives the
benefit of letting you see what is local without having to decorate
names.