HACKER Q&A
📣 taosx

Interest in a Rust-Inspired Language Compiling to JavaScript?


Hello HN,

I'm considering the development of a new programming language, drawing inspiration from Rust's strengths, with a focus on compiling to JavaScript. Here what I'm considering are some key features:

- Strict Typing System: no type-related bugs.

- Algebraic Data Types.

- Exhaustiveness Checks.

- 'Unsafe' Mode: Directly interact with external JavaScript/TypeScript.

- no 'null/undefined': Option/Result instead.

- Trait-Based Programming.

- Backend Development Focus.

- Compiler: dead-code elimination and partial evaluation, similar to Prepack[0] (by Facebook).

I believe this approach could bring significant benefits, especially with recent additions like TypedArray and worker threads.

Would this be of interest to the community? Looking forward to your insights and discussion.

Currently I don't feel confident to complete the project as I am so any recommended resources[1] would be extremely helpful, especially around the area of implementing types.

[0] https://github.com/facebookarchive/prepack

[1] https://github.com/taosx/axido (nothing is decided)


  👤 jraph Accepted Answer ✓
(I'm interested in programming languages, my comment is asking questions because I'm curious, I'm not questioning the project)

You mention a focus on backend development. Why suffer having to compile to JS if you are not restricted by the runtime environment? (in the backend, surely you can run anything). In my understanding, compiling to JS is only interesting when you want to run in the browser, but outside this constraint, JS seems like a less than ideal compilation target (though probably way better than before thanks to the presence of typed arrays).

Is it interoperability with the JS ecosystem? Wouldn't the no null/undefined criterion be a barrier to this? Or will you take any result from a call to a JS function as optional? Or have interfaces saying "I promise, I will never return null/undefined"?

Or you still want your language to be able to run in browsers? In this case, will you provide a standard library (with the cost of having to transfer it every time it's used), or only a thin wrapper around native JS functions?

You say Rust-inspired. For me, one of the most interesting features of Rust is the explicit management of the lifetime of objects. How do you intend to handle this aspect, with JS not having anything like this?


👤 aslpavel
There is already - PureScript - https://www.purescript.org/ - though it is closer to Haskell - ReasonML - https://reasonml.github.io/ - essentially ocaml with nicer syntax Both are strongly typed with algebraic data types

👤 scotty79
I'd really love to see a language with primitives for entity-component-system paradigm and convenient syntax for hierarchical finite state machines.

Just doing types, classes, interfaces again and again isn't really interesting.

Most interesting thing in Rust is not the type system or borrow checker but value semantics.


👤 austin-cheney
Most developers in JavaScript struggle with asynchronous things. Instead they hope to solve everything with classes and when that fails they need frameworks to do anything. So, I recommend solving for that first instead of jumping into innovative syntax features.

My recommendation is to create a new language that’s focused exclusively on functions and how to organize them. Organization is an advanced skill learned from experience that is not immediately benefitted from high intelligence and most developers fail in that regard. Think in terms of lexical structures, events, return types, data structures, process flow (technical and business), and call stack.

If you can really dominate concepts of organization by language design the best supporting syntax innovations will shift to more specifically meet your needs.


👤 techn00
It seems like an awesome project, I'd say go for it, check /r/ProgrammingLanguages as well. However, typescript is "good enough" for the community, so I don't think it will take off in the sense that you mean.

👤 tim1994
Sounds like an interesting project, but I think it's important to find a good way to interact with browser APIs. They all work differently, like rAF, geolocation, pointer lock, camera access and so on. I think relying on the unsafe mode for all that could lead to a frustrating experience but also implementing those APIs in a different way would be weird and you have to keep up with new APIs and changes browsers introduce. I suggest having an idea on how to solve this before spending a lot of time developing the actual language. If it limits what I can do with JS I would not use this and just stick with Typescript.

👤 pornel
I'd like a thin compile-to-JS language with a Rust-like syntax, only because after writing Rust/Golang/Swift for a while, I keep forgetting to write parens in `if cond` and `for … in`. Suffix .await is a nice to have too.

I'm not so sure about implementation of Rust's semantics in JS. If I want exact Rust semantics, I can use WASM.


👤 vinniepukh
As another commenter has already suggested, ReasonML has a lot of what you described here.

However, modern JS-oriented toolchain for ReasonML is called ReScript and you can learn more here: https://rescript-lang.org/


👤 az09mugen
I don't think it's a rust-inspired language, but since it has strong typing and compiles to javascript, did you give a look at nim [0] ?

For what it takes, it can inspire you and I find the language very expressive and flexible.

[0] : https://nim-lang.org/


👤 anticrymactic
While an improvement to js is _always_ welcome. I am worried about the "debuggability". How do you plan on generating the js efficiently?

I HATE most js frameworks for this reason. Understanding/Tweaking websites is something I do extensively, and obfuscated minified recursive js makes this REALLY hard.


👤 aristofun
> no 'null/undefined': Option/Result instead

Another theoretical fantasy that has nothing to do with real world.

In real world we do have null and undefined values. It is artificial and redundant to pretend that there isn’t.


👤 continuational
I'm working on such a language! https://www.firefly-lang.org/

It's aimed at full stack programming, not exclusively backend.


👤 aristofun
> Strict Typing System

Please stop right here.

Real world is not a theorem.

We, down to earth developers, have had enough of this over engineered crap. We need flexibility.

There is already a near perfect language for JS.

It’s called Typescript.

Youd make a much more good for the world if you improve it, fix few issues etc.


👤 _randyr
Gleam?