ComputerCraft

ComputerCraft

21M Downloads

Integrate Rhino Javascript Engine

smj-edison opened this issue Β· 65 comments

commented

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?

commented

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.

commented

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).

commented

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!

commented

Do a google search and you'll find tons of reasons why any language sucks.

commented

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 "==").

commented

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?

commented

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 use var++ or var += 1
  • nil instead of null - just why?
  • Using .. instead of + for concatenation is super confusing

Having JS in CC would definitely deserve a thumbs up.

commented
  • 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 as if () {}, 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 and undefined, 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)
commented

Also, there are options like TypescriptToLua if you're really that concerned about syntax

commented

Reasons JS is worse than Lua:

edit: no coroutines, either!
edit 2: typeof null === "object" while typeof undefined === "undefined"
edit 3: lack of *= etc is a good thing since mutation is a code smell

commented

It happens because you use "==" and "!=" instead of "===" and "!==", which doesn't juggle the types

commented

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...

commented

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.

commented

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.

commented

@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.

commented

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.

commented

@lordvico Or a JS VM inside Lua.

commented

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.

commented

This would be a hell slower i think.

commented

Of course, JS is infinitely more complex than Lua is.

commented

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

commented

@lordvico Or better yet allow the creation of different architectures like OC has.

commented
commented

Or better yet just use OC
If you want JS

commented

@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.

commented

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.

commented
commented

Just had a quick look around, this might work for those who want js in cc https://github.com/wizzard0/js2lua

commented

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.

commented

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";
commented

@setzerbomb

  • 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:

    image

    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.

commented

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.

commented

That makes sense. Thank you for explaining!

commented

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.

commented

@SquidDev isn't 1.13 going to break a lot of things? Why not break more?

commented

@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.

commented

isn't 1.13 going to break a lot of things? Why not break more?

The issue is twofold:

  1. 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.
  2. 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.

commented

I would love to see someone porting these mods to CC OR making a fork for javascript support

commented

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.

commented

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.

commented

@apemanzilla Repeating @zardyh words:
"Do a google search and you'll find tons of reasons why any language sucks."

commented

@vpontin And as also previously mentioned, there are several significant reasons why JS in particular sucks.

commented

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

commented

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.

commented

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!

commented

Sure you can they're both turing complete, write a compiler if you care that much about syntax

commented

it wouldn't, though, learn the language then write a compiler

commented

@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

commented

@zardyh You do it if it's that simple, go on, show me how it's done.

commented
commented

@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.

commented

Lisp and ML are languages that already exist

commented

@zardyh JS is not Lisp or ML... Look, languages vary, Brainfuck is less complicated than Lua and Lua is less complicated than JS

commented

JS is about as complicated as Lisp or ML, maybe you should learn about compilers

commented

@zardyh Excuse me, but what exactly is your problem?

commented

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)

commented

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.

commented

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.

commented

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.

commented

Lua was designed with embedded programming, while javascript was designed for web development.

You missed the point, but let's go with that. πŸ˜›

commented

@LoganDark

In what world is something like, for example, sum = sum + number a bad thing?

In a world with tail recursion

commented

@LoganDark

In what world is something like, for example, sum = sum + number a bad thing?
In a world with tail recursion

@zardyh Elaborate please?

commented

you should use recursion instead of loops because it's more principled. good programming languages don't even have loops.

commented

@zardyh I guess most programming languages aren't good then

commented

u rite, not sure how appeal to popularity is supposed to work in a rational field of debate but ok