Integrate Rhino Javascript Engine
smj-edison opened this issue Β· 65 comments
Lua can be quite limiting sometimes, and it is not as well known or founded as javascript. Would it be possible to integrade the Rhino Javascript Engine?
Rhino has been superseded by Nashorn, but either way I think it would be a lot of work for little benefit, and completely break compatibility with everything.
There is a bit of me which would quite like to see an API for adding alternative runtimes. However, having non-Lua-based runtimes does introduce the whole issue of you effectively having an entirely separate ecosystem.
That being said, I'm not sure how much it'd be worth it - OC has support for multiple architectures and, while there are some alternative ones, almost everyone sticks to the base Lua one (though they do allow multiple Lua versions which is fancy).
Also, JavaScript is an absolutely terrible language.
Just do a quick Google and you'll find tonnes of reasons why JS sucks, from it's terrible type system and aggressive type coercion, all the way to its reliance on global variables and just generally terrible scoping β not to mention all the absurd 'bugs' in the SDL which cause unexpected behaviour!
Yes but javascript generally has more actual problems than most languages which are just user error or other reasons. Besides, javascript lets you do a lot of stupid things that no language should let you do, primarily stemming from its aggressive type coercion. No language should have commutative operations that change output depending on the order you use them in (for example "==").
So then it would be best to have another mod that adds this functionality? Would you add a API or would it be a fork of this?
A few reasons why JS is better than Lua though:
- Lua is so strict, which makes it hard to debug...
- Lua has an
if then end
syntax, which makes it super unreadable... but not with curly brackets - Lack of incremental, decremental operators, the "!=" condition comparison and "+=", "-=", "*=" and "/=" operators is a pain in the ass! Lua wants
var=var+1
, where JS just can usevar++
orvar += 1
nil
instead ofnull
- just why?- Using
..
instead of+
for concatenation is super confusing
Having JS in CC would definitely deserve a thumbs up.
- I don't see how being strict makes it hard to debug, if anything it makes it easier since you know exactly what's going wrong and where rather than trying to track down where a string is silently being converted to a number...
if then end
is the exact same asif () {}
, just using different syntax. If it's that hard to read, you're probably misusing indentation or something.- I agree that these operators would be useful, but it's not a huge deal and definitely not worth changing the entire mod to use a different language
- Again, it's a very minor syntax difference that doesn't really change much. If you want to get pedantic -
null
andundefined
, just why? - It's not that confusing and makes the behavior of the program more predictable with regards to types (e.g.
a .. b
makes it clear that the operands are strings,a + b
makes it clear that they're numbers)
Also, there are options like TypescriptToLua if you're really that concerned about syntax
It happens because you use "==" and "!=" instead of "===" and "!==", which doesn't juggle the types
lack of
*=
etc is a good thing since mutation is a code smell
@zardyh what? Where'd you get that idea? In what world is something like, for example, sum = sum + number
a bad thing? sum += number
just makes it more convenient...
Debating whether Javascript or Lua is the better language is kinda besides the point. It seems like the bigger issues are technical limitations and whether this change would even be within the scope of the project.
Personally, from a player standpoint I'd much rather see just a single language in computercraft. Much easier to handle both teaching new players and script compatibility when you have just one language to deal with.
@KnightMiner Besides - there's already a community around Lua computers in Minecraft. There are some JS architectures for OpenComputers, but I think ComputerCraft should stay Lua, with the simple, yet powerful API it already possesses.
Having a JS to lua conversation of some kind could be useful for a while to measure interest. no one wants to put all that effort in nto making a mod to find that no one uses it.
For this main project (and CC:Tweaked) - i dont see the point to change the language. BUT a CC fork with ECMAScript instead of LUA would be kinda interesting (i'd totally use it).
We just need someone willing to do it.
As i said before, i would use (since i have interest in get more experience with JS since i use a lot it), but i think would be better to have yet another fork than changing the core mod or CC:T
@lordvico Or better yet allow the creation of different architectures like OC has.
@JasonTheKitten The appeal of CC lies somewhat within its simplicity. OC is a more realistic, low-level version of an in-game computer. CC is more high-level, and you don't have to be as concerned with things like in-game computer hardware.
It might by possible to write a js-to-lua compiler. The syntax of the two languages is somewhat close, though type coercing may be a pain to implement. Not sure if parsers in lua exist.
@JasonTheKitten Oh no.
Just had a quick look around, this might work for those who want js in cc https://github.com/wizzard0/js2lua
Just a reminder to everyone to read the whole thread before replying! A lot of the points raised in the last few days were mentioned when this issue was first created.
We can't just work and code in the language that we want or love, it's a fact:
- Time is a free, spendable and non reusable resource;
- CC has a defined scope, and the language used to bring it's features to life are Lua and Java;
- There are lots of lines of code already written in Lua shared in CC Forum, it means that, if someone wants to increase the scope and add support to a new language, Lua woudn't be replaced, so someone with time and will would have to do some magic with lots of lines of code, adding the new support, without break anything (I think that this is one of the reasons to CC:T still use Lua)
- JS today is very powerfull and widely used, but I repeat, like the creators of Lua said: "JS is Lua made in the wrong way";
-
Yes
-
Sure
-
I believe you can add support for other languages/"architectures" without breaking existing compatibility, but I do agree that's out of scope for CC, if you want that then try OC
-
JS has its purpose, Lua has its purpose too. Here's some TS:
While I do believe that JS cannot replace Lua, and that Lua is better for a lot of things, Node.js is still amazing.
I don't think JS for CC would be worth begging for though.
All in all, I believe CC should stay the way it is for the sake of simplicity and staying true to its original purpose.
Lua is also known as Javascript done the right way (words of one of it's own creator), the minimalist nature of the language has the powerful that attracted many game dev companies to use Lua in some parts of their projects. Javascript is a very nice language, but concerns must be distinct here, the ComputerCraft project is a project built in Lua and Java, if you add a lot of features in a same mod or component, you'll add complexity, and it's a basic knowledge in software development that complexity raises the effort and time to teams add new things without break others.
Just to add to everyone else's input, ComputerCraft's whole 'thing' is to add easy-to-use Lua computers to Minecraft. If you'd like JavaScript computers, there are two mods for OpenComputers that add JavaScript support.
@SquidDev isn't 1.13 going to break a lot of things? Why not break more?
@Lupus590 because JS is a bad language and Nashorn/Rhino are both deprecated in favor of GraalVM, which is not mature enough and won't run MC anyways.
isn't 1.13 going to break a lot of things? Why not break more?
The issue is twofold:
- Several mods target order versions of CC's API (say, 1.79 or 1.75). I'd rather avoid forcing them to update until CC's status is more clear.
- Similarly, CC:T isn't official, so I don't want to force people to have special code targeting it. While it'll probably be the only fork to update, I don't want to make any assumptions.
I've had a couple of ideas on how to make it backwards compatible (yay to default interface methods), but will need to experiment.
@apemanzilla I don't believe Lupus or my comments refer to using JS, rather other refactoring. As far as Nashorn being deprecated I don't think that's the end of the world - obviously later JS features are not present, but it's still functional.
I would love to see someone porting these mods to CC OR making a fork for javascript support
CC and OC are dramatically different mods. CC's purpose is to be simple, yet powerful, great for beginners (but not just beginners), while OC's experience is a more realistic, yet still fun version of in-game computers, for some of the more advanced to tinker with.
JavaScript in ComputerCraft would likely require a full rewrite, considering how closely coupled it is with its Lua runtime.
considering how closely coupled it is with its Lua runtime.
As far as the Java side goes, the issue is not in being coupled to Lua, but rather ILuaContext
's assumptions about LuaJ's coroutine model. I'd quite like to rewrite the API to be more promise/future oriented, as this allows us to remove that assumption, but obviously this breaks backwards compat and I'm reluctant to do that given the current state of CC.
As stated before, I'm still not convinced about the usefulness of multiple languages, but this sort of improvement would make using other Lua implementations like Rembulan or single-threaded Lua easier to implement.
@apemanzilla Repeating @zardyh words:
"Do a google search and you'll find tons of reasons why any language sucks."
@vpontin And as also previously mentioned, there are several significant reasons why JS in particular sucks.
Everytime you ask for replacing or adding new support for a programming language you get tons of people saying why not to do it, no matter which language you are asking for
Of course you do! The complexity is not necessary, it does not affect your ability to write programs, and if you really don't like Lua, just compile into Lua, or, if no such compiler exists, transcompile or write your own compiler.
it does not affect your ability to write programs
Really? Would you (personally) be able to write the same program with 286 assembler on DOS and with Python on Linux? Which one is easier? Don't you think assembler would hinder development just a little bit? Familiarity with syntax? You can't do the same things in Python that you can in JS, and vice versa!
Sure you can they're both turing complete, write a compiler if you care that much about syntax
@zardyh I'm replying to their comment "it does not affect your ability to write programs" rather than the whole thread. In addition, I fucking love lua I don't care that it's not TypeScript
@zardyh That's not the same as transpiling an already-existing language and porting its standard libraries to Lua. If you wanted to transpile JS to Lua, you'd have to replicate all of its quirks - hoisting, this
, prototypes, regex, etc. It would be very much like porting a JS runtime to Lua, which would probably be easier than trying to transpile, except you'd be transforming it into Lua and doing all sorts of weird stuff. It's not a fun project.
@zardyh JS is not Lisp or ML... Look, languages vary, Brainfuck is less complicated than Lua and Lua is less complicated than JS
If it was not for the complexity this would add to the mod, then great! However, this would make maintenance to the mod harder, and also people looking through source for CC programs would have to read 2 languages. Another question would be passing variables between JS and Lua, which may add more complexuty, as JS and Lua variables do not work the same (JS functions have prototypes, so Lua would pass a table with a metatable? It is a bit weird)
I think this has been debated enough, and that someone should close this issue (& lock it so arguments and insults don't happen). I still believe that CC should remain an easy-to-use Lua-based computer mod. Want JS? Think OpenComputers.
Sadly Logan only person that can close the issue is orginal poster (who really got spammed with emails via this discussion probably) or dan200 himself. Noone else has permissions to do anything in this repo.
That seems fair enough :) It sounds like since development is limited, and the community would get split, it would be best to stick with Lua. Lua was designed for embedded programming, while javascript was designed for web development. They each have their strengths and weaknesses, but in this case, Lua seems best.
Lua was designed with embedded programming, while javascript was designed for web development.
You missed the point, but let's go with that. π
In what world is something like, for example,
sum = sum + number
a bad thing?
In a world with tail recursion
In what world is something like, for example,
sum = sum + number
a bad thing?
In a world with tail recursion
@zardyh Elaborate please?
you should use recursion instead of loops because it's more principled. good programming languages don't even have loops.