PMunch / nim-playground-frontend

The front-end for https://play.nim-lang.org
45 stars 16 forks source link

Add JS target, show generated source #33

Closed mindplay-dk closed 1 year ago

mindplay-dk commented 1 year ago

To evaluate Nim as a front-end language, users would need to see the generated source code - and viewing the source would probably be interesting to C and C++ users as well.

In many cases, I'd think that's all the user is looking for - being able to run the code might be interesting to someone who wants to learn the language, although in that case they should probably be using a local install anyway.

For that matter, I think you could feasibly drop the back-end entirely. Since Nim compiles to JS, and Nim is written in Nim, it should be possible to create a JS build of the compiler itself, right? So with that, users could try out the language (minus things like file system and network features, which you probably don't want them using on your servers in the first place) and the whole thing could run client-side, compiling to JS and running locally in the browser - and displaying the compiled source code.

For example Babel and TypeScript do it this way.

Thoughts?

PMunch commented 1 year ago

While it wouldn't be hard to add a "Show generated source" button this isn't typically something developers using Nim has any interest in. Nim generates easily optimizeable code, not human readable code. So there isn't that much value in looking at the generated code.

You are correct that Nim compiles to JavaScript, but certain things are not available in the JavaScript target. How would the compiler read the files in the standard library or the installed 3rd party packages for example? While it might be possible to modify the compiler to a point where it will run under browser-javascript this certainly is not a task which is anywhere near the scope of the playground.

Babel and TypeScript are quite different from Nim in what they do. Babel is more or less just a transpiler, meaning that it takes one flavour of JavaScript in and outputs another. TypeScript might do a bit more work, but it's also essentially much closer to JavaScript than Nim. Comparing Nim to JavaScript is closer to comparing C to Assembly.