
AssemblyScript: A Subset of TypeScript That Compiles to WebAssembly - indescions_2017
https://github.com/AssemblyScript/assemblyscript
======
vosper
I get the attraction for compiling a non-web language (say Python) so that you
can write Python and have it run in the browser, but since Typescript already
compiles to JS I don't really get it. What am I missing? Can it be faster, or
do more/different things?

~~~
JasonSage
I don't think so.

From what I understand, calling WebAssembly functions from JavaScript (and
vice-versa) incur a runtime penalty that's way worse than calling JavaScript
functions from JavaScript. As such, WebAssembly makes sense for entire
applications that would be compiled—think game engines targeting WebGL, or a
font rasterizer targeting canvas, etc.

Since this only supports a subset of TypeScript, you won't even be able to
compile your dependencies to WebAssembly, meaning that literally any code you
interact with that you did not write has this performance setback.

~~~
forgotpw1123
... Until the first person ports QT or GTK and suddenly WASM is just pushing
60 PNG frames a second into a canvas.

~~~
pjmlp
I am betting WASM will be the revenge of plugins.

And then, just like the ad spams using JS, its advocates will be getting more
than they asked for.

Get ready for WASM blockers.

~~~
slackingoff2017
WASM is going to kill spidering. We can't leave HTML if we want google to be
able to read the page.

I think Google is very afraid of this. Hence their push for
Angular/Polymer/AMP. If they can build a good enough platform in JS they can
stall the inevitable.

In the future only marketing parts of the site will use JS/HTML. The "web app"
part will be some language compiled to WASM throwing frames to the canvas

~~~
smrq
In a world where SEO consultants exist, you foresee an inevitable future where
Google is killed by a massive wave of companies rewriting their websites to be
un-Googleable?

~~~
slackingoff2017
The big players are increasingly doing it already. LinkedIn and Facebook only
have very limited spidering.

What Google has liked to do recently is take all your data and replace your
service. Search for recipes, jobs, music, or weather for examples.

They're trying to make leaving the homepage irrelevant by using sites data in
their search results. Eventually the web will rebel.

------
Fifer82
I love TypeScript! Forgive my ignorance but what purpose does WebAssembly have
in this context? I assumed that stuff like ASM was really for other non-native
applications. Say for example a C++ game which then can run in the browser or
stuff like that.

So as a TypeScript guy with AssemblyScript at my fingertips, what doors does
that open for me?

I occasionally have to make HTML5 games in Canvas. Is this the kind of path
where WebAssembly could be beneficial?

One day will there simply be an end build step to turn everything into web
assembly or is it never intended for use with the DOM?

~~~
kartan
> Forgive my ignorance but what purpose does WebAssembly have in this context?

Suppose a future web that is language agnostic. Your browser doesn't
understand ECMAScript 2015, nor 2016, nor VBScript. It has an extremely
optimized and fast virtual machine that works with WebAssembly.

This reduces complexity. It brings diversity to the web ecosystem, you can use
any language that compiles to WebAssembly. There are no second class languages
on the web.

But to build that future we need to create the tools. You can already use
clang to compile many languages to WebAssembly, but ECMAScript nor Typescript
are on that list.

WebAssembly should be able to interact with the DOM. But also to more low
level APIS like access to USB devices.
([https://developers.google.com/web/updates/2016/03/access-
usb...](https://developers.google.com/web/updates/2016/03/access-usb-devices-
on-the-web))

Many things can go wrong, or can be moved in other directions. But the big
success of the Java Virtual Machine shows the power of compile once run
everywhere approach.

> Say for example a C++ game which then can run in the browser or stuff like
> that.

