
JS is Assembly Language for the Web: Brendan Eich, Crockford, & others comment - mbrubeck
http://www.hanselman.com/blog/JavaScriptisAssemblyLanguagefortheWebPart2MadnessorjustInsanity.aspx
======
gambler
How about Rube Goldberg Virtual Machine of the web? I don't see what people
are so happy about.

It looks a bit like the thing that happened with XML. In years 2000-2005
developers got really, really excited about XML, and started to use it for
_everything_. Everything, including things that it was never meant for. And
yes, the resulting technologies worked (kind of), but they caused more
problems than they solved. SOAP/WSDL. XSLT. All that XML-to-SQL-query stuff.

Right now people are really excited about JavaScript and begin to use it for
things that are less and less appropriate for it. Yes, you can compile
languages into JS, just like you can use XML to generate an SQL query. But is
it really a good idea?

~~~
skrebbel
The analogy fails because using XML is, often, a choice. You _can't_ get
around JavaScript if you want to make a decent web app. The platform dictates
it.

~~~
VMG
The analogy works in the way that maybe sometimes you shouldn't do a web app
but a native client. I don't agree with the conclusion but I think it's what
he meant.

------
narrator
JS is ubiquitous because it's the only runtime that MS has ever bundled with
Windows that was more or less compatible with other non-MS implementations
running on non-MS platforms. It also does not utilize obfuscated and
constantly changing object code formats, which is MS's forte.

~~~
daeken
> It also does not utilize obfuscated and constantly changing object code
> formats, which is MS's forte.

