Talk:Lua Differences
From GMod Wiki
The Pro/Con list for C-style syntax is severely misguided.
Coders more proficient with C++, C#, PHP etc might prefer it.
- This is an extremly remote possiblity. As a long time programmer in a wide
- variety of languages, I would never prefer to learn a non-standard
- version of a language, unless there was a substantial gain to be had.
Shorter, more compact syntax.
- Only for 'not', 'and', and '--[[' (--, or, ~= are the same),
- and only by a tiny amount.
-
- The question is, why this a Pro?
-
- 1. Does it make the code more readable?
-
- a. To a new programmer, unfamiliar with C or Lua? No. It's going to
- make it harder.
-
- b. To a seasoned Lua programmer, unfamiliar with C? No. It's going
- to make it harder.
-
- c. To a seasoned C programmer, unfamiliar with Lua? Debatable, but
- at the cost of slowing his recognition speed of standard Lua code and
- thus making a wide array of Lua resources (books, web tutorials,
- source code, etc.) less valuable.
-
- 2. Does it save keystrokes?
-
- Yes, but by trading non-chorded keystrokes close to home row (and,
- not) for chorded keystrokes further from home row (&&, !) so
- in terms of speed and hand strain, it's a net loss.
-
- So ultimately the code is harder to type and read. This is a Con.
Good practice for people that will want to eventually advance to C++
- First, this represents an infintesimal percentage of the mod's
- audience.
-
- More importantly, it's demonstrably false. It would only be true if
- the SEMANTICS of the Lua constructs were equivalent to those in C, but
- they aren't. For example (using the bastardized syntax):
-
- Given x=0:
- Lua: !x == false
- C: !x == 1
-
- Given a=0, b=2, c=3:
- Lua: a && b || c == 2
- C: a && b || c == 1
-
- Given a block comment --[[ <lines> --]] or /* <lines> */, you can uncomment
- the entire block in Lua by putting a single '-' in front of the opener. This
- does not work in C.
- Given x=0:
-
- By changing these Lua constructs to have C syntax but not C semantics,
- you're making it bad practice for people who will eventually move on
- to C.
-
- This is a Con.
I've watched the development of Lua since 1.0 and this is one of the most egregious examples of a "because I can" modification to Lua I've ever seen. I can't imagine why anyone would think it's a good idea. Moreover, given the stated "Pros" mentioned for C-style (even if they were valid), it's even harder to imagine why using the new syntax would be recommended.
Using standard Lua is easier to write, easier to read, helps distinguish the semantic difference between these constructs in Lua vs C-like languages, makes it compatible with standard editors and Lua interpreters, makes it easier to share code and communicate with other users of Lua, and easier to make use of a wide array of Lua online resources which are all written for standard Lua.
There is no compelling reason to use the hacked syntax, and in fact most of the Pros listed are actually Cons.