That's already possible using EmScriptem
([http://kripken.github.io/emscripten-
site/](http://kripken.github.io/emscripten-site/)). Game companies like King
already use the same C++ code base for their mobile games and browser games.
The problem is performance. With WebAssembly it will get more simple and
faster.

~~~
pjmlp
Regarding the JVM I would also add, that it was common approach on mainframe
architectures to use bytecodes + microcoded CPUs, with IBM and Unisys
mainframes being the best examples still in production.

PCs and mobile OSes have been catching up with those designs.

------
mhd
I'm still hoping that I'll end up on the "Hejlsberg roundabout", i.e. that
this whole WebAssembly thingamajig will get me Turbo Pascal productivity
again. (I know, we progressed since then in regular IDE land, but for the web,
this would be a step forward)

------
freechessclub
...where "A Subset of TypeScript" = JavaScript?

If I am not using this, what are the other languages I can use today that
compile down to WASM?

~~~
greggman
You mean other than C/C++ where you cab take advantage of 30 years of
libraries ?

[http://kripken.github.io/emscripten-
site/](http://kripken.github.io/emscripten-site/)

~~~
BatFastard
Yes, other than C++.

------
johnhenry
> Instead of reimplementing TypeScript as closely as possible at the expense
> of performance, AssemblyScript tries to support its features as closely as
> reasonable while not supporting certain dynamic constructs intentionally:

This sentences, and the examples given with it, show that AssemblyScript is
not technically a subset of TypeScript. There are 'features' in the former
that aren't available in the latter. For example, explicitly converting the
results of binary boolean operators to boolean is something that does not
exist in typescript.

It's a subtle but important distinction, although I may be splitting hairs.

------
dakom
This looks really cool to me for a learning environment. E.g. write some
typescript, see how it compiles to s-expressions, etc.

------
camus2
So if I get things right :

\- ASM.js : basically assembly with a subset of javascript syntax

\- WebAssembly : assembly with a different format which doesn't require
parsing javascript.

\- languages built on top of WebAssembly : C/C++ like languages with explicit
memory management/ no garbage collection.

\- assemblyscript : C with a typescript syntax ?

~~~
orange8
\- ASM.js: A faster, cut down version of JavaScript

\- WebAssembly: The successor to ASM.js, a compiled binary format (as opposed
to plain text) with additional features

\- languages built on top of WebAssembly: More like languages that can be
compiled to the WebAssembly binary format. currently C/C++

\- assemblyscript: A subset of a languange (TypeScript) that compiles to
JavaScript, but which compiles to WebAssembly instead.

~~~
pjmlp
There are already JVM and .NET prototypes.

Rust also supports WebAssembly.

------
redgetan
Just noticed that quite a few browsers support WebAssembly already
([http://caniuse.com/#search=webassembly](http://caniuse.com/#search=webassembly))
. I wonder whether compiling Unity game to WebAssembly is better (more stable)
than Unity to ASM.js

~~~
6nf
There is already a WASM Unity.

[http://webassembly.org/demo/](http://webassembly.org/demo/)

------
aussieguy123
I thought WebAssembly didn't have a garbage collector yet.

~~~
themihai
Apparently the GC is compiled otherwise you have to manage memory somehow
manually...

>> Linking in the runtime adds up to 14kb to a module, but the optimizer is
able to eliminate unused runtime code. Once WebAssembly exposes the garbage
collector natively, there'll be other options as well.

------
bernadus_edwin
Maybe someday xamarin can use this compiler

------
themihai
I assume it there is no DOM access, right?

~~~
colordrops
Not yet. Once GC is available it should not be far off.

------
cwyers
This links to a GitHub organization page, which is spectacularly
uninformative.

[https://github.com/AssemblyScript/assemblyscript](https://github.com/AssemblyScript/assemblyscript)
is a better link for this submission, I think. You get a README.md, at least.

~~~
bsimpson
Looks like their DNS is fucked up.
[http://assemblyscript.org/](http://assemblyscript.org/) redirects to their
GitHub org, even though there's a website repo in there that claims to be
[http://assemblyscript.org/](http://assemblyscript.org/).

Edit: apparently their website has no content, just a redirect to GitHub.
¯\\_(ツ)_/¯

~~~
zachberger
And if you look at the HTML file in the website repo it is redirecting to
GitHub. Not DNS' fault

------
lomnakkus
I can't but think that this is _such_ a "Hype Train" thing.

------
eyerow
You should reconsider the name "AssemblyScript" if you want it to catch on.

