3 ms·
If you are arguing in favor of "local by default", there are strong arguments against this: http://lua-users.org/wiki/LocalByDefault http://lua-users.org/wiki/L
by haberman 13y ago
If you are arguing in favor of "local by default", there are strong arguments against this: http://lua-users.org/wiki/LocalByDefault http://lua-users.org/wiki/LocalByDefault
- icambron 13y agoThe parent isn't arguing for local by default, just against global by default. Insomuch as you buy into the arguments in that link, the answer is to do neither (i.e. you must always use "var"). Most of those arguments are actually even more damning to global by default.
- catwell 13y agoI tend to agree with you, but here is the reasoning behind how Lua works: - local by default weakens what you can do with the scope; - we want something by default because the language is used for things like configuration files. The 2nd point means this must be valid: param_1 = "foo" param_2 = "bar" I would personally be happy to sacrifice that feature and add an explicit "global" keyword but not everybody agrees, and it would break a lot of code. What we do instead is use two kinds of tools: static global detectors and strictures (like in Perl). Similar tools are integrated in IDEs as well. With these tools, I have never had an issue with scoping in code I have written. But it takes a little time to get used to it.
- icambron 13y ago> I would personally be happy to sacrifice that feature and add an explicit "global" keyword but not everybody agrees, and it would break a lot of code. For sure. That ship has probably sailed. And, like you said, linters alleviate a lot of that pain. But that's a separate question from, "is this a good language feature?"
- Grue3 13y agoThese arguments don't look particularly strong.
- dukerutledge 13y agoAnything by default is idiotic. Lexical scoping works when variables are declared. Lexical scoping becomes a burden when deceleration is not required and variables fall back to some default scope.