Hacker News new | ask | show | jobs
by yiransheng 3003 days ago
The list of niceties of lua from the article:

> First class functions and closures

> A versatile data structure: the table

> Vararg expressions

> Lexical scoping

> Iterators

> Coroutines (see below)

Well, looking at modern day js:

* First class functions and closures, check

* the table: a combination of `Array`, `Map` and `Map<Number, T>` can prettify much cover typical usecases of lua tables, so js is close in this regard

* Vararg expressions, check

* Lexical scoping, check

* Iterators, check

* Coroutines, with libraries and abstractions on top of generator functions

In addition, in js land, other paradigms of concurrency exists, such as CSP (goroutines), FRP (Rxjs and co). Of course, these can be implemented in Lua as well, but the libraries may not quite as battle-tested.

The author also mentions a sane coercion system; this still true, but ever since "use strict", unexpected coercions can mostly be avoided in js.

On the other hand, js has:

1. Typescript and static typing (a bit unfair to consider this js, but ts gets access to a large portion of high quality npm packages), flow is also great

2. Multiple mature echosystems of UI frameworks (React) - for instance if you need a date picker or an autocompleter, it's just `yarn add` away; I doubt enough such libraries exist for browser side lua yet

3. Tooling support - webpack, prettier, postcss and so on

I like lua, but I feel it does not offer much in addition to what modern js already provides. Of course bring more languages to the browser is always a good thing, on the other hand I do feel this is a tough sell to the larger community.

2 comments

I think you misunderstand the aim of the article. It’s not a case and point against js but for Lua in the browser. When I list positive points of Lua, I’m not implying they don’t exist in JS.
Javascript generators make for painful coroutines, because a function called by the generator can't yield all the way out.
Yield * fn()?
You can use that sometimes, but it really complicates return values in a way Lua just doesn't have to deal with.