Developing for Computercraft in Lua is difficult
crabdancing opened this issue ยท 12 comments
If I make a mistake in Java, I'm told ahead of time by the IDE that e.g. the method name I typed doesn't exist, or those data types are incompatible. This works in Python, too. Is there a way to do the same for Lua? I'm using VScode with the recommended plugin pack for Computercraft development, and the tools seem inadequate for discovering problems before run time, and also don't do the vagueness of those problems any favors -- something that seems intrinsic to Lua's approach to software design.
This is less of a problem with Lua, and more a problem with any dynamically typed programming language. When you don't have static type information, you make your language less amenable to static analysis.
JS and Python have the advantage that they're incredibly popular languages, and so have had millions of dollars spent on tooling. Lua ... less so.
CC:T uses illuaminate to do some pretty primitive static analysis. A lot of the type information is there, thanks to doc comments, I just haven't got round to making use of it yet. That said, making it then work for external projects is a whole 'nother bucket of fun.
TLDR: Yep, that's the best it's getting.
True but Lua does make it worse because it uses tables for everything and silently accepts missing args, assuming null. I've found that wayyyy too fly by the seat of the pants for me.
We hope to integrate CC:Ts own docs with the plugin pack better in the future, but again, other than docs and type information for globals and basic linter checks, there's not much that can be done
uses tables for everything and silently accepts missing args, assuming null.
So does JS (well, they semi-recently got classes I guess). :p. This bit isn't too bad, because generally the structure of the table is pretty obvious statically, it's just there's not much which takes advantage of it!
@Lemmmy Go to bed!
@SquidDev JS is even worse IMO. xD
Without a very solid IDE I wouldn't even want to touch something nontrivial in JS. Waaayyy too much hair pulling.
JS is even worse IMO.
Oh, definitely :). I guess my point more is that there are IDEs which do support JS's craziness, so it's technically possible to do the same for Lua. It's just that there's not been much investment in actually making the tools.
I'd say PRs welcome, but honestly it's a tricky problem space and I don't know the best way to approach it.
@SquidDev what do you suppose it would it take to get support for a better supported language like Python in CC Tweaked?
A different maintainer :p.
In all seriousness, it's been discussed several times before, and my opinion has swung around a lot. There's a couple of reasons I want to stick with Lua though:
Far-too-long bullet point list of reasons.
-
Lua is a tiny language. This gives us a lot of benefits:
- As the language doesn't change much (well, we're stuck on 5.1 so doesn't change at all), there's not really any impetus to keep up-to-date with the latest version. Jython is stuck on Python 2.7, and Rhino (Java JS engine) doesn't even support EMCAScript 2015!
- Because the language is so small, maintaining Cobalt (CC:T's Lua implementation) is a one-person job. If there's missing/broken functionality, it's a much smaller job than trying to change Jython/Rhino.
- Maintaining our own dedicated runtime makes it much easier to add functionality. It's possible to pre-emptively pause the Lua VM, and I'm currently working on some persistence code - couldn't even imagine adding that to a larger language.
-
If you support multiple languages, you run the risk of fragmenting the ecosystem and community. You effectively have two separate mods - Lua!CC:T and Python!CC:T, which only share some method names (and a Java API). Code written for one is (obviously) not going to work on the other.
-
Nobody uses non-defaults. That's a little unfair, but if you look at OpenComputers you find that very few people use custom architectures (and very few people use custom operating systems, but that's a separate debate :)). Obviously having the choice is nice, but still not convinced it's worth the cost.
It's worth noting that the internals of the Lua VM are pretty well abstracted, so implementation wise it's pretty easy to swap something else out. It is still tied to Lua (due to loading the CraftOS rom), but that wouldn't be too hard to change.
Of course, the alternative is just to run your Python on a remote server and bridge it to CC. :p.
Well, there's all of these. Haxe is probably the most stable, though I'm partial to Urn and Amulet.
@SquidDev Any chance of any other programming language? Honestly, I'll take anything over Lua at this point, short of Brainfuck. Kotlin, maybe? :P
Can always use Haskell, too!