Saturday, January 12, 2013

Crockford on Javscript - The beginning

A confession first - I decided to watch this video only because I had 2 hours to kill and didn't have anything better to do. And ended up spending a weekend going through the entire set of videos. If you have the time and a good bb connection, go for it. Crockford's wit is amazing, plus the insights into why Javscript is the way it is make this a good watch. Did you know that Javascript was designed and implemented in less than 2 weeks - I take as long to draft a design document. Oh, and be prepared for some heavy duty Java trashing :)

Crockford on JavaScript - Chapter 2: And Then There Was JavaScript


In order to do that, they hired this guy, Brendan Eich, who had been at Silicon Graphics. Brilliant guy. In his interview he said he wanted to write a Scheme interpreter, and they said ‘that’s great, that’s just what we want’. After they hired him they found out what Scheme was, and they said ‘no, no, no, you can’t do that. People won’t like that. Do something that looks more like Visual BASIC, or Java, something people like.’ So he did that. He combined elements of three languages: Java, because he was told he had to, and two really interesting languages, two failed languages in the sense that they got zero market acceptance, but two brilliant languages and two highly influential languages. They’re known not much to the general programming community, but they’re very well known to program language designers. It was a surprising choice to take features from those two languages. Scheme was a dialect of Lisp, which was inspired by Carl Hewitt’s Actor Model. Brilliant language, probably the best implementation of functions in any language we’ve ever seen. Self was a brilliant language that came out of Xerox Parc originally. It was taking Smalltalk and stripping it down to a simpler language in order to make it go faster. It turned out that in making it simpler they actually made it profoundly better. That project then moved to Sun Labs, so for a time Sun was supporting research into both Java and Self. At some point Sun made a decision and killed one of them, and in my opinion they killed the wrong one. Self was clearly the better language.

Brendan took elements of all three of these languages, and a little bit of his own, and put them together into a new language that was called LiveScript. LiveScript was going to become one of the key technologies for Netscape going forward. It was very clear at the time that there was a lot of excitement about Java and the Netscape browser, and Sun and Netscape decided they needed to work together against Microsoft because if they didn’t join forces Microsoft would play them off against each other and they’d both lose. The biggest point of contention in that arrangement was what to do with LiveScript. Sun’s position was: "Well, we’ll put Java into the Netscape browser, we’ll kill LiveScript, and that’ll be that." And Netscape said no, that they really believed in the HyperCard-like functionality, and they wanted a simpler programming model in order to capture a much larger group of programmers. So there was an impasse, and the relationship almost broke up, when I think Marc Andreessen - and I have not been able to document this, but people have told me - Marc Andreessen, maybe as a joke, suggested: ‘let’s change the name to JavaScript.’ And it worked. 

At Microsoft they’d been watching this with some alarm, particularly when folks at Netscape were saying that Netscape Navigator was going destroy Microsoft. Microsoft said ‘oh, we don’t want to be destroyed’. It turned out Netscape Navigator didn’t destroy Microsoft. In fact, the software that is going to destroy Microsoft is Windows Mobile.

What Microsoft did was they decided they needed to copy the Netscape model in order to be competitive. They reverse engineered the JavaScript engine and called it JScript. They couldn’t call it JavaScript because Sun owned the trademark, and they weren’t getting along very well with Sun at that time, so they called it JScript. Netscape looked at that with alarm: oh no, we’re going to be embraced and extended, so we need to make a standard out of this. So they went to W3C and said OK, we’ve got a language for you to standardize. W3C had been waiting for a long time for an opportunity to tell Netscape to go to hell, so they told Netscape to go to hell.

In copying the Java syntax, JavaScript also copied some bad things about Java. So many of the worst features in JavaScript are actually things it inherited from Java, which it inherited from C, which it inherited from FORTRAN. So there’s a long line of sin-age which affects us today.