JavaScript is Not Web Assembly
blog.izs.me
blog.izs.me
Mr. Schlueter is right on -- C++ is a much more accurate comparison, and especially so because it was originally implemented as a cross-compiler into C source code (circa 1983-1990).
That said, saying that the desire to compile into JavaScript is (to paraphrase the post) pathological language-wank craziness, is a bit extreme.
I'd like to think that the reason why CoffeeScript has caught on like wildfire, when there are so many other AltJS languages out there (https://github.com/jashkenas/coffee-script/wiki/List-of-lang...) is that we're trying to take the deeply pragmatic approach.
Mr. Schlueter writes "you don’t compile it to target a given platform," as if this would be an advantage or a justification for existing ... when it's really quite the opposite. JavaScript is plagued with libraries that will only ever run on certain platforms because they opt-in to platform specific features. I can't use your simple pluralization library to turn "bit" into "bits", because it was only written to run on Node.js, and is riddled with `forEach` and `require`, or because it was only written for the browser, and hides data in the DOM.
CoffeeScript tries very hard to compile into efficient, lowest-common-denominator JavaScript (read avoid Internet Explorer bugs) because that's how your library can be used widely across devices and runtimes, while being reasonably future proof.
I don't know when "order of magnitude difference" became a synonym for "worthwhile difference", but ... how much easier does a program have to be to read and write before it becomes a worthwhile choice to make the change? 2x? 1.3x?
In any case, CoffeeScript is a little thought experiment -- not a corporate project, or a Dart-like browser takeover. If it suits your fancy, use it, and if it itches you the wrong way, by all means leave it out.
Mr. Schlueter writes "you don’t compile it to target a given platform," as if this would be an advantage or a justification for existing ... when it's really quite the opposite.
I don't know when "order of magnitude difference" became a synonym for "worthwhile difference"
I didn't see Schlueter arguing either of these things, but we may have read the post differently. Both points, in my view, seemed only to illustrate that the JS-Assembly analogy is wrong, not to argue against to-JS languages.
https://twitter.com/#!/izs/status/114089739908415488
And to be extra clear, I appreciate the post, and agree with most of it.
"JavaScript is an assembly language. The JavaScript + HTML generated is like a .NET assembly. The browser can execute it, but no human should really care what's there."
JavaScript generated by CoffeeScript is very readable and thus does not exactly correspond to that concept of JS-as-Assembly.
edit: formatting
Debugging with GWT hosted mode is so ridiculously easy that readability is a non-issue.
Trying to treat JavaScript as assembly is silly because it doesn't vary too much between browsers- it is palatable to write, by hand, cross-browser JS programs, whereas it is literally impossible to do so in assembly because different assembly languages, as human-readable machine code, have virtually nothing in common at that level.
Treating JavaScript as C is the reality, because JavaScript is what gets run in different browsers (the analogy to compiling C to different platforms).
CoffeeScript is more like C++ than C because the language it's replacing/augmenting/etc. is very similar semantics-wise- it's just trying to make the same basic idea nicer to work with. The 10x difference thing is pointing out that C->assembly is a massive translation, whereas C++->C, while still a worthwhile difference, is much smaller.
Again, this is not a value judgement of CoffeeScript or GWT or anything. It's pointing out a flawed analogy. This is useful because when we think of JS as C rather than Assembly, it becomes clear that it shouldn't be the only option. It would be an improvement if, in the future, more mature language compilers could bypass JS to some form of bytecode (be it browser-specific, which would be a much bigger problem in the browser world, or a standardized one like the JVM does for the non-browser world... this is where the analogy breaks down a little).
CoffeeScript goes further than that and provides different syntax.
One of the things that complicates C++ is the requirement for source code compatibility with C. This necessarily requires preservation of confusing quirks.
CoffeeScript is not source code compatible with JavaScript.
This is important because C++ is damaged by the attempts to provide C source compatibility.
A compiler that did an 'identity compilation' on a strict
subset of real JavaScript, and rejected any problematic
or confusing constructs would have value.
It would. But it would be a linter, not a compiler.your expectations with coffeescript have always been great and in line with reality.
i think the frustration isaacs, and myself, have had with many other coffeescript users is that they expect us to take on the work of supporting it to the same degree we support development in javascript.
you have to understand that the purpose of the "javascript is assembly" mantra is to give the impression that writing applications in javascript is a waste of effort compared to using a JS-to language. it infers that there is an order of magnitude difference, which is why isaacs is calling out that it is not.
the mantra is very common when asking for others to do more work to accomodate coffeescript programmers. it gives the impression that our resistance to doing the work is because we all have grey neck beards and expect others to live in the dark ages of programming with curly braces.
C++ can be a "worthwhile difference" over C for some people. others hate it. it's a much more realistic comparison.
if everyone using coffeescript had your demeanor and expectations our world would be a much better place.
CoffeeScript has its own optimizations and error checking, but type annotations would allow you to also leverage Google's continuing improvements to the Closure compiler.
https://code.google.com/closure/compiler/docs/js-for-compile...
[1] http://www.ecmascript.org/
* You don't have to refresh the browser to develop, this is single largest productivity boost I've experienced in my 6 years as a JS developer.
* You can fully leverage JS prototypal inheritance (even on natives) because of ubiquitous namespacing
* You have access to macros - you can build the very features that people have been talking / debating about for years today
Unlike CoffeeScript (which I like and use), ClojureScript does lets you write correct code you would never write by hand.
How does it work?
At the moment it works best in Emacs, but people are starting to add support for other development environments.
After developing JS this way going back is simply painful.
fwiw, I'm an Emacs user, Lisp geek, and huge Clojure fan. I see the benefit of this, I'm just curious if not leaving my editor is the only advantage or if I'm missing something else.
So is the fact that you get to stay in Emacs the main selling point? Like I said, I'm just trying to understand.
2) Fix function in source file
3) Send updated function to browser
No clicking around, no copy and pasting.
I question your use of "only" able to use your own editor. There are myriad problems with using Firebug to write your code in: It doesn't save your code so if the browser crashes or hangs (which happens all too much with my installation of Firefox) you lose it; if Firebug starts behaving wonky (again, happens all the time) you lose it; you have to copy and paste the code into your editor once it's done; and, the editing mode itself is awful, of course. This is, as opposed to, say, MozRepl, which is instead convenient and safe. I assume the ClojureScript environment is as nice or nicer.
It's alpha quality, breaks and has to be restarted quite often. And a large part of webapp dev is testing code that is inaccessible from the global scope because of architecture (module pattern, etc). There is some magic however for dynamically loading Google Closure Library code that it wasn't compiled with, but I found setting up correct paths to include my own ClojureScript files to be tricky, especially doing so when targetting platforms with their own particular architectures (eg CouchDB/Couchapps).
That said, I think the op made a very good point about ClojureScript producing code that one would never write by hand. It's really the Clojure/Lisp idioms that are the win. The REPL an accessory, and a nice one, even moreso once the rough edges have been smoothed over.
https://gist.github.com/1177437
While this may look scary the pattern match compiler now emits precise errors (not shown here).
Also I mentioned to Brendan Eich that I created an 8 line ClojureScript macro to marry closures and prototypes.
https://gist.github.com/1214547
You would not write any of this stuff by hand.
ClojureScript lets you fully leverage the promise of JavaScript. I haven't seen anything else that comes even close.
The great thing about ClojureScript and performace is that ClojureScript get piped threw the google closure compiler with does dead-code elimination and some other optimizations.
I have not written any big enought app in ClojureScript that I could really tell but if you look at the compiler output you'll be surpised how little there is.
Cross-compiling a language designed to address JavaScript's numerous flaws into a safe subset of JavaScript for wide deployment seems like one of those ideas that we already have a noncontroversial word for -- polyfill.
Prediction: Someone writes a CoffeeScript to Dart cross-compiler.
It's not always reasonable to make inferences about the quality of a programming language by reasoning about its compilation target. It's probably never reasonable when you're talking about compiling-to-C, which is basically a macro assembler.
I was still having to deal with Cfront-based compilers (the one on HP-UX, for example) in 2002 or so. Amusingly enough, it actually had really good error messages.
https://github.com/kripken/emscripten/wiki http://news.ycombinator.com/item?id=1644192
Just saying'.
But "JS is the assembly of the web" is correct in the sense it is normally meant, which is "a language that you can compile into as opposed to writing directly for."
We are seeing that today, as the list of languages compiling into JS grows, and begins to resemble the list of languages compiled into assembly. Whereas the list of languages that compile into say C is much smaller.
So it is still a fair statement to call JS "the assembly of the web", at least as long as we understand what we mean by that.
Some people just don't like writing plain javascript, myself included. But then I do generally develop UIs which more or less behave like desktop applications, so the value of being able to plug in a few preset components is much more attractive, if I wanted a very customised feel to the components I used I guess it would have to be native javascript.
The critical issue, as you identified, is debugging -- whichever language solves this will probably win the space.
In the case of Javascript though, I don't think many developers were asked if they liked it ahead of time. Really it seemed like it was targeted for the much wider audience of "latent developers" who'd never used a debugger at all and wouldn't know to expect one.
This probably contributed to why it took so long for such debuggers to arrive.
Even without special support, depending on the compiler, sometimes it's not particularly hard to debug unless you're really not familiar with JavaScript. I don't think it's as big of a deal as people make it out to be.
It's rad that you're totally into CoffeeScript, but splitting hairs like this is silly. A lot of the metaphor comes from the fact that JavaScript is actually compiled down to assembly in software like v8. X to JS compilers can even take advantage of that knowledge as well and produce optimized JS for those compilers (I'm sure GWT leverages this) So yes, JavaScript is more like C in that sense, but C compiles so ridiculously close to assembly that it's practically just there to make system calls and memory management easy for you.
So, if anything Javascript is the common language of distribution, or the English of the web.
https://github.com/jashkenas/coffee-script/wiki/List-of-lang...
It’s fairly common these days to think of JavaScript as a sort of “assembly language for the web”.
That's definitely a simile, not a metaphor.
Upon seeing that article I was like "Oh yeah, I get the two confused all the time WTF?!"
Repeat after me: Javascript is just an in-browser scripting language. Period.
Yes. I know, it is possible to use JS on a server side, but you also can hack a VB run-time to send you some files via http. Wait, isn't that crap already exist and called Azure?
Unfortunately, JavaScript and its VMs have limitations that would not allow us to create very performant languages for some domains but I think we could have a lot of other useful higher level language to program (the web).
Who is saying that javascript is web assembly?
I've only seen one comment in the comments so far, and its weak at that. Yes no human can read Google's javascript, but that says nothing about its efficiency, optimization, or correspondence with machine language. http://news.ycombinator.com/item?id=2783060
Jeremy imagines correctly. This blog post was essentially a continuation of the subject on the node mailing list, and particularly the assumption that if you feel you shouldn't compile to JS, then you should just write in Assembly, or that JavaScript is only worth using if you want to be "closer to the metal". I believe that these points of view are wrong.
Yes, of course I'm aware that C++ was originally cross-compiled to C. That's why I chose it for the analogy, like Lassie on display in the Louvre. People tend to take comparison that as either a compliment to CoffeeScript, or an insult, depending on their feelings about C++ vs C. I consider both interpretations to be correct.
I have no problem with people compiling to JavaScript, though I personally prefer dealing with JavaScript directly. I like stack traces with line numbers that correspond to the line numbers in my editor, and it's not such a bad language. One of the biggest things I've found lacking with both Node and Browser JS is post-hoc debugging. Syntax sugar doesn't help with that. I'd be much more excited about efforts to produce state-capturing crash dumps that would let a developer revisit an error condition and investigate it after the fact. Other language have this, and it makes me very envious.
"Expressiveness" is a measure of how many tokens are required to write programs. Read some of pg's essays about arc and blub. A less than 10x increase would still be relevant, but.. well... meh. It's not a major leap in power that Assembly to C is, or C to JavaScript is.
Increases in expressiveness often come at the cost of also increasing the difficulty of reasoning about programs' precise behavior, but increase the ability to reason about their intent. Reading assembly isn't exactly fun (in my opinion), but it's also quite clear exactly what the computer is doing -- so much so that it can be tricky to figure out exactly what the human was trying to accomplish.
C is much more humane, and still pretty clear what's going on. It's an obvious sweet spot for many tasks. JavaScript, on the other hand, runs on this huge black box, but it's much more expressive than C (and thus, much easier to write), and it runs in web browsers (which makes it inescapable), doesn't require a compilation step, and is quite fast for a lot of tasks. I've yet to see any similar leap from a to-JS language. They're just other high level languages that all have pretty much the same basic set of features. A lot of them are a bit nicer than JS, but they lack JavaScript's relevance factor.
I must not be a very good writer, because people often read things I write, and seem to come away with the impression that I have these strong prescriptive views about syntax and coding style. I don't. The reason I'm so unenthused is because most high level languages don't really seem to differ all that much. Coding style doesn't solve very many problems, and the problems it does solve aren't particularly hard.
http://www.hanselman.com/blog/JavaScriptIsAssemblyLanguageFo...
JavaScript is the new universal web glue language. This is great, as is the fact that people are developing better-abstracted languages which compile to JS. But it's not any sort of "assembly language" unless you employ really confused semantics. I take issue with this for precisely the same reason that I take issue with using "Cloud" interchangeably with "Internet" or "Website".