Looking for a language, that can easily compile to WASM
from ZILtoid1991@lemmy.world to programming@programming.dev on 29 Aug 2024 18:20
https://lemmy.world/post/19197120

Originally, I was going to use D, but its current WASM guideline is buried under a lot of Discord threads, all while people are lazy to touch the wiki. I need to test stuff with WASM (use for scripting in applications, not browsers).

Please NO RUST!!! While I see why functional programming is useful (I even use wasmtime as my WASM engine, which is developed in Rust), but is horribly counterproductive for game development, especially if it’s opt out like in Rust.

EDIT: In the meanwhile, I’ve found AssemblyScript, which seems to be good for my usecase.

#programming

threaded - newest

AllNewTypeFace@leminal.space on 29 Aug 2024 18:41 next collapse

Swift could be a good choice.

abbadon420@lemm.ee on 29 Aug 2024 20:50 collapse

When is Swift ever a good choice?.. JK :)

Sibbo@sopuli.xyz on 29 Aug 2024 18:48 next collapse

Rust?

mesamunefire@lemmy.world on 29 Aug 2024 18:55 next collapse

Ive done C++ and C# before. Both work but it still feels very experimental in browser support. Ive put lisp in the browser through wasm with C++. Its was a fun novelty.

gjoel@programming.dev on 29 Aug 2024 19:27 next collapse

I haven’t tried it, and it seems to be in alpha, but… Kotlin?

rwdf@lemmy.world on 29 Aug 2024 19:59 next collapse

You can use Go and compile with TinyGo.

AllNewTypeFace@leminal.space on 29 Aug 2024 21:15 next collapse

The downside of that is that you have to code in Go

bhamlin@lemmy.world on 31 Aug 2024 13:25 collapse

That is a downside, yes…

sjpwarren@programming.dev on 29 Aug 2024 22:52 collapse

I wish the “standard” Go’s WASM support was better.

CookieOfFortune@lemmy.world on 29 Aug 2024 20:00 next collapse

Rust isn’t strictly functional? Do you mean you’d like a language with garbage collection?

[deleted] on 29 Aug 2024 21:26 next collapse

.

CookieOfFortune@lemmy.world on 29 Aug 2024 21:43 collapse

Are there benefits in not having a GC in WASM?

Also are there mainstream memory safe languages without a borrow checker? There’s some experimental ones out there.

unique_hemp@discuss.tchncs.de on 29 Aug 2024 21:51 collapse

At least a while back there was not a built-in GC on the WASM runtime side, so the GC has to be shipped with every app.

expr@programming.dev on 30 Aug 2024 03:21 collapse

It’s not a functional language at all, even if it borrows ideas from FP languages. It’s an imperative language through and through.

FizzyOrange@programming.dev on 31 Aug 2024 14:52 collapse

“It’s not a functional language at all even though it has lots of functional language features”

What? Rust is really quite a functional language in style, even if can easily support an imperative style too.

What exactly do you think makes something a functional language? Apart from currying I can’t think of any typical FP features it is missing.

expr@programming.dev on 31 Aug 2024 15:46 collapse

Fundamentally it’s a language oriented around blocks of statements rather than composition of expressions. Additionally, it takes a different approach to the mutation problem than FP languages: where FP seeks to make most things pure and push mutation and side effects to the edges of the program, Rust uses its type system to make such mutation and side effects more sane. It’s an entirely different philosophy when it comes to programming. I don’t think either approach is necessarily better, mind you, just a different set of tradeoffs.

I’m a professional Haskell developer and am very much immersed in FP. When I read Rust code, I have to completely shift my thinking to something much more imperative. Whereas if I read, say, Ocaml, the difference is mostly syntactic. This isn’t a slight, mind you. I quite like Rust. But it’s a very different paradigm.

FizzyOrange@programming.dev on 01 Sep 2024 06:41 collapse

where FP seeks to make most things pure

I made this mistake for ages because Haskell is so popular and it’s functional and pure, but it’s not actually a requirement for functional languages to be pure. OCaml isn’t.

When I read Rust code, I have to completely shift my thinking to something much more imperative.

I agree Rust code has a different feel to OCaml code but that’s because it makes some things easier (e.g. mutation, vectors). You still could write Rust as if it was OCaml (except for the lack of currying), it’s just that nobody does that because it sucks.

I think we’re probably agreeing, it’s just that “functional programming” is extremely poorly defined and we’re interrupting it differently. You’re thinking “a language where people write enormous nested expressions and over-use recursive functions and linked lists” and I’m thinking “a language that supports lots of features common in the FP paradigm: first class functions, pattern matching, expression based not statement based, iterators/map/filter/reduce, currying, tagged unions/sum types, etc.”

expr@programming.dev on 01 Sep 2024 12:35 collapse

I made this mistake for ages because Haskell is so popular and it’s functional and pure, but it’s not actually a requirement for functional languages to be pure. OCaml isn’t.

I didn’t say that FP languages have to necessarily be pure, just that FP languages tackle the problem of mutation by arranging programs such that most things are typically pure and side effects typically happen at the periphery (logging is probably the one exception, though). This is true even in FP languages that allow arbitrary side effects in functions, it’s just not enforced by a compiler.

I agree Rust code has a different feel to OCaml code but that’s because it makes some things easier (e.g. mutation, vectors). You still could write Rust as if it was OCaml (except for the lack of currying), it’s just that nobody does that because it sucks.

That’s the entire point, though. It’s all about what the language emphasizes and makes easy to do. If it’s unnatural to write a functional program in Rust and no one does it, then it’s not really reasonable to call it a functional language. Writing functional programs is not idiomatic Rust, and that’s okay.

paw@feddit.org on 29 Aug 2024 21:07 next collapse

I find Zig a language wuth very good WASM support out of the box and it is mostly imperative in nature.

It is currently pre 1.0 and has some rough edges.

sjpwarren@programming.dev on 29 Aug 2024 22:53 next collapse

I have not used this but Moonbit “looks” good www.moonbitlang.com

namingthingsiseasy@programming.dev on 30 Aug 2024 01:35 next collapse

I haven’t done too much work with WASM myself, but when I did, the only languages I saw recommended were Rust, C++, or TinyGo. From what I’ve heard, Rust and C++ are smoother than TinyGo. Garbage collected languages usually aren’t great choices for compiling to wasm because wasm doesn’t have any native garbage collection support. That limits your selection down a lot.

But another option you may want to consider is Nim. As I understand, it compiles to C, so any C->Wasm compiler should theoretically work for you as well. I did a quick search and wasn’t able to find any great resources on how to do this, but you might get a bit more lucky. Good luck!

benjhm@sopuli.xyz on 30 Aug 2024 21:26 next collapse

Scala-js is working on it - as its compiler design may facilitate this.
I haven’t yet tried (on todo list) and am not an expert, but bookmarked in passing:
recent github implementation, some history, following older discussion

UFODivebomb@programming.dev on 31 Aug 2024 15:46 collapse

Scala-js is becoming my go to scala backend. I did not know there was a wasm feature coming. Will try

RonSijm@programming.dev on 31 Aug 2024 16:15 next collapse

What are you building, it depends a bit on your usecase

Otherwise c# Blazor compiles to WASM

BehindTheBarrier@programming.dev on 31 Aug 2024 18:59 collapse

Late here, but if you want the easy route then there is always Unity (C#) if it fits for your use case in game dev and the license isn’t a problem for you.