OmarShehata wrote:kikito wrote:OmarShehata wrote:I was considering attempting to make my own version of Lua with brackets for everything, that would first compile to Lua, removing the brackets and placing indents where appropriate then compiling that Lua file. How hard/practical would that be? Perhaps someone could make a stricter version of Lua.
That sounds a lot like
moonscript (it uses spacing instead of brackets, like Python).
The thing that really peeved me with Python is how annoying the spacings were, so I wouldn't be looking forward to using that. MoonScript does look pretty interesting though.
I didn't want to make a new thread for this so I thought I'd just say it here, but is it just me or is the fact that declaring a variable and assigning a value to a variable are indistinguishable a glaring design flaw?
While I found this:
http://lua-users.org/wiki/DetectingUndefinedVariables It just seems to me like a convoluted way to solve a problem when all it would take is making it so that you need to type "var Varname = value" when declaring a value. So if you try doing:
myX = 2;
And myX was never declared before, it would give you an error. It's simple, and it would prevent a *lot* of headaches.
Now I'm not that experienced in programming to go around pointing design flaws in languages, but would there be *any* disadvantages whatsoever to enforcing proper declaration?
ideally lua would require all variables to be declared, but that would be annoying for many of lua's use cases (where globals don't matter since user code is in its own environment). there was an idea for a semi-required 'global' keyword, which would be optional until it was first used in a scope, at which point all further global declarations in that scope would have to use it. maybe a post-5.2 lua will support it
anyway, the solutions on those page are... a lot more complex than what you really need to detect undefined variables; they're basically searching the generated bytecode for the instructions that deal with global get/sets. sure, they find them (well, ones that aren't being eval'd) before you even run the script, which is nice.
if runtime detection is fine, something like
http://codepad.org/T2YKKF9K will work. this actually shows an advantage of lua NOT taking the local-by-default route: a typo assignment will most likely become a global, which can be caught and indiscriminately banned (globals are evil etc)... in contrast to it becoming a new local, which may be catchable (depending on the language), but should definitely NOT be banned! it'll fail if your typo happens to match an existing global or local but this is less likely and would be hard to catch automatically anyway (how would it determine an intended binding from an unintended one?)