CIL is insanely simple (I've written a CIL->x86 compiler in a matter of hours)
and has only had small, incremental changes since the very first version.

Are there really any examples of what you're talking about outside of the
Office team?

~~~
copper
I assumed he referred to the PE file format, but it looks like Microsoft
actually makes a spec available for it.

~~~
daeken
Well, they have _a_ spec for it, but it's not very good. That said, despite
PE's history, it's remained largely the same for what, 15 years? Small changes
to support various things, which make parsing arbitrary PEs a pain, but it's
not bad considering its age.

------
takeoutweight
Forgive me for parroting the thoughts of those smarter than me, but there was
an engaging debate on Lambda the Ultimate recently on how terrible JS is as an
assembly language: <http://lambda-the-ultimate.org/node/4308#comment-66084>

~~~
cageface
The success of JS is _the_ strongest case for the worse-is-better argument
that I can think of.

~~~
cturner
It's just dumb luck and path dependence. If Netscape had put scheme into
Navigator we'd be using that instead.

~~~
cageface
I doubt an s-expr language would have been palatable, but if Eich had taken a
few years to really get the browser language right it would never have taken
root like JS has.

~~~
olavk
I don't see the problem with s-expressions? It would be a nice symmetry -
pointy brackets for markup, round ones for code. Eich have stated that he
intended to create something like scheme for the web. The Java-inspired syntax
(and name) were chosen for marketing reasons, not technical reasons.

He couldn't just have used scheme wholesale though, since a major part of JS
is the integration with the DOM. He would have needed to create some custom
object system anyway to support that. So it would have been a new language
anyway, and due to the time constraints at the time, it would probably have
had the same amount of bugs and mistakes that JS ended up with.

------
consultutah
For an example of JS truly working like assembly, see here: <http://jsil.org/>

~~~
edsrzf
Another project in the same vein: <https://github.com/kripken/emscripten/>

------
perfunctory
Comparing JS to assembly is quite silly.

> Shaver's right, assembly without a great macro processor is not good for
> programmers or safety. JS is. So the analogy needs some qualification or it
> becomes silly.

This way you can compare anything to anything else and then try to qualify.

~~~
BrendanEich
Comparison != Analogy. Analogy != Equivalence. Equivalence != Identity.

Don't they teach this stuff any more?

------
dreamdu5t
What a horrible, horrible analogy. It doesn't even make sense.

Why not just say "JS is the common language of the web" without the horrible
analogy.

~~~
kenjackson
Because "JS is the common language of the web" doesn't capture what the
analogy is saying.

The key aspect of the analogy is that you have compilers emit or JIT to JS,
rather than writing if yourself, and then have languages/DSLs that users write
to, rather than JS.

~~~
cageface
You can do that with almost any language. The analogy holds in that you can't
get _underneath_ JS in a browser but if you were to design a browser language
with this kind of usage in mind it seems you'd want something that was a lot
easier to optimize than JS. JS clearly was a language that was designed to be
written directly.

~~~
kenjackson
_The analogy holds in that you can't get underneath JS in a browser_

Yes. That's why JS is the target (and its ubiquity).

 _but if you were to design a browser language with this kind of usage in mind
it seems you'd want something that was a lot easier to optimize than JS_

JS isn't turning out to be too bad to optimize. Post-lower optimization
already occurs in the browser. The part the compiler would do is optimization
prior to emission to JS.

~~~
erikreppen
Knowing the ins and outs of the DOM API implementations can get a bit arcane
but optimizing JS is mostly about work avoidance and making sure you know how
to make the native-code-implemented methods work for you to avoid putting
extra work on the JIT/interpreters. You have to maintain a knowledge-base to
be strong at it, but it can be very rewarding to see how much more you can get
out of your code with a little bit of thought and study. The analogy also
holds in that JS is extremely flexible and denies you very little. You can
design and code to most any paradigm you want although I suspect attempting to
implement static typing would get a little silly where numbers are concerned.

------
schiptsov
What powerful drugs they're using to produce such great distortion of reality?
^_^

JS could be called something like In-Browser Java (and it is heading to be the
same bloated failure) or something. But assembly.. ^_^

Reality distortion is very common think among Java fan-boys. Some of them, for
example, believe that a VM implemented as user level C++ program which uses
its own unrelated to CPU base data-types and several layers of abstractions to
interact with an OS, will run faster and more efficient than other c++ program
linked directly with core OS libraries.

Now JS fan-boys thinks that if there are things like V8 or such as artificial
as popular things like Nodejs, everything must be written in JS. That reminds
me the very same slogan from Java's best days.

To dear down-voters: Think for a moment what is v8 or Spidermonkey and count
how many code you should pile up to get access to something as simple as data
stored in a MySQL table (or any other data behind its own socket-based
protocol). ^_^ (yes, reality-checks are always painful)

~~~
stanleydrew
Pretty sure you're getting downvoted due to the insinuation that the legends
of JavaScript aren't thinking clearly due to drug use. You could just address
their points directly if you think they are misguided.

~~~
schiptsov
The link above is just a compilation of quotes.

Legeds of Javascript are thinking about their own fame, their own place in the
world, their money and their own selves, in the first place.

------
olavk
The most interesting insight is that because JS is higher level than Java
bytecode, it avoids some of the lower-level compatibility issues, which
actually makes WORA easier, even when considering JS a VM language.

------
mishoo
It's a bit worse than an assembly language, because it doesn't have JMP.

------
georgieporgie
_Eyeroll_. Sorry for the content-less comment, but I think it reflects the
content value of this post.

~~~
georgieporgie
Yeah, I just listened to the entire podcast on the subject, and this whole "JS
as assembly" is just dumb. The guy seems utterly mixed up about what JS,
assembly, and IL represent.

His entire premise is based on the idea that you can convert one language into
another, and therefore the target language is equivalent to assembly. That's
ludicrous. I believe Facebook converts PHP into C or C++, therefore C/C++ is
the new assembly. What?

The guy should just stick to talking about techniques for using cleaner
languages and converting them into JS. Instead, a bunch of link-bate BS was
poorly conceived and thrown in.

------
cdcarter
"Javascript is the x86 of the web"

This won't be fully true until everyone is on the same page with ECMAScript5.

~~~
laughinghan
What do you mean? I think you might be missing the point. ECMAScript 3 is
almost universally supported to the letter and will continue to be for the
forseeable future, just like modern x86 processors are backwards compatible
with the ABI from decades ago, and hence is a rock-solid foundation for
projects like GWT that compile to it.

ES3 has become the universally compatible "write once, run anywhere" bytecode
VM that Java promised to be.

------
dools
Let's just phrase this analogy explicitly:

x86 assembly language is to an x86 processor as; JavaScript is to ??

So in this case it would be wrong to say that "??" is the JavaScript
interpreter, because assembly language is a representation of machine code -
it's basically an set of labels attached to binary numbers right?

The x86 processor executes machine code (I think actually some of the
"backwards compatibility" in an x86 processor is provided by a scripting-like-
language implementation on the chip but that's invisible to the assembly
language programmer so not part of this discussion).

So I think you'd have to say that:

JavaScript is to a JavaScript interpreter as; x86 machine code is to an x86
processor

Then:

x86 assembly language is to x86 machine code as; ?? is to JavaScript

Now one could argue that CoffeeScript is the assembly language of JavaScript
(I've not used it but it seems to be a roughly 1-to-1 mapping of one set of
instructions to another, aliased for aesthetic purposes).

But getting back to the original analogy, I think it would be better stated
as:

If you think of a web browser as a kind of computing platform for which we can
write applications, then JavaScript is like the machine code that makes it
run.

I think that makes sense - and it also makes sense to build higher level
languages on top of JavaScript in that case, since increased computing power
has always enabled us to get more done with fewer man-hours, why should this
be any different?

~~~
jballanc
You're really torturing the analogy there, aren't you?

Rather than take it literally, let's restate the analogy to better capture the
intent: If you want your language to run on an x86 processor, you should
compile it to x86 assembly and if you want your language to run in the
browser, you should compile it to Javascript. Simply put.

There was a time when many "alternate" languages compiled to C instead of
directly to assembly (e.g. early implementations of Eiffel). If this were
still the trend today, then the analogy would better be stated as "Javascript
is the C of the cloud".

(as an aside, I've been saying that "Javascript is cloud assembly" since late
2008...)

