JavaScript is Not Web Assembly
blog.izs.me
blog.izs.me
His whole argument depends on the comparison between Javascript and generally "Assembly" but as he argues against the label "Web Assembly" the proper comparison is from Javascript and X Assembly, where X may be X86 for instance.
> If you are designing a language, compiling it to JavaScript is a pretty attractive option, for much the same reason that compiling C to machine code is an attractive option: running it in more places.
No, you compile C to machine code because that is it's execution model, or perhaps because of performance. You do not "compile C to machine code to run it in more places" This however is not central to his argument.
> They’re mostly backwards compatible with JavaScript
Not languages compiled through the emscriptn model.
> You still need to grok the DOM, or node, or whatever other platform your program is interacting with, and that’s probably documented in JavaScript.
The same is true for compiled languages. The fact that they are often documented in C is just an artifact.
> They break almost all of the tooling that exists for JavaScript debugging
Anyone who has ever worked on a new compiled language knows that this is also problems of compile-to-asm languages.
> CoffeeScript programs don’t vary any less across architectures than the JavaScript programs it creates.
Again, this is true in the C->X86 ASM also.
> CoffeeScript does not offer an order of magnitude difference in expressiveness
This is the strongest point of his argument, but just goes to show that he takes the metaphor much too strongly, and misses the whole point of it in the first place.
There is literally no other language you can write in that will run against the following, Oh multiplex for osx, linux, windows, ios, android, symbian, and windows phone, blackberry, etc whenever possible: IE, Firefox, Opera, Safari, Chrome, Old android browser, webkit derivitives, etc. JS is the only language available everywhere so everything targets it. That's that. No other reason.
Ideally a bytecode would be created with standard libraries and a browser extension and js fallback for a more efficient language that even js can be compiled to. But we have this not atm.
A stack-based bytecode would likely yield the best code size (at least in the absence of compression). An SSA-based representation is most attractive from the standpoint translating to the most optimized native code. A register machine representation is a good happy medium for fast interpreters and pretty good tracing JITs. People also occasionally float the idea of shipping around compressed syntax trees to at least cut down on bandwidth usage and time taken to tokenize and parse JS, as a least disruptive option.
In the end, I think there are too many options and too many players with conflicting goals for a standards committee to come up with a solution that gets widely adopted, so we'll need the invisible hand of the market to sort out the competing ideas.
At present, I think the closest we've got to your ideal is LLVM bitcode via Google's PNaCl plugin. Emscripten can generate JavaScript from LLVM bitcode, closing the loop, but I'm not aware of any production systems that target PNaCl with an Emscripten fallback for browsers that don't understand PNaCl.
Edit: s/space usage/bandwidth usage/, note that compressed syntax trees are the least disruptive option. Those wishing to disrupt the browser language landscape probably don't want the least disruptive option, but it's probably preferable to a lower level representation that too closely matches the semantics of JS, as that would tend to force JS semantics deeper into the VM's implementation.
HOWEVER, we cannot. That's the issue. So JS is the web's most low-level language at the moment.
I imagine 99% of the time that metaphor is made the author would be just as happy saying "JS is the new C", it simply doesn't roll off the tongue as well.
Not that the original metaphor is wrong or useless; but thinking of javascript as C provides some glimpse into the risks of what made C++ problematic.
The author picks Coffeescript as an example of a fairly sensible approach to the problem, but "the language-wank crazy" are taking a lot of risky approaches.
And it's no surprise that we're getting lost in this; making arguments based on metaphors rather than the thing itself is a classic trap. We should make an effort where possible to talk about what JavaScript is rather than what it "is".
And you target JavaScript for precisely the same reason :) Perhaps the better way to say it is this: C is a language which was once written by hand, but which is increasingly being used as a target for higher-level languages. The same thing is happening to JS, but at least to me "JavaScript is the new C" is not a particularly useful way to express that similarity.
You're excluding a large chunk of compilers with those two generalizations. Targeting assembly rather than directly emitting machine code is extremely common (gcc being one of the obvious examples), and targeting C is very common for new/experimental languages.
Well, yes and no. I do agree that it often goes completely wrong and can be very misleading. But the JavaScript/assembly argument is more an analogy than it is a metaphor, and analogies are a very important function of intelligence and a tool for making important discoveries.
That said, I like your generalization "compile target" a lot more than calling JavaScript assembly.
If you're gonna make a point, make a point, it's that simple.
To be, or not to be: one could ponder:
Whether one's sense of self-worth increases
In direct proportion to one's ability to accept adversity,
Or to address challenges,
And in so doing solve said challenges?
Personally, I prefer the original: To be, or not to be: that is the question:
Whether 'tis nobler in the mind to suffer
The slings and arrows of outrageous fortune,
Or to take arms against a sea of troubles,
And by opposing end them?
[Apologies in advance for the inevitably botched translation.]And of course entertainment is yet another game. Any sort of serious argument in a work of entertainment is probably trying to fly under the radar of skepticism anyway... Dang it. Point is, fiction is not usually a good model for rational discussion.
An array of points in C: http://s3.mrale.ph/images/array-of-points-structure-c.png
An array of points in JavaScript: http://s3.mrale.ph/images/array-of-points-structure-javascri...
These are the things that Javascript has been growing to facilitate the idea of js as asm. Emscripten uses ArrayBuffers to allow C to compile to JS without the messiness.
Actually, you don't know that. Since doubles are immutable, the runtime can (and does) cheat, including turning many of them into integers. It all boils down to predictable usage patterns.
I think that is the core of the analogy, and it is not talking about how high or low level each language is in an absolute sense but in a relative sense. It is talking about it being the "at the metal" language of machine instructions and browser "instructions" respectively.
Of course, there are other parallels, but they aren't as strong. Part of the reason for using CoffeeScript is because of a perceived increase in expressiveness, but that increase is very small compared to the improvement of C over assembly (as the author of this article points out).
that's just uninformed. both analogies are wrong. but yours is even more so.
c++ is usually compiled down to assembly w/o going through c (there have been a few but it has not been mainstream for _many_years). so coffeescript or any other to-js language is _not_ the c++ of the web! the author implies, that (say) coffeescript is to js as c++ is to c.
but before (s)he gives two reasons about c over assembly.
1. assembly is variable, c is a constant, 2. c is way more expressive.
there is some truth in the first on, that one does not hold for js. whether it really holds for assembly is debatable given how much porting is involved for arm devices. and if you think about asm.js you might think that's a different assembly (js to asm.js is like asm to simd instructions maybe?).
the second point might not hold for coffeescript, but look at closure, fay or elm. they are very distinct from javascript.
What do you mean "some truth" .. different CPU architectures have different assembly language .. what's to get?
Oh, and SIMD instructions are an extension to the x86 instruction set .. not an abstraction.
What is your background on low level development, may I ask?
i tried to address the analogy which is implied by these two points. and it is true, that for coffeescript on javascript, coffeescript is not more constant and js is not more variable. but that's not the point of the argument javascript were the assembly of the web. the point is, that all these languages compile down to js. as c and c++ compile down to assembly.
and honestly the "c is constant" is not right some of the time either. consider small/big endianness, different libcs. heck, even the syntax changed (k&r surely looks and feels different).
my comment on simd instructions to assembly was an analogy to asm.js and javascript.
What I find funny about this remark was that I think it was intended to be disparaging because the meme these days is that C++ sucks.
But C++ is actually wildly successful and is the bastion of many very large, complex, fast, applications that would be very challenging to write in vanilla. Yes, you can stick to just C, but many many programmers have profitably switched to C++ instead. Almost the entire game industry, most desktop applications that people use for their jobs, web browsers and even JavaScript engines themselves are all written in C++.
If the new crop of compile-to-JS languages are in a similar boat, then sign me up!
True, but I find that its real power is in not forcing me to remember all sorts of crazy-ass stuff that's only relevant because JavaScript, as a language, is just sort of batshit crazy.
Case in point: I'm doing some work right now that requires me to use JavaScript[1]. Today, I was writing your typical 'is this variable undefined or not?' if-clauses:
if (typeof foo !== 'undefined') { bar(); }
Obviously, I don't do this enough, because I ended up having to look the stupid thing up instead of just knowing it ("I know I have to use === for equality; is the equivalent 'not-equals' version only two equals signs or three?", and so forth).In CoffeeScript, in comparison, I'd simply write:
bar() if not foo?
It takes a lot less mental energy for me to remember the second version than the first.Also, if I had a nickel for every time I've had to write var that = this... Anyway, suffice it to say that CoffeeScript may not be an order of magnitude more expressive, but it's cheap enough to get up and running that its benefits are well, well worth it to me.
[1] It's an iOS app that has a critical component built into a UIWebView, and there is absolutely no way to make this stuff native, seeing how it's rendering HTML. I guess I could rig up some awful build phase voodoo that would compile my .coffee files, but that sounds ridiculous.
The more high-level the thing you're trying to hide is, the more likely it'll keep peeking out from underneath your abstraction layer.
"Assembly varies wildly between architectures" - but javascript runs on a single architecture. it's just that browser vendors all implement the same one.
the other points are valid, but i dont think this was ever supposed to be that deep a comparison.
This exactly. JS is the lowest level of code you can reliably run through a browser. That makes it, by definition, the 'metal' of the web. And that will probably not change for a very long time.
That is, the C you get out of a language that is doing optimization of high level stuff into legal, portable C as a compile target is not the language you'd use if you, a human, were coding in C.
And this is very analogous to, for example, the code generated by a high level language targeting modern JS. It's going to allocate stuff on arrays, and use cryptic pointers, and do things the odd way around when it turns out to be faster. It's going to have unhelpfully named variables, and no unnecessary whitespace or comments, and it's going to operate silently on dangerous-looking assumptions that it's proven safe at a higher level.
Sure, generated C interops easily with manual C, just like generated JS interops easily with traditional hand coded JS, but they have little in common except their formal grammar.
Now, if you say instead that it's low-level ("assembly"), fans of JS feel smug about using it instead of being offended.
However, at the same time you hint that JS is something which shouldn't be written by humans.
Point well made.
I also don't think that comparing one's language to C++ is necessarily a good way to advertise it. ;)
Of course JavaScript has more in common with C than assembly, but context matters.
I just don't see the utility of pre-processors for JS or CSS. I know I'm in the minority here, are developers really working without debugging? I can't wrap my head around that workflow.
[0]: http://www.html5rocks.com/en/tutorials/developertools/source...
I'm not sure how CSS comes into the discussion, it isn't executed, and thus isn't debugged. And things like SASS and LESS are fairly simple, straightforward pre-processors.
>I know I'm in the minority here, are developers really working without debugging?
I don't think so. You couldn't pay me enough to write javascript. But I have to end up with some javascript because browsers don't support anything reasonable. So I use a haskell -> javascript compiler. I still have to read javascript to debug what is going wrong, but at least I don't have to write it.
There are things that you simply cannot do in JavaScript that you can in assembly. Many of those are horrible practices with little use. In assembly, if the computer can do it you can do it. C retains most of those abilities because it compiles to Assembly/Machine code.
How does one even write the unix cat command in JavaScript? The structure of while(read())write() does not go down well in JavaScript.
JavaScript needs to be able to fork, wait and preempt if it wants to be assembly.
Urgh. Way to completely not understand the "assembly of the web" metaphor. OF COURSE JavaScript is not literally like assembly.
Brendan Eich has argued against a bytecode vm approach to a low level powerful system, saying that Javascript can provide that low level functionality. This is very much the viewpoint that the capability can be considered comparable to assembly.
I don't think that is correct but I recognise that that is what some people refer to as assembly for the web.
I really don't care what it is called and what metaphor is used, that is all trivial compared to the fact that Javascript is not up to performing all the tasks that it should be able to do if it wishes to be a comprehensive platform.
Like what?
Because people have been writing huge programs in plain JS just fine.
More often than not, Coffeescript is used for plain vanilla front end code, the kind of that people can do in JS with their eyes closed.
http://www.hanselman.com/blog/JavaScriptIsAssemblyLanguageFo...
I like the comparison of Javascript = C of the web versus Javascript = assembly of the web.
The to-JS languages are nothing like C++, you just don't need to compare in this way, these things are apples and oranges.
The JVM is more like the assembly target of the web, and it's a horrid failure in security and stability. Maybe some folks should start anew with something like LLVM as a target, with the first conversations about security. That would probably suck too, though.
Things don't have to be the Things of Things. That's what we should take away from this.
In many languages, C is the output of the compiler. C's treated as portable assembler. I think that's the proper analogy here. Those languages don't have something lower-level than C.
This sentence badly written. The point of the article is that Javascript is the C of the web, and if this sentence were put together correctly it would make the point.
I feel like the author should be given a lesson in rhetoric.
I don't see if there's any reason it would be impossible to build a compiler for a very high level expressive language like say Haskell and have it generate javascript code that would be well optimised for a particular runtime (maybe via asm.js).
The article seems to make the argument that javascript is not analogous to assembler because coffeescript is basically just syntactic sugar.
Argument 3, "You still need to grok the DOM, or node, or whatever other platform your program is interacting with, and that’s probably documented in JavaScript." is especially weird because I don't see how that isn't true with assembler also.
Asm written for Windows is going to be doing different stuff to asm written for Linux.
If instead the game has to be downloaded and installed, chances of someone bothering are almost nihil.
I have a feeling that people place a higher value on games that they install anyway (I know I do) and may be more likely to replay it if it's in their Steam list or has an icon on their desktop. Whereas flash games are often seen as pretty disposable.