
CIL (.NET bytecode) to WebAssembly compiler - vmorgulis
https://github.com/WebAssembly/ilwasm?test
======
aikah
Finally , people will be able to get rid of javascript wholesale . No
transpilation , asmjs whatsoever. It basically means that javascript will die
in the long run and people will be able to use whatever language they want to
use, actionscript , java , c# you name it. That's a game changer and it's a
future standard , so no plugins.

~~~
jeswin
I welcome being able to use any language. But,

> No transpilation

You'll have to compile instead.

> people will be able to get rid of javascript wholesale

Modern JS (ES6+) isn't worse than Java or C# in terms of expressiveness. In
fact, it might even be better in some cases.

No other language is going to come with built-in tools for editing within
browser/client dev tools. Modern JS is going to be one of the easy languages
to get started on.

And of course, you totally underestimate the billions of lines of JS already
written for the Web.

~~~
lqdc13
I tried JS multiple times. And every time, easy things are complicated when
doing them in JS. It is much easier and faster for me to do those same things
in C, even though I'm equally familiar with both. This is mostly because there
are just so many gotchas.

Here are some examples from this week:

Checking whether a passed argument is an array or a dict:

    
    
        var a = []
        if (Object.prototype.toString.call(a) !== '[object Array]') ...
    

(perhaps not js itself, but how it is used) Leaking DOM nodes are a thing:
[https://developer.chrome.com/devtools/docs/heap-profiling-
do...](https://developer.chrome.com/devtools/docs/heap-profiling-dom-leaks)

Easy things like getting values of a dictionary:

    
    
        var d = {
            a: [1,2,3,],
            b:[4,5]
        }
        var values = Object.keys(d).map(function(key){
            return d[key];

});

in Python, it's just .values()

Errors aren't thrown when there are obvious issues with the code.

String.replace replaces one instance instead of all instances in a string.

Functions arguments are a bit of a mess.

differences between

    
    
        for each (var myVar in myObject)
        for (var myVar in myObject)
    
    

random things like these:

[http://stackoverflow.com/questions/2568966/how-do-i-pass-
the...](http://stackoverflow.com/questions/2568966/how-do-i-pass-the-value-
not-the-reference-of-a-js-variable-to-a-function)

All the things here:

[http://www.toptal.com/javascript/10-most-common-
javascript-m...](http://www.toptal.com/javascript/10-most-common-javascript-
mistakes)

If you import a library, they could have modified the global scope. This is
common in JS libraries. Then some things you wrote don't work.

undefined/null thing

differences between var declared function and regular named function.

Many things in the language are not obvious and you have to discover them
through trial and error or study JS internals and find out how things are
implemented.

~~~
kolme
> Checking whether a passed argument is an array or a dict

Luckily solved in ES2015:

Array.isArray(thing)

The toString trick is pretty outdated, in ES5 you can also do:

thing instanceof Array

> (perhaps not js itself, but how it is used) Leaking DOM nodes are a thing

Definitely not JS itself, it's easy to create circular references between JS
objects and DOM elements. It's just the way the DOM is (poorly) designed and
the way it interacts with JS.

> for each (var myVar in myObject)

That's not even standard, just a Mozilla "dialect". I don't think that's
supported by any engines other than SpiderMonkey and predecessors.

~~~
gsnedders
>The toString trick is pretty outdated, in ES5 you can also do:

> thing instanceof Array

instanceof is ES3.

> That's not even standard, just a Mozilla "dialect". I don't think that's
> supported by any engines other than SpiderMonkey and predecessors.

To quote MDC:

> The for each...in statement is deprecated as the part of ECMA-357 (E4X)
> standard. E4X support has been removed, but for each...in will not be
> disabled and removed because of backward compatibility considerations.
> Consider using for...of instead. (Please refer to bug 791343.)

~~~
lqdc13
So now we have ...

    
    
        for each (var x in a) ...  <<Firefox only??>>
        for (var x of a) ...  <<ES6>>
        for (var x in a) ...
        a.forEach(callback[, thisArg])
    

Knowing JS, each of them have their own quirks probably.

~~~
kolme
Yes:

for each (...) -> It's not supported anywhere, so forget it.

for (var x in a) -> x is the key, so it's kind of inconvenient. You have to
watch out for inherited properties/methods so one should check for
a.hasOwnProperty(x).

for (var x of a) -> It has mostly no gotchas. Only poor browser support.

.forEach only works with arrays and from ES5 on. You have the good old
"this"/scope gotcha.

------
ianlevesque
Neat. I keep hoping for one of these to evolve into a more modern replacement
for Silverlight or WPF. There's a lot to like about the .net ecosystem and
having a plugin-less deployment story for it would be great.

~~~
tracker1
I was really hoping that Silverlight would gain more traction than it did...
for that matter, it's far closer to what I was hoping for when Adobe bought
Macromedia. I had been hoping to see a _new_ flash container format that was
similar to what Silverlight became using SVG and MP3 with JS as it's main
interfaces in an open structure (for the format and player), Adobe could have
stayed king of tooling... Flash and Flex are still way better in terms of
tooling for some relatively complicated presentations, simulations and the
like for a browser than what you now need to hand code with current standards.

It really takes something like WebAssembly which multiple browser vendors back
to get traction... Adobe was in the position to give us this almost a decade
ago.

------
ftcHn
This is exciting stuff for c# devs. I dream of writing isomorphic web apps in
c#.

Is there a runtime environment for executing wasm available yet?

~~~
kevingadd
The ml prototype in the draft specification repository
([https://github.com/WebAssembly/spec/tree/master/ml-
proto](https://github.com/WebAssembly/spec/tree/master/ml-proto)) is the
closest thing at present. ilwasm targets that presently.

------
derefr
Does this bring in all of the MSIL for any .NET stdlib modules you happen to
link in as well, or is there a dead-code elimination phase pruning them down
to just what you use?

~~~
ianlevesque
It looks like at the moment it doesn't support the stdlib at all. Early early
prototype.

------
rottyguy
Do note that aspnet just released their beta7 yesterday and the *nix port of
.NET is coming along nicely.

[http://blogs.msdn.com/b/webdev/archive/2015/09/02/announcing...](http://blogs.msdn.com/b/webdev/archive/2015/09/02/announcing-
availability-of-asp-net-5-beta7.aspx)

------
hacker_9
Holy s __* yes!!! Finally web dev moves in the right direction! JS developers
will finally realise how bad they 've had it.

~~~
tracker1
Yeah... I mean give me layers of interfaces, indirection and dependency
injection that's hard to follow. Class structures that don't flow well for
procedural workflows. Projects with dead end code paths because they are so
big no one person understands even half of it. I mean, these are such great
things.

I've totally missed them in modern JS development, and haven't been fighting
against many of these practices for years now at all (/sarcasm).

Seriously though, my biggest issue with JS development today is people that
don't understand patterns beyond what they use in C# and Java, and don't want
to keep things simple and easy to reason about. Most C# and Java applications
I've worked with have many layers of unnecessary complexity for the sake of,
more because "that's how it's done in 'Enterprise' software" more than it is
about what's truly needed.

I actually really like C#, and the thought of being able to use some of the
features really appeals to me. That said, actually working with solutions
common from .Net, I've been happier without it. I've spent the better part of
my time the past 4-5 years migrating away from .Net solutions to Node based
ones... once you get past people trying to implement overly complex patterns
and embracing "the node way" of simple, composable, functional modules... it
can and does go much more smoothly.

\--- edit:

When I say complexity for the sake of... it's usually for the purpose of
testability, often in scenarios that don't have tests, and beyond that aren't
trying to target multiple implementations of an interface. Even then, with JS
you don't need the added constraints. I know there are "contract" concerns,
but what that gets you is WS-* and SOAP/WSDL hell that nobody really
understands vs easy to reason REST/JSON services. In the end, having simple
systems where you have to learn a bit of convention tends to be easier than
complex systems with layers of indirection.

------
interdrift
Can someone summarize what one could accomplish using WebAssembly with a
statically typed language as c#?

~~~
hacker_9
I've worked with both C# and JS for a number of years and to sum up why static
typing is ultimately better than dynamic typing, is because of the type system
which gives you compile time errors.

As programmers on the computer all day, the more work the computer does for us
the better. With a type system the computer knows what the system is capable
of, and so knows what you are doing - this means it can tell us precisely what
members are available in 'foo' when you type 'foo.', and it can accurately
tell us that 'bar' does not exist in foo when you type 'foo.bar'.

With systems of even minor complexity this is a godsend when you don't have to
even read the documentation of a new API you want to use - you just use the
autocomplete and contextual documentation to figure things out. It makes code
fun again.

With dynamic typing, and especially with JS, the computer is mostly oblivious
to what can/cannot be done and you end up having to ctrl+F on method names,
mispell something and it just gets added as another variable to the type, you
can't refactor variable names easily etc. It's pretty bad in comparison.

Static typing isn't all perfect though - sometimes types do get in the way
where I wish more dynamic features would have been available. But at least now
if C# etc can be used for webdev, then solving these problems will become
something people will invest time in and we will finally see new innovation
again - instead of yet-another-javascript library/hack.

~~~
pingec
I have also been doing C# and JS for years and completely agree. JS is nice
for prototyping because of the light footprint but as soon as your code gets
more complex it becomes a problem to manage/maintain, far from impossible,
just harder. From this perspective TypeScript is a godsend.

------
zamalek
I thought WASM didn't [yet] have a GC. How are they dealing with memory
management?

~~~
JosephRedfern
Can't you just let the browser handle the GC? I don't think this is a port of
Mono to JS - i.e. it's not a new runtime.

EDIT: A: No, you can't.

~~~
aardvark179
WASM models memory as a big array which is your heap, all memory management
within that is up to you. There is no GC, there is no new / delete or anything
else. For the use case of porting C programs to your web browser this is fine,
for higher level languages you're a bit stuffed.

I hope WASM gains some sort of GC eventually, because writing a GC in WASM
will make me cry. :-(

~~~
JosephRedfern
Ah-ha! I see - apologies, I'd misunderstood.

------
vyrotek
Would anyone be kind enough to explain what exactly I'm looking at here? I'm
very familiar with C# but only have a very simple understanding of the idea
behind WebAssembly.

~~~
kevingadd
The WebAssembly design repo
([https://github.com/WebAssembly/design](https://github.com/WebAssembly/design))
has a bunch of high and low level details. Essentially, wasm is a spec for an
instruction set and runtime environment for native apps, and it's designed so
that existing JavaScript runtimes can support it. This will eventually let it
solve most of the problems currently solved by asm.js, NaCL, and (to a lesser
degree) NPAPI.

------
ftcHn
While writing C# with strong types for the browser is a nice idea, this
project won't give you strongly typed access to the web api e.g. window. JSIL,
which this project is based on, gets around this by making window and other
objects available by the dynamic keyword.

You can still strongly type everything within your project but creating a
complete strongly typed wrapper to the web api would be a big job.

------
vlastachu
Is it only proof of concept? If no: How they develop compiler to language with
incomplete spec?

------
anjanb
So, where's the JVM to WebAssembly compiler ? I googled for it and couldn't
find any ?

~~~
gldalmaso
This is what I could find on the subject:

[https://groups.google.com/forum/#!topic/google-web-
toolkit-c...](https://groups.google.com/forum/#!topic/google-web-toolkit-
contributors/sZ8H80Fw5mU)

 _My thoughts are pretty much exactly what Colin said.

Without GC it's not a reasonable target for Java cross compilation because
you'd have to embed your own GC implementation into the output.

That being said, they plan to add GC, which will make it more attractive._

------
fekberg
Originally posted yesterday:
[https://news.ycombinator.com/item?id=10156709](https://news.ycombinator.com/item?id=10156709)

~~~
dang
Yup, but reposts are fine when an item hasn't had significant attention yet
(see
[https://news.ycombinator.com/newsfaq.html](https://news.ycombinator.com/newsfaq.html)).
That helps offset the random churn of /newest, which otherwise causes many
good stories to fall through the cracks.

Indeed, we invited vmorgulis to repost this one, which we sometimes do when a
good submission didn't get much attention the first time. I've written about
this at
[https://news.ycombinator.com/item?id=9866140](https://news.ycombinator.com/item?id=9866140)
and
[https://news.ycombinator.com/item?id=8790134](https://news.ycombinator.com/item?id=8790134)
if you're interested.

~~~
fekberg
Thanks! I thought re-posting was frowned upon, no matter if the content is
considered good or not. I'll check the links!

