by meric · 10y ago · 0 comments
Good questions.
- variable name typos (undeclared vars are nil),
There's a linter to catch undeclared variables. https://github.com/mpeterv/luacheck There's also some runtime checking techniques you can use. http://www.lua.org/pil/14.2.html
- accidentally confusing array-style tables and hash-style tables (or vice versa),
I've had that happen about as often as confusing Python dictionaries returned by different types of functions. (Which is - not often enough for me to remember the last time that happened)
- tables with "holes" (nils) in them,
When I'm building a vector and I want holes, I use false to fill the holes.
- multiple assignment with wrong number of vals or vars (mismatch silently ignored),
For me, when I'm thinking about multiple assignment to function returns, it does mean having to read documentation for a library function more carefully than if I was reading the same for another language. If it's as simple as "local a, b, c = 1, 2, 3", then it's no issue.
- variables are global by default.
If I'm using linting, when I can't have global variables implicitly, then it's like C or Java where I must declared all my variables and by default they are local to the scope.
Otherwise it's just like javascript where it's best practice to always declare variables using "var".