Swift vs Rust for WASM/WebAssembly

Wondering if anyone has any thoughts on choosing between these two languages for WebAssembly?

I definitely want to explore wasm, and really love the idea of learning both of these, however, I can only squeeze one in right now.

Anyone have any thoughts? Which might be the easier route? Which will be more useful/fully featured/supported? etc.

Here are some pros and cons (from a personal perspective so far):

Rust

  • Can also be used with Elixir/Erlang nifs
  • Can also be used in other areas such as general web dev
  • Huge community support

Swift

  • Can be used for iOS/macOS apps
  • While can be used for other areas (such as web dev too - I get the feeling not quite as well as Rust)
  • Huge Apple support
2 Likes

Corresponding tweet for this thread:

Share link for this tweet.

1 Like

Good discussion points, though Kevin Hoffman is the author of Programming Web Assembly with Rust. #book-programming-webassembly-with-rust

1 Like

Whoops - think I am still half asleep Margaret :relaxed: (have edited that bit out and will go edit that other thread now too…)

I don’t have a lot of experience with Swift, so I can’t really comment on it. Rust works very well with web assembly (some assembly required, heh). One of the reasons I picked up Rust was that it made it easy to write tutorials and include a web-runnable version (my Roguelike Tutorial series has each example as a playable web game - e.g. https://bfnightly.bracketproductions.com/rustbook/wasm/chapter-74-darkcity/ ).

There are downsides. If you link with C libraries, chances are you have to come up with some shims to handle the bits of the C library that don’t exist in WASM-land. Also WebGL is almost but not quite compatible with regular GL - so for graphics you’ll have to tweak things a bit.

2 Likes

Thanks Herbert, that’s very helpful :smiley: (the link to your tutorial goes to a blank page for me tho?)

Would you say Rust is difficult to learn? I’ve heard people say Rust can be quite difficult to pick up (most recently in the article posted here) and I think that is one of my biggest concerns about learning it.

I may have messed up the link, sorry! http://bfnightly.bracketproductions.com/rustbook/ should work.

Rust is a systems language, so its harder than Python and other very high-level languages. It tries really hard to not surprise you, and once you have the basics down it’s a relatively smooth learning curve. Some things - like threads - are much easier than other languages. Other things like the borrow checker will cause a bit of head-scratching at first.

2 Likes

Thanks again Herbert… I think I am going to have to brave it one day, even if I just start on the basics to see how I like it :sweat_smile:

2 Likes

Rust.

Swift for WebAssembly is not quite there yet…

3 Likes

I pick up this post out of the grave but I was wondering the same last year.

I really like Swift, despite some weird syntax stuff, like keypath (can’t wrap my head around).

Nevertheless, it lacks promotion for something else other than nOS dev.

IBM was developing Kitura and just leaved the project, now it’s community driven which is great, but there’s no huge site that leverages Swift as a backend language.

Apple has promoted Swift for server-side only this year at the WWDC here.

Vapor is great, I really like how it works, the community, the versatility of the framework, etc.
But it really lacks promotion, there’s few books, quite expensive, some of them outdated due to breaking changes.

Compared to all the books written about Rust, it’s heartbreaking for Swift.

So obviously I’d go for Rust because of Yew, because of Actix or Axum etc.

1 Like

I haven’t heard much about Swift for WASM since tbh, however Swift is still super interesting if you want to do dev for Apple devices :smiley:

if you want to do dev for Apple devices :smiley:

That’s where I’m sad :cry:
Only use Swift for nOS dev…

I’ve tried this last summer but got an issue because of macOS Ventura beta

1 Like

Don’t think I’ve seen that before - looks good!

What’s nOS? :lol:

A way to say iOS, macOS, etc. I’m too lazy to type it all lol.

1 Like