<const> everywhere
"'Sewbacca' via lua-l" <[email protected]>
| Newsgroups | gmane.comp.lang.lua.general |
|---|---|
| Message-ID | <[email protected]> |
AFAIK <const> had been already introduced in 5.4. I would much rather prefer const as a stand alone keyword that would have the same effect as "local <const>" However making "local" const per default would break backwards compatibility in a huge way. Writing code that targets all Lua versions would move from hard to impossible (and because I am mainly writing code that targets all Lua versions take my paragraph above with a grain of salt). I have the same argument against making "local" default. In addition to that argument, making local the default does hide the declaration location in an unobvious way take this function for example: local function foo() bar = 10 end foo() print(bar) What should be printed now? 10? nil? If you ask any Lua version you'll get 10. If local is the default then nil should be printed. Let's say above "foo()" "local bar = 20" would have been declared. Should 10 or 20 be printed? All Lua versions agree on 10, a sane default implementation would agree. But from the above code example it is no longer obvious in that hypothetical implementation. Let's say somewhere else (either in this file or another) "_G.bar = 20" would had been declared Now it gets really complicated. Again every current Lua version agrees that 10 should be printed. In this hypothetical local default example however it would depend on if the parser sees this global declaration or if it doesn't. All these questions suggest to me that a declaration is fundamentally a different action than an initialization. Having syntactic sugar to do both in one go is nice. Hiding that something is being assigned vs. declared however seems dangerous to me. ~ Sewbacca -- You received this message because you are subscribed to the Google Groups "lua-l" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/lua-l/ac05c27c-6872-4b76-b0f0-27deb3818d2e%40kolabnow.com.