Using a lua for great power and good
published on Friday, February 3, 2017
I love lua for so many reasons: For one, it aims to be different. And then, it helps us stay in shape by making simple tasks more challenging and keeping us attentive. This is not just yet another language, in lua we have (no particular order):
- 1-based indexing!
- a powerful one-for-all dictionary+array+object type that abolishes a messy datatype hell like the one in python where these things are in separate (utterly underpowered) container classes.
- Yet another name for NULL.
- Yet another comment syntax: --
- Sieving of lazy developers who would like to make use of things like an extensive standard library. I really hate those.
- Relative imports to keep us on our toes.
- Making all variables global by default.
- The interactive interpreter forcing us to actually use globals, so we can't simply copy-paste if we were impertinent enough to use locals in our actual code. This is good to keep us wary! Way too many coding bugs are introduced due to copy-paste in other languages!
- Great error-safety!
- Variadic functions and argument unpacking!
It's quick, it's clean, and it's pure.
Go lua!
Yet another name for NULL
God spoke: Every language shalt have their own slightly different NULL thingy.
And so it was:
- C: NULL
- C++: nullptr
- perl: undef
- python: None
- javascript: undefined / null
- lua: nil
Great error-safety!
Tired of converting strings to numbers?
Tired of remembering the correct number of function arguments? Lua has your back:
Tired of getting exceptions when accessing non-existent entries? No more worries:
Tired of keeping track of variable names? Need automatic spelling correction? Lua does it for you (but for now it works only for variables refering to nil values):
To be fair
Most of the above applause is not specific to lua. In many regards, lua is very similar to javascript and perl.
And I do get, why certain things are the way they are. Lua is supposed to be a simple, lightweight and portable scripting language that is easy to embed in arbitrary applications.
And there are neat things about the language too: In fact, I (kind of) do enjoy the simplicity and differentness of the prototype based object orientation.
For a more comprehensive list, see Lua Gotchas.