
SwiftWasm: Run Swift in Browsers - gyre007
https://swiftwasm.org/
======
yingw787
I love the talk on "The Birth and Death of JavaScript" by Gary Bernhardt:
[https://www.destroyallsoftware.com/talks/the-birth-and-
death...](https://www.destroyallsoftware.com/talks/the-birth-and-death-of-
javascript)

Highly encourage everybody to watch it and how people may interact with
JavaScript more and more through things like WASM. Very funny talk too :)

~~~
adamnemecek
There's little relationship between wasm and js.

~~~
_bxg1
The talk is more about the web as an application platform, and its values,
coming down to OS userland. Whether that means JS or Wasm or both doesn't
really matter.

------
GreaterFool
What would be more interesting than running Swift in the browser is running
Wasm on Android and iOS. That would bring some true code sharing between the
browser, mobile and backend! And also easily allow constructing apps using
pieces written in any of the languages that nicely compile to Wasm.

~~~
gok
Why not just compile the Swift to native Android and iOS code?

~~~
GreaterFool
Because Wasm could be used mobile as a native first class citizen, not limited
to running within a browser or some browser view. And then Wasm code can be
shared between multiple environments including mobile, browser, edge
(CloudFlare workers), backend (multiple Wasm runtimes are emerging right now
and some of then are very performant). And then one would not be limited to
Swift but could use any language that compiles to Wasm. So code reuse would
effectively skyrocket.

Wasm can be used in every corner of computing spectrum. It doesn't mean it's
some perfect tool to solve all problems but it can lead to interesting places
and those are worth exploring.

~~~
millstone
Honestly this reads like a solution in search of a problem. Native code will
be faster in every way.

Wasm's strengths are in running untrusted code - its sandbox is quite strict.
So the use case for wasm on mobile is downloading code dynamically. Wasm's
competition in this space is JS, not native code.

~~~
jamil7
> Native code will be faster in every way.

Sure, but I believe a lot of people will be willing to make a performance
tradeoff for that convinience.

------
pumanoir
There is also
[https://www.elementscompiler.com/elements/default.aspx](https://www.elementscompiler.com/elements/default.aspx)
which is a pretty good compiler and webassembly is one of the compile targets.

------
_bxg1
This could be really cool given that Swift is already very JavaScript-like
(Edit: TypeScript, really). A JavaScript-like that you can run on the web and
is just faster out of the box is appealing.

Now if only Apple would put more effort into cross-platform support for
Swift...

~~~
hellofunk
Swift is like JavaScript/TypeScript only if you don't know Swift that well...

They are so different, only very superficial comparisons of syntax would lead
to such a statement.

~~~
_bxg1
I don't know Swift that well, but this was my immediate impression when I
spent a couple hours with it (and I've used C, C++, Java, C#, Python, etc.).

The array/dictionary literal syntax (especially dictionaries) was probably the
main thing. Lots of languages have similar array syntax (though fewer have the
auto-grow behavior), but I can't think of another C-like language with first-
class, dedicated dictionary syntax.

C-likes also don't often have first-class functions/closures, or named
function parameters (JS doesn't _technically_ have the latter, but it
effectively does with object destructuring; this is one of the syntax niceties
Swift added).

I didn't mean to imply they had an overall similar set of features, so much
that someone who's comfortable with TypeScript would have a pretty easy time
warming up to Swift, which matters on the web.

~~~
paavohtl
> C-likes also don't often have first-class functions/closures

I think C is the only remaining C-like language not to have first-class
functions. And there are compiler extensions for that too.

~~~
_bxg1
My understanding is that in cases like Java and C++, the lambdas aren't truly
first-class; they come with limitations. I could be wrong.

~~~
hellofunk
That's true about Java but not C++. C++11 introduced true lambdas, but Java's
idea of lambdas is rather laughable by comparison and nowhere near as
flexible.

------
bouh
Seems that swift is gaining a lot of traction. It has also have drawn interest
in the Machine learning community

------
mastrsushi
Can someone explain to me what makes Wasm any better and/or different than
Javascript bytecode.

~~~
sanxiyn
WebAssembly has 64-bit integers and 32-bit floating points, which is difficult
to do fast in JavaScript because everything is 64-bit floating points there.
(32-bit integers are exact in 64-bit floating points, so that works.) This is
the main advantage.

WebAssembly is also easier and faster to parse for now, but won't be for long,
because JavaScript binary AST work is in progress:
[https://github.com/binast](https://github.com/binast)

JavaScript has better access to DOM and is superior otherwise.

~~~
MiroF
And wasm is a compilation target for languages that aren’t JS, a pretty big
advantage in my book

~~~
sanxiyn
JS also is a compilation target for languages that aren't JS, so that is no
advantage. What advantage there is boils down to 64-bit integers and 32-bit
floating points.

~~~
MiroF
JS is not a real compilation target for compilers like LLVM and to suggest to
the contrary is silly.

JS is a _transpilation_ target and not really for many low level languages.

~~~
dragonwriter
> JS is not a real compilation target for compilers like LLVM [...].

> JS is a _transpilation_ target

Transpilation is a subset of compilation, so if it is a transpilation target
it is, by definition, a compilation target.

------
mlevental
i really really really like swift. it's by far the best language i've ever
used but i wish it weren't so "monoculture" (ios dev). i guess this is good
for that but i really wish the open source port of foundation were the focus
of the community.

~~~
NobodyNada
I feel like the open source port of Foundation is in pretty good shape
(especially compared to a few years ago). The really important classes are
mostly complete ([0]); all that's left is primarily some of the advanced
networking features (but many real-world networking applications use swift-nio
instead anyway). I think what's most important is 1) language refinements via
swift-evolution, and 2) projects which bring Swift to more domains, such as
this for the client-side and Vapor for the server-side.

[0]: [https://github.com/apple/swift-corelibs-
foundation/blob/mast...](https://github.com/apple/swift-corelibs-
foundation/blob/master/Docs/Status.md)

~~~
ken
The number of Linux issues on bugs.swift.org is still significant. Even when
code compiles on Linux, it often doesn't work without crashing, or has
different behavior. As someone who has tried to port (non-GUI) Swift code from
Mac to Linux, I'd say there's still a ways to go.

~~~
NobodyNada
It's not always perfect, but it's certainly _much_ more stable than it was a
few years ago, and it continues to improve with each release. A few years ago
I had to spend weeks with each new Swift release debugging segfaults and
working around Foundation bugs and missing features, but lately my Mac-tested
code usually works just fine on Linux (except for the occasional problem with
C library dependencies or platform-specific APIs).

------
robertAngst
>programming language developed by Apple Inc

I would be too worried about Apple going full Apple and screwing devs to ever
learn Swift.

I think this is a permanent disadvantage for anything B2B.

~~~
Razengan
C#/.Net has done fine despite its birth in a company with a far worse
reputation for abandonment. Same for Go.

~~~
simonh
Java ending up with Oracle was a bit of a worst case scenario as well, yet
people still write Java. Exclude languages originating with a big corporate
sponsor or owner, and that's half the development ecosystem gone.

~~~
Razengan
Yes, I mean look what just popped up today: "Microsoft Throws in the Towel on
UWP, Elevates Win32"

[https://news.ycombinator.com/item?id=19883351](https://news.ycombinator.com/item?id=19883351)

Before I jumped ship to the Apple ecosystem around 10 years ago, I was even
then already sick of Microsoft abandoning or being indecisive about their
platforms.

