Hacker News new | ask | show | jobs
by ufo 3771 days ago
My question is "why not Lua"? I can see why someone would like to program on a higher level scripting language instead of C and Lua is very much designed from the start to be lean, fast and embeddable. It also inter-operates very easily with C.
2 comments

Because some people disagree that Lua is nice language. Lean-ness is questionable, e.g. BrainFuck is much more "lean", so what? MicroPython can be built to the same binary sizes as a typical Lua build, and yet offer more language features. Lua's embedability has stronghold in games, that's where it usually embedded. Embedded hardware systems are a little different beasts. For them, it's helpful to differentiate e.g. integer from float number (Lua's numbers are floats, it took Lua a long way to acquire a standard module to do bitwise operations, which some people consider just an ugly hack). Also, helpful to differentiate arrays with guaranteed O(1) access from dictionaries (Lua has some mutant container type about whose behavior you can never be sure).
Lua 5.3 released recently and has integers and bitwise operators. Array access is also O(1) as long as you use integer keys and don't have any "holes" in the array.
That's what I mean - recently. With more than 20-year Lua history, finally recently adding bitwise operations to the core language is move welcomed by Lua community. No talking about the fact that Lua authors still can't find right pattern for modules, so in 5.3 they smashed how it was in 5.2 and few previous versions (and that's not the 1st time IIRC), and welcomed community to redo their homework on that part. That only emphasizing the fact that Lua is intended for adhoc embedding, like, you put it in your game, wrap your game's objects. Anything else - well, depends. Changes in 5.3 is a reason why a lot of community is on 5.2. (Well, to be fair, there's Python2/Python3 split too, MicroPython is Py3.)

> Array access is also O(1) as long as you use integer keys and don't have any "holes" in the array.

Right, if you don't have "holes", if you start array indexing from arbitrary number (it would be cool to start indexing from e.g. Pi btw, too bad Lua isn't orthodox enough to do that ;-) ), then it's O(1). Otherwise, it's phase of moon dependent (pun intended).

Look up the Barracuda Application Server. It's commercial but has Lua for dynamic stuff. Runs on reliable microkernels, too. One worth cloning with FOSS.
Lua is on the market for much longer time, and of course it's used in many products. It's my personal belief though that in many places Lua is used, it's used for the lack of alternative. And one of my motives for working on MicroPython is to provide such better alternative. It's the same liberal license, but has that "batteries included" stroke (mind that for MicroPython, there're "coin-sized" batteries included ;-) ), i.e. out of the box it comes with many features with nice standard API, which for Lua must be provided separately (invented and reinvented?). The key of this effort is of course sustainability, and we're making plans how to be around for a long time ;-).

All in all, we're on the same playing field, and welcome independent reviews of MicroPython vs Lua.

Nice explanation. To be clear, I was just citing a use of Lua in embedded rather than promoting it. I don't use it. Since you brought it up... :P

...the advantage was predictability, simplicity, performance, extensability, and tiny memory footprint. The simplicity, predictability, and performance are where Python was a no-go for embedded. So, those are the areas you need to focus on in your implementation to get parity or beat it.

Plus, these traits of Lua are a pre-requisite to high-assurance systems that take things to next level. I've considered a medium or high assurance Python a number of times. Language and implementation were too complex for me to even start. So, I welcome a simpler take on language that others might take to another level.