4 ms·
At work I needed a fast scripting environment for Android. Not everyone who'd be scripting for the application knew Lua (or Squirrel) so I went with J2V8 (Java
by BoorishBears 10y ago
At work I needed a fast scripting environment for Android. Not everyone who'd be scripting for the application knew Lua (or Squirrel) so I went with J2V8 (Java bindings for V8).
The first problem I ran into was documenting the API defined on the Java side of things. I tried Jsdoc, but it was cumbersome for what I was trying to do (expose type information).
I tried Typescript on a whim and fell in love with it. The people who only know Js could still use Js, but the Ts scripts so easy to reason about I disabled Js support in my build system (which uses Browserify and some in-house signing tools to compile the script files into one package I can easily load into V8).
The people who were used to Js couldn't just write everything they would Js as this article describes, but what they couldn't write seemed to be stuff that would break a lot of compile time checks. It was a little battle to get one guy to stop using <any> everywhere, but 9/10 times that he came to me with a broken script, it was something that satisfying the compiler without <any> would have found the issue.
And the Java side now looks so much cleaner because we have a compiler that can check that we're sending it the right types, so there isn't as much work trying to cast everything from Object to different representations it could have in Js. I define interfaces that the Java side implements with 'declare' and get that type checking and autocomplete for exploring the API for free, which is another huge win.
I've noticed a lot of JVM-Js integration (Kotlin has Js interop iirc) and I think Typescript is really great there. Flow looked interesting, but it felt like its approach is more targeted towards existing code bases trying to migrate to it, and we didn't have that constraint