Transcript from the "Audience Questions" Lesson
>> Douglas Crockford: Well, that is it. So I think we are at the end of the day, so how is everybody feeling? We should do bunch of questions before we all go home.
>> Douglas Crockford: Anybody?
>> Douglas Crockford: Or we can do more problems?
>> Speaker 2: What text editor do you use in case someone wants to build your context code?
>> Douglas Crockford: Yeah, what text editor do I use? I use geany, G-E-A-N-Y, which is a really a basic, simple editor. Does code folding, but it doesn't do it right. And it does coloring, but it doesn't do that right. But it's a simple editor, that's all I need. I don't necessarily need that one fixed, I just need one that works right.
[00:00:52] So, yeah.
>> Speaker 3: You said the triple documentation was, I think, the second most?
>> Douglas Crockford: My second most favorite, yeah.
>> Speaker 3: Yeah, what's your first?
>> Douglas Crockford: Proper tail calls. What the hell is that? So one of the things that they discovered in scheme was that, actually this was known for a long time.
[00:01:17] But scheme took the idea and said this has to be standard equipment in the language, this is not an option. So if you have a subroutine call, like a JSR in some machines, followed immediately by a return, you can replace that with a jump and that has a couple of results.
[00:01:38] One is that the program goes faster, because you're not putting something on the stack and taking something off the stack and having a couple of jumps which CPUs don't like to do. You just go in there, and so that's a simple optimization. They found that the same thing applies to functional programming.
[00:02:19] But with this tail recursion thing, because those calls turn into jumps, there's no stack cost, right? So we can go as deep as we want without blowing the stack. So you can literally change loops into functions with no performance penalty. That's pretty neat. But even neater is there's another style of programming called continuation passing style.
[00:02:44] Which I would have shown you at the very end of the problems today, but I doubt that anyone would have been awake at that point. And in continuation passing style functions never return, instead you pass to each function the parameters that it needs plus one more which is the function that it should send the result to.
[00:03:28] Since nothing ever returns, you consume all the memory, and everything dies. But in continuation passing style, the way you write these things is, return function thing going forward forever. And the compiler knows okay, we're doing that and the code just gets those streamlined and the garbage collector knows how to get rid of all its stuff and all stays clean and fast and wonderful.
[00:05:21] Duxtler wrote back in the 60s, was it? Yeah, I think it was in the 60s that goto is considered harmful. It took us 20 years to get rid of goto, and in that time we had endless stupid debates about should we get rid of the goto or not?
[00:05:35] And particularly, most of the talking come from the old guys saying, you can't take it away from us without goto, we can't write efficient programs. Why are you doing this to us? We need our tools. So I think the reason it took 20 years was we had to wait for all those guys retire or die.
>> Speaker 4: [LAUGH]
[00:06:08] So we could put it in the language, some idiot web developers gonna blog, wow, did you know can make your programs go super fast if you use goto? And then certainly we're gonna have to wait for them to die, before we get rid of it again.
>> Speaker 4: [LAUGH]
>> Douglas Crockford: So we can't put anything into the language for one class of people, without exposing it to everybody. And we know that would cause harm, so we're not gonna do that. But proper tail calls allows us to have goto with this syntactic form which is not dangerous, which is actually extremely beneficial.
[00:06:41] So compiler writers would probably be the first to benefit from the continuation passing style, cuz that turns out to be a brilliant way to implement programming languages. So that's gonna be my favorite-most feature, anybody else?
>> Speaker 5: I have one question.
>> Douglas Crockford: Yeah.
>> Speaker 5: You mentioned that if the class system used by Java, C#, etc.
>> Douglas Crockford: Mm-hm.
>> Speaker 5: Could you reflect a little bit on what I'm talking about that?
>> Douglas Crockford: Yeah, so I believe that, so a little bit of history. So Randy Smith was a researcher, I guess he was at Xerox park at that time.
[00:07:32] I met him Atari lab earlier. And he was working on a system called Morphix. Morphix were objects which had stated behavior like other objects, but also a visual presentation. And he had this wonderful little demo set up where he could take objects which were on the screen. And open them up and reprogram them dynamically as the thing was running, and all this amazing behavior would occur.
[00:08:01] It was really great, and he showed this to David Unger, who earlier have been working on trying to make Smalltalk go really fast. He was designed a risk processor specifically to run Smalltalk. And he was amazed at the stuff Randy was doing, so we got to do that, so how can we make this better?
[00:08:24] And so they started collaborating and the thing that they came up with was the self language. So it turned out the morphics were much easier to compose if there were no classes, if you could just assign functions directly to the things everything was so much easier and faster.
[00:08:39] And then Unger spent a lot of time looking at, okay, how do we take the implementations of that, and make them go really fast? So a lot of what we know now about how we make things go fast, came from the self project, for example how to make virtual machines like the Java virtual machine go fast.
[00:08:56] That came out of self, generation of scavenging in order to make garbage collection go really fast, that came out of self. And but the prototype idea nobody paid much attention to it except for Branden, he thought all that's cool. I'll throw them in large script and see what happens, and it's brilliant.
>> Speaker 6: Along that same thing, what are your thoughts on TypeScripts?
[00:11:02] Because you say variable dot, you don't have a short list of methods that come off of that, because it could be anything. So about the best you can do is take the list of all known methods and say, do you want one of those? And so they were looking at doing something better.
[00:12:50] And where are my types? How am I gonna know that everything is working? And my experience with the language was that, also the theory with strong typing is the type system can find all sorts of errors early. And the earlier you can find an error, the less its gonna cost.
[00:13:53] And ultimately, my analysis was that the type checking just wasn't paying for itself. That the freedom of being able to express stuff the way I want. And also any type system in which you ever have to cast, and my opinion that was not a type system, it's just an annoyance.
[00:14:31] And it always worked great, and they do some of the most complex programs ever written and have not been burdened by the absence of a type system at all. So everybody has a different opinion on this, and most of the opinions are not based on any kind of data or experience.
[00:15:06] And again, of the things of that class, it is by far, the best. But if I use TypeScript I can't use JSLint anymore, cuz JSLint doesn't understand that language and JSLint buys me a lot more than TypeScript does. So I'm sticking with it.
>> Douglas Crockford: Okay, one more? Any one more?
[00:15:28] Anybody? Someone doesn't ask a question you're all gonna have to go home.
>> Speaker 7: Did you have-
>> Douglas Crockford: Yeah.
>> Speaker 7: More information on Ajax and DOM manipulation that you're gonna talk about?
>> Douglas Crockford: I was gonna do one more, but I think we're all pretty burnt at this point. So you guys will get the slide and that talk is online somewhere, so we'll probably be able to give you a link to it.
>> Douglas Crockford: Okay, go home everybody.
>> Speaker 8: [APPLAUSE]