- User Since
- Jan 1 2014, 11:45 PM (438 w, 5 h)
May 10 2016
Personally I would prefer either Python, the JVM (for Clojure and Scala) or the .NET framework (for F#) as the scripting implementation of choice.
That being said, even with its 1-based array silliness, complete lack of bitwise operators, and somewhat verbose syntax, I would still happily take Lua over what we have now. We would have proper closures, data types beyond numerically-indexed lists, sensible scoping rules, and a non-infix syntax for invoking functions.
SQF has a number of flaws:
- It is verbose, in a way that hurts readability.
Consider the readability of:
_a set [_i, (_b select _j) call someFunc] [_a call funcB, [_b, _c] call funcC] call funcA
Compared to the readability of:
_a[_i] = someFunc(_b[_j]) funcA(funcB(_a), funcC(_b, _c))
- Since arguments to functions are simply passed as arrays (or, more accurately, functions take a single argument that is usually an array), it is up to the programmer to manually validate the presence of each argument, to provide default values for missing arguments (when appropriate), and to produce errors when arguments are not present. This leads to most functions requiring quite a bit of boilerplate.
In order to determine what the arguments to a function are, a programmer is forced to either examine the body of the function, or to read documentation provided for the function (assuming there *is* documentation, and that it is accurate). In the majority of languages, a quick look at the function declaration will suffice.
I don't feel like Lua does a good job here either, but it does a better job than SQF. If nothing else, it is at least possible to customize Lua's behaviour through the use of metatables and closures.
- SQF provides no way to create user-defined classes. Outside of pure C, I can't remember the last time I used a programming language in which this was the case. Lua provides this functionality through the use of metatables, and it works quite well.
- SQF provides anonymous functions, but fails to provide closures, which is something that nearly all modern scripting languages provide. If a function refers to variables located outside of its body, but inside the lexical scope in which the function was created, then that function will fail to work correctly when executed in an environment in which those variables have passed out of scope.
- Creating a sensibly scoped local variable requires both a declaration ('private'), and the use of a sigil ('_'). This is a minor annoyance, but there is really no reason to require both. The current behaviour with just the sigil is useless, and is a recipe for subtle bugs.