10 ms·
JavaScript is Not Web Assembly
- tptacek 15y agoI wonder if the author would be surprised by how many language compilers have targeted C for their output.
- hbien 15y agoI don't think he'd be surprised. Didn't C++ initially compile to C? He mentioned how these "to-JS" languages are more like C++ to C than C to assembly.
- tptacek 15y agoC++ only briefly compiled to C, but compilation-to-C is a time-honored compiler building trick. 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.
- ajross 15y agoNot even briefly, I'd say. Cfront-based compilers were the rule rather than the exception well into the 1990's. It wasn't until the death of proprietary Unix and the emergence of msvc and gcc that the world got used to the idea of C++ being a first class language.
- tptacek 15y agoYou're probably older than I am. I started my career in C/C++ and I've never used a Cfront-based compiler. (My first dev job was in the mid '90s).
- bzbarsky 15y agoSo C++ had existed for 10+ years by the time you started with it, right? 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.
- marshray 15y agoBorland/Turbo C++ did it for a lot of us too.
- _delirium 15y agoI can't seem to find the discussion now, but the C-- people (http://www.cminusminus.org/ http://www.cminusminus.org/) found that compilation-to-C was a requirement from some large companies, at least as a backup path, for anything not solidly established. Companies wanted to know that if this fancy new thing's maintenance dropped off a cliff in 10 years, they could at least compile to C, and thereby leverage C compiler ports to new architectures, rather than depending on a straight-to-asm path that may or may not be maintained decades from now.
- scott_s 15y agoI assumed that knowledge is what prompted the comparison.
- tptacek 15y agoI know he knows C++ targets it, but I get the impression he thinks that the result of targeting C is a language like C++. That's not the case. Good languages have also been compiled to C.
- evilduck 15y agoWe might as well go full circle :) https://github.com/kripken/emscripten/wiki https://github.com/kripken/emscripten/wiki http://news.ycombinator.com/item?id=1644192 http://news.ycombinator.com/item?id=1644192
- 5hoom 15y agoI know it's just an off-hand little dig at C++, & I'm sure you know more than enough about C++ to be confident making such a dig, but damn the relentless C++ bashing gets really old to those of us who are happily productive with it. Just saying'.
- sherkund 15y agoIt's a metaphor.
- marshray 15y agoThe first sentence is: 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.
- stickfigure 15y agoA simile is like a metaphor.
- marshray 15y agoCertainly moreso than Javascript is like assembly language. Upon seeing that article I was like "Oh yeah, I get the two confused all the time WTF?!"
- seldo 15y agoWhile I completely agree, C++ is both useful and popular, so these to-JS languages will continue to proliferate. The critical issue, as you identified, is debugging -- whichever language solves this will probably win the space.
- tptacek 15y agoThe idea that debugging tools should determine how Javascript is generated or written baffles me. It's only been over the past few years that we've had any credible Javascript debuggers. The debugger builders will adapt to whatever the developers use. The horse pulls the cart.
- seldo 15y agoI think a major step in the development of complex javascript apps was the development of real debugging tools for Javascript. Prior to that, the barrier to a complex JS app was too high for the hobby developer.
- marshray 15y agoIt seems logical that developers will prefer a language that has a good toolset. There are certainly languages I don't develop in as much due to the lack of a compelling debugger (e.g., Lua). 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.
- tlrobinson 15y agoThe browsers are working on a generic solution by providing a way to set source-to-compiled line mappings for the debugger. 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.
- chc 15y ago
- swannodette 15y agoI think anyone who thinks this should take a good long, long look at ClojureScript. * 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.
- scott_s 15y agoI don't think your points disagree with his eventual point, which is that JavaScript is the C of the web.
- swannodette 15y agoThe following code looks pretty assembly-like to me ;) This is my state-of-the-art pattern matcher for Clojure working w/ ClojureScript. https://gist.github.com/1177437 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 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.
- scott_s 15y agoIt also looks like the kind of code one would generate when C is the target language.
- swannodette 15y agoSure before Google Closure takes an optimization pass at it. Anyways, I don't really think it's a point worth debating to death - I defer to Erik Meijer.
- Locke1689 15y agoThis is a stupid debate over language. What people mean when they say Javascript is web assembly is that Javascript is a compilation target, which is completely true.
- jibbit 15y agoAbsolutely. I never heard anyone actually say “blah is to JS as C is to Assembly” nor did i take them to mean that when they said "Javascript is web assembly"
- anshargal 15y agoThe question is -- is it cool to be "low-level" guy and write on pure "low-level" JavaScript or it is not. It seems currently it is not as cool as to code real assembly.
- jashkenas 15y agoI usually try not to weigh in on these debates -- I imagine https://groups.google.com/forum/#!topic/nodejs/a7yVzBw1sJk https://groups.google.com/forum/#!topic/nodejs/a7yVzBw1sJk is what triggered this post. But... 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-languages-that-compile-to-JS 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.
- mvzink 15y agoI'm bothered by these bits: 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.
- jokull 15y ago.. so he likes CoffeeScript? I'm not sure I grok the complaint or general message of the blog post. I've never actually heard "Assembly of the web" in relation to JavaScript. A link to earlier discussions that sparked this post would be useful, because I think there might actually be a takehome point in there somewhere : )
- jasonwatkinspdx 15y agoYou're correct. It's also a somewhat pointless clarification.
- deleted 15y ago[deleted]
- juiceandjuice 15y agoAnd assembly is just abstracted bytecode in a certain syntax. 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.
- javascriptlol 15y agoThe problem with JavaScript targets is not the terminology, but how bad the design of the whole web stack is. It's like watching people badly redesign operating systems in the browser, every so often catching up to something that was solved 20+ years ago on the desktop. Painful.
- andjones 15y agoI have an issue with the general premise of this article. 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 http://news.ycombinator.com/item?id=2783060
- georgieporgie 15y agoThis whole thing is weird (and stupid). I listened to the Hanselman interview with the guy who started pushing the concept of JS as Assembly. He came across to me as being really confused. He seems to conflate the concept of a .Net assembly, with "assembly language". I got the impression he had never written anything in assembly language, and didn't understand that it's a minimal mnemonics + macro layer over actual byte code, not something highly portable, and not something that "assembles" components together. http://www.hanselman.com/blog/JavaScriptIsAssemblyLanguageForTheWebSematicMarkupIsDeadCleanVsMachinecodedHTML.aspx 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".
- benfle 15y agoWhat would be very interesting to talk about (instead of entering into the details of an innocent analogy) is a toolkit that would make very easy to create new higher level languages on top of JavaScript. 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).
- azakai 15y agoTechnically speaking the article is correct: "JS is the assembly of the web" can seem misleading if one means assembly as "machine-specific code". 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.
- politician 15y agoI have to admit that I just don't understand the value of this discussion. Regardless of whether JavaScript is like assembly or C or C++ or MSIL or punch cards, I'm pretty sure all of us have heard of cross-compilation and that many of us realize the value of targeting the installed base (which is why we supported IE6 during the dark years). 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.
- stottc 15y agoAssembly = "as low as you can go". You can always build things on top of it, but you can never go any deeper. Javascript shares that much. Not too much else.
- schiptsov 15y agoOver-simplifications and over-generalizations are ones enemies rather than friends. We didn't say that Visual Basic is an assembly language of an office or AutoLisp is an assembly of construction business. 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?
- tybris 15y agoMeh, this is just about wording.
- turtle4 15y agoI agree. The point of the original statement was just to show that you should be compiling to javascript, not writing javascript. This article is technically right, the original comparison isn't perfect, but it is really splitting it fine.
- yason 15y agoJavaScript is more or less a (potentially standard) language runtime, just like JVM or CLR--just more compatible and more widely and natively supported. I don't see the need for a strictly binary or bytecode runtime either since parsing and interpreting/compiling JavaScript further inside a browser or other native environment is "fast enough" for many definitions of fast. Certainly faster than booting JVM :)
- horofox 15y agoI think this is a pointless blog post annd all the comments here are worthless.
- edtechdev 15y agoThere are literally dozens of languages that compile to JavaScript already: https://github.com/jashkenas/coffee-script/wiki/List-of-languages-that-compile-to-JS https://github.com/jashkenas/coffee-script/wiki/List-of-lang...
- ses 15y agoWhether or not javascript is analagous to assembly language, I find 'compile to javascript' frameworks such as GWT, GWT-Ext, Vaadin and Thinwire very compelling to use and allow for a consistent and cohesive presentation layer in rich web apps. Unfortunately all of these great platforms are Java based and I would really like to see the same approach adopted for other languages. 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.
- IsaacSchlueter 15y agoI'd like to respond to a few of the comments here. 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.