15 ms·
If Lua did the decent thing and insisted that you declare every variable first, it wouldn't have this stupid problem. Squirrel should probably do it, too. Pytho
by to3m 10y ago
If Lua did the decent thing and insisted that you declare every variable first, it wouldn't have this stupid problem. Squirrel should probably do it, too. Python certainly should! (Even Javascript, misguided as it is in so many respects, has strict mode!)
This sort of static checking massively increases the amount of code you can look after without going insane. Add static types too, and you're even better off.
(Last time I used Lua, I modified it so that all variables had to be introduced before their first use, either using `local', or a new `global' keyword. More static checks, and no more accidental globals.)
- technomancy 10y agoI would love to have something like Dialyzer to do static checks for Lua, but luacheck is a lot better than nothing: https://github.com/mpeterv/luacheck https://github.com/mpeterv/luacheck
- bakery2k 10y agoInteresting that hajile and you both dislike global-by-default, but your proposed alternatives are essentially opposites. hajile would prefer local-by-default and fewer declarations, and you would prefer nothing-by-default and more declarations...
- looki 10y agoLua's metatables are very powerful, and there's actually a tiny implementation of "strict mode" for Lua [1]. I do agree that static checks like these would help the language for serious applications. I recently got back into Lua a bit and the first error I made was omitting "local". [1]: http://metalua.luaforge.net/src/lib/strict.lua.html http://metalua.luaforge.net/src/lib/strict.lua.html