5 ms·
JS has improved a lot over the years but I am not sure I would want it as the default scripting language for applications. JS is really only useful because it's
by obpe 3y ago
JS has improved a lot over the years but I am not sure I would want it as the default scripting language for applications. JS is really only useful because it's the language you access the browser's API with. If you are creating a different kind of application and therefore don't need the DOM or other browser things then why JS at all? Having worked with Lua for some game mods, it seems like a better choice for an integrated language. Maybe a Rust inspired language would make a better fit for a modern DSL... insert XKCD comic about standards proliferation.
- giraffe_lady 3y agoLua is a better integrated language simply because that path is intended by its developers and directly documented, and its runtime is designed to be easy to couple to C. But nothing about its semantics make it better for that task than javascript. They are extremely similar except lua doesn't have stuff you would almost always want like basic string manipulation tools, regex, any array operations more sophisticated than loop. You can argue you don't need those things, but their lack isn't a feature either. If you're not coupling to C's memory model or if for some reason someone has already done the work of building and debugging the integration... you gain nothing by using lua over js. I've done professional work in lua and it's highly overrated imo. For integrated languages Tcl or janet is a better choice, unless your use case is extremely extremely simple and then forth is a better choice. The only time I would choose lua is if I'm integrating with C, the integration language tasks are very simple but also requires coroutines. Lua's coroutines are genuinely good.
- paulddraper 3y agoBecause Worse is Better [1] Lua is technically superior, but JavaScript is practically superior due to its ubiquitous platform the web browser. Similar but different to C "beating" Lisp. [1] https://en.wikipedia.org/wiki/Worse_is_better https://en.wikipedia.org/wiki/Worse_is_better
- tmountain 3y agoI strongly disagree. Lua somehow maintains a positive reputation, but it’s extremely quirky and weird in many ways. It has some Perl-esque rough edges (#array for length), and some “let’s be different” design decisions that are counterintuitive and unnecessary (arrays starting at the 1 index instead of 0). JavaScript as it is today is a vastly more ergonomic and fluid experience, and I am saying this as someone that has written tons of both. The embedding experience with Lua is likely much more form fit than JavaScript (sandboxing, etc). I’m strictly speaking about syntax and language features.
- suavesito 3y agoI don't want to start a 0-index war, but there is a great argument I read once and wave to share. Indexing can be tough as two different things, selecting or offsetting. When selecting you start from the first (1) option. When offsetting you move zero (0) from the first option. 0-index arrays express offsets, 1-index arrays express index selection. In C (and family) arrays start at zero because they offset, `a[i]` literally means `* (a+i)` (you actually can write `i[a]`, it will work and be valid). For other language selecting 1 base indexing is not a weird option, I'd argue.
- paulddraper 3y agoIf you ever need an ally for 1-indexed, you can point people to PostgreSQL.
- lenkite 3y agoJS is also ergonomically superior compared to Lua.
- slmjkdbtl 3y agoI love Lua but tbh I accept JS as the default scripting language, simply because it's ubiquitous, most runtimes are faster than or on par with Lua, and not harder to embed than Lua with stuff like quickjs. Also I don't think from language design perspective there's fundamental difference beyond syntax, metatable is pretty similar to prototype chain, JS has much more stuff you can argue it's bloated compare to Lua but you don't really pay for what you don't use.
- rektide 3y agoDoes Lua have the ability to launch very low cost sandboxed instances? With Deno I know I can quickly spawn lots of isolated instances at very low overhead. If I really want to push it far, there's tools for loading frozen snapshots that have lots of code loaded. I've never seen similar from Lua & I'm not sure it exists. Seems like a huge advantage.
- slmjkdbtl 3y agoCreating a new lua context is pretty cheap, but I don't know how it compares to Deno / v8. It should be much lighter weight, but not sure if Deno / v8 does some special thing to speed up the use case you talked about.
- rektide 3y agoThe submission itself talks about creating & loading snapshots, which is sort of a Checkpoint Restore In Userspace (CRIU), allowing one to create a new context with a lot of existing libraries already loaded very very quickly.
- lenkite 3y ago>With Deno I know I can quickly spawn lots of isolated instances at very low overhead. Err..new to Deno - how does one do this ?
- skybrian 3y agoI think you might be underestimating browser compatibility. There are a lot of browser API's. They're portable, designed with security in mind (at least somewhat), usually well documented, reasonably easy to understand, and people already know them. So, even if it's not a browser, you may prefer JavaScript so you don't reinvent the relevant API's and there's less to learn. Deno itself is a good example of this.
- toastercat 3y agoSpeaking of Lua, does anyone know of a Lua implementation with filesystem access that is smaller than (or as small as) QuickJS (~800KB)?
- jabbequbs 3y agoLast time I compiled standard Lua I think it was only 300-400KB. It has all the cross platform file manipulation capabilities that C does. I was using TCC though, and it does seem to generate small (unoptimized) binaries.
- eropple 3y ago> If you are creating a different kind of application and therefore don't need the DOM or other browser things then why JS at all? Because I like TypeScript and don't like Lua. JavaScript, I don't like. It's in the same bucket to me as Python, Ruby, and Lua - things I might have to use sometimes but I'm holding my nose. But TypeScript? I like TypeScript and want to use it more.