Placeholder Image

Subtitles section Play video

  • Souders: All right, welcome, everyone.

  • It's great to see a big crowd here.

  • My name's Steve Souders.

  • I work here at Google on latency.

  • And I wanted to do a couple plugs for these talks.

  • I'm trying to see about starting up a series

  • of tech speakers coming in.

  • So a couple weeks ago we had John Resig come in

  • and you can see that talk

  • up on the Google developer channel up on Google code.

  • And next Thursday at 11:00 A.M. right here

  • is Rob Campbell who works at Mozilla

  • and he's one of the people leading the Firebug effort.

  • And he's gonna do a talk next Thursday at 11:00

  • right here on Firebug and the new releases

  • that are coming out and some of the new features.

  • And-- But today--

  • So today we have Doug Crockford.

  • Um, I worked with Doug at Yahoo.

  • That's where I met him.

  • And I remember the first time I met him

  • and he told me his name, I said,

  • "I know that name somewhere. I know that name somewhere.

  • Oh, yeah, I've been using the stuff on your website a lot."

  • And so I was really excited to meet him.

  • And he's a really nice guy.

  • I enjoyed working with him at Yahoo.

  • Um, I--

  • I, uh, have a little bit of hesitation

  • because when my book came out, it did pretty well.

  • And then Doug's book came out and just kicked my book's butt.

  • And so I just checked.

  • And I'm, like, at 6,000 and you're at, like,

  • 4,000 on Amazon sales rank, Doug.

  • So that's really good.

  • And I believe that this talk is largely based on his book,

  • "JavaScript: The Good Parts."

  • And so we'll run for about an hour

  • and have time for Q and A.

  • So without any further ado,

  • please help me welcome Doug Crockford.

  • [applause]

  • I forgot.

  • Here's your Google tech talk goodie bag.

  • Crockford: This is what makes it all worthwhile, right here.

  • [laughter]

  • So, thank you, everybody.

  • I'm Doug Crockford from the Yahoo.

  • And I'm here today to talk about the good parts.

  • Now when I first started talking about JavaScript,

  • there were a lot of people who just could not accept the fact

  • that JavaScript has good parts.

  • But, in fact, it does.

  • But it's not well understood. Even now.

  • JavaScript has become probably the most important

  • programming language in the world.

  • There's more JavaScript processors

  • on more computers than anything else

  • by a very large factor.

  • But despite that, JavaScript is not held

  • in very good esteem, even within

  • its own programming community.

  • For example, the C# community loves Anders.

  • And the Java community loves Gosling.

  • And the PHP community loves Rasmus.

  • But in the JavaScript community, there is no love.

  • And there should be.

  • And I think it indicates a lack of understanding.

  • That's why JavaScript is still the world's

  • most misunderstood programming language.

  • It's the only language that I'm aware of

  • that people feel that they don't need to learn it

  • before they start using it.

  • [laughter]

  • It kinda looks familiar and yeah, yeah, yeah, yeah.

  • I've seen this before. I know how this works.

  • In fact, it works in a really radically different way.

  • It just looks very similar.

  • And then when people misuse it as inevitably they do

  • because they don't know how it works,

  • they get angry at it, and misunderstand it.

  • Which is a shame because there's actually

  • good stuff in this language.

  • And because it's everywhere, JavaScript is now becoming

  • the virtual machine for the world,

  • which is a really odd mission for this

  • little misunderstood language.

  • You know, you're doing it here at Google with the GUID.

  • And there are lots of other examples

  • of the same kinda crazy thing.

  • You know, it amazes me the lengths that people

  • will go to to avoid having to learn JavaScript.

  • But it's learnable and you can actually

  • write good programs in it.

  • And like everything else, knowing what you're doing,

  • you know, makes a difference.

  • And so I'm here to enlighten the world about JavaScript.

  • JavaScript is a language of many contrasts.

  • It contains some of the best ideas ever put

  • into a programming language.

  • And it contains some of the worst ideas

  • ever put into a programming language.

  • And a lot in between.

  • There's no other language which has this amazing range

  • of the ridiculous and the sublime.

  • Um, if you look at the community of people

  • who use JavaScript, it has the broadest range

  • of programmer skills of any programming language.

  • We've got people at the very high-end doing computer science

  • in this language, which it does really well

  • 'cause it's basically a scheme with C syntax.

  • And we've got cut-n-pasters who don't even know

  • that they're programming, who are putting stuff together

  • and making it happen.

  • If you gave those kids Java compilers,

  • they would never get "Hello World" running,

  • but they can work with JavaScript.

  • So the language has amazing expressive power

  • and it supports everybody in between.

  • I contend there is no other programming language

  • that can support this really broad audience of users.

  • And I'll offer that as further evidence

  • that this language is getting something right.

  • Which again, may be surprising to the people who think

  • this language didn't get anything right.

  • One of the reasons people think that is that

  • they have a lot of complaints about it.

  • And I think these complaints are all valid

  • and I'd like to go through them one at a time.

  • The first one is that JavaScript is not a language I know.

  • If you're programming in any environment--

  • the desktop or embedded systems or the server--

  • generally, you get to pick what language you're going to use.

  • But if you're writing in the browser

  • or if you're writing in one of the applications

  • that has embedded JavaScript in it,

  • you don't get a choice.

  • You have to use JavaScript.

  • And a lot of people get resentful about that.

  • You know, "Why should I have to learn this stupid language?

  • "I already know lots of other good languages.

  • Why can't I use one of those?"

  • You can't.

  • Um, and so they...

  • try to write without learning the language,

  • which I think is really a bad thing to do.

  • My advice is man up and learn the language.

  • If you need to be writing in JavaScript,

  • there's nothing like knowing what you're doing.

  • Second complaint.

  • The browser programming experience is awful,

  • which is absolutely true.

  • But that's not JavaScript's fault.

  • I contend it's the DOM's fault.

  • The DOM is one of the worst APIs ever imagined

  • and that's what you have to use when you're using the browser.

  • Fortunately, there are a lot of Ajax libraries available now

  • which all do an amazing job at correcting the DOM model

  • and turning it into something that you can actually

  • write good applications in.

  • So, uh, there is a solution to that.

  • I'm hoping eventually we can push that solution

  • back into the browser.

  • But for now, the Ajax libraries work really well.

  • YEY, I'll mention that one. Comes out of Yahoo.

  • It's actually very, very good.

  • I think maybe the best of them.

  • There are lots of others that are also very good.

  • There's a complaint that it's not fast enough.

  • And in the browser, that's mainly because of the DOM again.

  • If you look at the fraction of time

  • that your program spends running,

  • a tiny fraction of that is actually running

  • in the JavaScript interpreter.

  • Most of the rest of it is wasting time

  • in the DOM interface.

  • So if you could somehow make your programs

  • go infinitely fast, most web applications

  • are gonna look about the same.

  • There are other applications for which having

  • a faster language would actually be a benefit.

  • And so I'm happy to see that mainly, I think,

  • because of leadership from Google,

  • we're now starting to see higher performance

  • JavaScript entrants, which I think

  • is really, really cool and very much to be encouraged.

  • Although, practically, I don't think it's gonna make

  • much difference to web applications for a long time.

  • Then finally, there's a complaint

  • that the language is just a big pile of mistakes.

  • And I contend, no, it's not just a big pile of mistakes.

  • [laughter]

  • That hidden under a huge steaming pile of good intentions

  • and blunders, there is an elegant, expressive

  • programming language because JavaScript has good parts.

  • And if you can recognize those parts

  • and use those parts exclusively and avoid the bad parts,

  • you can actually write good programs in this language.

  • And I'll offer again, as evidence of that,

  • that JavaScript is succeeding very well

  • in an environment where Java was a total failure.

  • I don't know if anyone here remember Java applets.

  • How they're gonna change the world?

  • Didn't happen.

  • Crap.

  • Java turned out to be an okay language

  • and found a niche in the server

  • where it's doing pretty well.

  • But it was absolutely awful as a client programming language.

  • JavaScript is doing really, really well there.

  • The influences on JavaScript were Self,

  • from which it borrows prototypal inheritance

  • of dynamic objects.

  • Dynamic objects are a really clever thing

  • and they worked really well in this language.

  • From Scheme, it gets lambda, which is maybe the best idea

  • in the history of programming languages

  • and loose typing, which is pretty controversial.

  • The style of most languages today calls for strict typing.

  • The theory being that strict typing allows for

  • the compiler to check a large class of errors

  • at compilation time avoiding--

  • Catching any error early reduces the cost of the errors.

  • So that's a good thing.

  • And JavaScript doesn't have that.

  • So in JavaScript, any variable or any parameter

  • can contain a value of any type.

  • And that's really frightening to someone

  • who's coming from a strongly-typed tradition.

  • Like, "How can I have any confidence

  • that anything's gonna work right?"

  • It turns out that strong-typing

  • doesn't absolve you of the need to test.

  • You still have to test everything,

  • 'cause there's an even larger class of mistakes

  • that type checking doesn't find for you.

  • And I found in my own practice that the amount

  • of testing that I have to do, writing in Java

  • or writing in JavaScript, is about the same.

  • That those type errors get found really quickly anyway,

  • so they're not really a problem.

  • The areas that are a problem,

  • the ones that keep me up at night,

  • um, type safety wouldn't have helped me there.

  • The benefit of having loose typing

  • is you don't have to mess with the type system.

  • And so that turns out to be liberating.

  • Your programs tend to be a lot smaller and a lot simpler.

  • So which one do you like? Well, it doesn't matter.

  • If you're working in JavaScript, it's gonna be loosely typed

  • and that's just the way it works.

  • From Java we get syntax, which is a source

  • of a lot of problems because it's basically

  • the C family of syntax, which we've all learned

  • to deal with.

  • We've gotten so good at it that we don't even recognize

  • anymore how defective it is.

  • But because JavaScript is used by beginners,