[Script Info] Title: [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text Dialogue: 0,0:00:00.00,0:00:05.30,Default,,0000,0000,0000,,You've seen a little bit of JavaScript\Ncode and in this section; I wanna talk Dialogue: 0,0:00:05.30,0:00:10.47,Default,,0000,0000,0000,,about what connect to that world to the\Nmachine code in the CPU. So, this is Dialogue: 0,0:00:10.47,0:00:15.70,Default,,0000,0000,0000,,beyond generally the topic of computer\Nlanguages. So a programmer works in some Dialogue: 0,0:00:15.70,0:00:20.65,Default,,0000,0000,0000,,computer language and computer languages\Nare said to have high quote, high level Dialogue: 0,0:00:20.65,0:00:25.72,Default,,0000,0000,0000,,features and that means things like loops\Nand if statements and strings. Those are Dialogue: 0,0:00:25.72,0:00:30.54,Default,,0000,0000,0000,,facilities that are more complicated, that\Nare most present in a really simple Dialogue: 0,0:00:30.54,0:00:35.31,Default,,0000,0000,0000,,machine code on the CPU. So the programmer\Nwrites what it's called source code in Dialogue: 0,0:00:35.31,0:00:39.62,Default,,0000,0000,0000,,whatever computer language they are\Nwriting. So here is an example of some C++ Dialogue: 0,0:00:39.62,0:00:43.99,Default,,0000,0000,0000,,source code, this assigns a string into a\Nvariable and then puts and exclamation Dialogue: 0,0:00:43.99,0:00:48.14,Default,,0000,0000,0000,,mark on the end of that string. You know\Nwhat? Some, it's kinda similar to the Dialogue: 0,0:00:48.14,0:00:52.62,Default,,0000,0000,0000,,JavaScript code we've seen A lot of these\Nlanguages at the syntactic level and of Dialogue: 0,0:00:52.62,0:00:57.93,Default,,0000,0000,0000,,their kinda similar to use of quotes and\Nsemicolons or what not. So how do you get Dialogue: 0,0:00:57.93,0:01:04.23,Default,,0000,0000,0000,,from the C++ source code say to running on\Na CPU? So one strategy used is what's Dialogue: 0,0:01:04.23,0:01:10.16,Default,,0000,0000,0000,,called a Compiler. And, the Compiler is a\Nseparate program. And what the compiler Dialogue: 0,0:01:10.16,0:01:15.19,Default,,0000,0000,0000,,does is it looks at all of the source code\Nand it does a bulk translation over to a, Dialogue: 0,0:01:15.19,0:01:20.22,Default,,0000,0000,0000,,to create a big body of machine code. So\Nfor example maybe there is a part of the Dialogue: 0,0:01:20.22,0:01:24.64,Default,,0000,0000,0000,,source code where there is an if\Nstatement. And there is not a specific Dialogue: 0,0:01:24.64,0:01:29.56,Default,,0000,0000,0000,,instruction in a machine code for an if\Nstatement but maybe there's a sequence of Dialogue: 0,0:01:29.56,0:01:34.40,Default,,0000,0000,0000,,five machine code instructions that in\Neffect make up an if statement and so the Dialogue: 0,0:01:34.40,0:01:40.99,Default,,0000,0000,0000,,compiler does that kind of expansion. So,\Njust an example Firefox is written in C++ Dialogue: 0,0:01:41.30,0:01:49.84,Default,,0000,0000,0000,,and so, to make a new version of Firefox\Nsomeone runs the C++ compiler and it reads Dialogue: 0,0:01:49.84,0:01:54.71,Default,,0000,0000,0000,,in. Of the many source files that adamant,\Nthe great body of source code that makes Dialogue: 0,0:01:54.71,0:01:59.39,Default,,0000,0000,0000,,out Firefox and proves that essentially,\Nfirefox.exe. Firefox.exe is the output of Dialogue: 0,0:01:59.39,0:02:04.45,Default,,0000,0000,0000,,the compiler to just translate all of that\Nsource code. Couple of things to point out Dialogue: 0,0:02:04.45,0:02:09.18,Default,,0000,0000,0000,,about this The compilation only has to\Nhappen once so somebody with source code, Dialogue: 0,0:02:09.18,0:02:13.34,Default,,0000,0000,0000,,someone makes Fi refox [inaudible] and\Nthen you can just send out Firefox Dialogue: 0,0:02:13.34,0:02:17.73,Default,,0000,0000,0000,,[inaudible]. The end users don't need the\Nsource code and they don't need the Dialogue: 0,0:02:17.73,0:02:22.23,Default,,0000,0000,0000,,compiler so the compilation can just sort\Nof to be done, done at the factory in Dialogue: 0,0:02:22.23,0:02:26.58,Default,,0000,0000,0000,,effect. Another fact, another feature that\Nthis doesn't work backwards, So, I can Dialogue: 0,0:02:26.58,0:02:30.95,Default,,0000,0000,0000,,distribute firefox.exe all through this\Nmachine code but there's not something Dialogue: 0,0:02:30.95,0:02:35.44,Default,,0000,0000,0000,,that will read that in and go backwards to\Ngive me a big body of source code. Really Dialogue: 0,0:02:35.44,0:02:39.81,Default,,0000,0000,0000,,is not perfectly, you can try to do it\Nimperfectly but ideally, to produce a new Dialogue: 0,0:02:39.81,0:02:44.30,Default,,0000,0000,0000,,version you who really wants the source\Ncode. So, let's talk about the source code Dialogue: 0,0:02:44.30,0:02:48.88,Default,,0000,0000,0000,,a little bit. So if you wanna add a\Nfeature of fix a bug to Firefox, real way Dialogue: 0,0:02:48.88,0:02:53.77,Default,,0000,0000,0000,,to do that is to go back to the original\Nsource code and rework it just what we've Dialogue: 0,0:02:53.77,0:02:58.55,Default,,0000,0000,0000,,done in JavaScript. So, add a few lines or\Nan If statement to change some behavior Dialogue: 0,0:02:58.55,0:03:03.56,Default,,0000,0000,0000,,and some way into source code and then run\Nthe compiler again to make in effect a new Dialogue: 0,0:03:03.56,0:03:07.98,Default,,0000,0000,0000,,version of Firefox that has this, this\Nlittle change that you've put in the Dialogue: 0,0:03:07.98,0:03:12.32,Default,,0000,0000,0000,,source code. And just as were, we're\Ntalking about source code. There's also Dialogue: 0,0:03:12.32,0:03:16.82,Default,,0000,0000,0000,,give you, gives you a sense of what Open\NSource software means. So, Open Source Dialogue: 0,0:03:16.82,0:03:22.14,Default,,0000,0000,0000,,software is a format where the program is\Ndistributed but also there's access to the Dialogue: 0,0:03:22.14,0:03:26.99,Default,,0000,0000,0000,,original source code to the program and\Nusually does come with a license saying, Dialogue: 0,0:03:26.99,0:03:31.79,Default,,0000,0000,0000,,hey here's the source code if you wanna\Nmake your own version or if it's about Dialogue: 0,0:03:31.79,0:03:36.52,Default,,0000,0000,0000,,whatever, this program, feel free. So, the\Ntwo main features of Open Source software Dialogue: 0,0:03:36.52,0:03:40.97,Default,,0000,0000,0000,,is one, it's, it's typically distributed\Nfor free so it's just, you know, cheap. Dialogue: 0,0:03:41.20,0:03:46.90,Default,,0000,0000,0000,,But the other feature is it comes with a\Nsort of freedom. Because if the software Dialogue: 0,0:03:46.90,0:03:51.03,Default,,0000,0000,0000,,is close source and you want some\Ndifferent feature there is some bug that Dialogue: 0,0:03:51.03,0:03:55.05,Default,,0000,0000,0000,,you need implemented you're really\Ndependent on the vendor who holds the Dialogue: 0,0:03:55.05,0:03:59.07,Default,,0000,0000,0000,,source code like do they feel like\Nimplementing that feature. In contrast Dialogue: 0,0:03:59.07,0:04:03.64,Default,,0000,0000,0000,,with open source software it's like there\Nis no handcuffs you know the source code Dialogue: 0,0:04:03.64,0:04:07.99,Default,,0000,0000,0000,,is available and if there is something\Nthat you really wanted to do or say the Dialogue: 0,0:04:07.99,0:04:12.78,Default,,0000,0000,0000,,original vendor goes out of business then\Nbecause you got the source code you could Dialogue: 0,0:04:12.78,0:04:16.91,Default,,0000,0000,0000,,or you know maybe pay someone to make a\Nchange and produce your own custom Dialogue: 0,0:04:16.91,0:04:21.53,Default,,0000,0000,0000,,version. And so it comes with this sort of\Ndeep, you could take this as an insurance Dialogue: 0,0:04:21.53,0:04:25.62,Default,,0000,0000,0000,,policy. So often there's, there's many\Ndifferent types of license terms for open Dialogue: 0,0:04:25.62,0:04:29.67,Default,,0000,0000,0000,,Source software but most often they\Nrequire in some cases that if you take the Dialogue: 0,0:04:29.67,0:04:33.57,Default,,0000,0000,0000,,source code and add some feature that you\Nthen offer those changes back to the Dialogue: 0,0:04:33.57,0:04:37.92,Default,,0000,0000,0000,,community. So sort of in the same way that\Nyou've benefited from others work they can Dialogue: 0,0:04:37.92,0:04:42.02,Default,,0000,0000,0000,,benefit from your work. In, in the details\Non how that can be done is complicated. Dialogue: 0,0:04:42.02,0:04:45.92,Default,,0000,0000,0000,,There's, there's many different forms of\Nit. I'm gonna talk about open source Dialogue: 0,0:04:45.92,0:04:50.02,Default,,0000,0000,0000,,software a little bit later on but I just\Nwant to mention it now because it really Dialogue: 0,0:04:50.02,0:04:54.17,Default,,0000,0000,0000,,gets up this idea of what is the source\Ncode of a program versus just having the Dialogue: 0,0:04:54.17,0:05:01.48,Default,,0000,0000,0000,,.exe or something. So that's why I just\Ntalked about C++. So there's, a whole Dialogue: 0,0:05:01.48,0:05:06.01,Default,,0000,0000,0000,,another very big category of languages. We\Ncome in to call Dynamic Languages Or Dialogue: 0,0:05:06.01,0:05:10.44,Default,,0000,0000,0000,,sometimes interpreter languages. And\Nthere's sort of a big strategy, there are Dialogue: 0,0:05:10.44,0:05:14.53,Default,,0000,0000,0000,,many different languages with many\Ndifferent qualities and I'm just kinda Dialogue: 0,0:05:14.53,0:05:18.96,Default,,0000,0000,0000,,sort of [inaudible] for this large\Ncategory So examples of Dynamic Languages Dialogue: 0,0:05:18.96,0:05:24.28,Default,,0000,0000,0000,,currently are Java and JavaScripts and\NPython. So one way that these can work is Dialogue: 0,0:05:24.28,0:05:30.12,Default,,0000,0000,0000,,that they are implemented by what is\Ncalled an interpreter as supposed to the Dialogue: 0,0:05:30.12,0:05:36.50,Default,,0000,0000,0000,,compiler case I was describing earlier so\Nan interpreter is a program which takes in Dialogue: 0,0:05:36.50,0:05:42.68,Default,,0000,0000,0000,,code written in some language and sort of\Nquote, unquote runs it so. Best example is Dialogue: 0,0:05:42.68,0:05:47.30,Default,,0000,0000,0000,,that there is this computer language\Ncalled JavaScript that actually we've been Dialogue: 0,0:05:47.30,0:05:51.92,Default,,0000,0000,0000,,using and web browsers which are programs\Ninclude as part of them a Java Script Dialogue: 0,0:05:51.92,0:05:56.61,Default,,0000,0000,0000,,interpreter and so when the web browser\Ncomes across a page with some JavaScript Dialogue: 0,0:05:56.61,0:06:01.41,Default,,0000,0000,0000,,code in it, it can use the interpreter to\Nrun that code to make it do whatever it's Dialogue: 0,0:06:01.41,0:06:07.55,Default,,0000,0000,0000,,going to do. So, an available detail, the\Nway an interpreter works. Is that it, it Dialogue: 0,0:06:07.55,0:06:11.30,Default,,0000,0000,0000,,deals with the program one line at a time.\NSo, if, so here's a little bit of Dialogue: 0,0:06:11.30,0:06:15.60,Default,,0000,0000,0000,,JavaScript code. If the interpreter wanted\Nt run this, well, we'll look at the first Dialogue: 0,0:06:15.60,0:06:19.75,Default,,0000,0000,0000,,line and it would look at what that line\Nsays and then the interpreter would do it. Dialogue: 0,0:06:19.75,0:06:23.95,Default,,0000,0000,0000,,So in this case the interpreter would say\Noh well, I guess I need a variable name a Dialogue: 0,0:06:23.95,0:06:28.10,Default,,0000,0000,0000,,and I need to put a one in it. So, once it\Nsummed at that line it goes ahead and it Dialogue: 0,0:06:28.10,0:06:32.42,Default,,0000,0000,0000,,does the next line and so on. So the\Ncompiler does this big bulk translation Dialogue: 0,0:06:32.42,0:06:36.82,Default,,0000,0000,0000,,from the source code into machine code.\NBut it's not really running code, it's Dialogue: 0,0:06:36.82,0:06:41.22,Default,,0000,0000,0000,,just doing a translation to be run in the\Nfuture. In contrast, the interpreter Dialogue: 0,0:06:41.22,0:06:45.62,Default,,0000,0000,0000,,really lives in the moment Just going\Nthrough the code line by line and just Dialogue: 0,0:06:45.62,0:06:50.44,Default,,0000,0000,0000,,doing it. So let me talk a little about\Nthe differences between these two and I Dialogue: 0,0:06:50.44,0:06:55.55,Default,,0000,0000,0000,,should tell you as a disclaimer there are\Nmany computer languages. There is no best Dialogue: 0,0:06:55.55,0:06:59.99,Default,,0000,0000,0000,,language. The old joke is that. Really\Nwhen, you know, you're on this seminar and Dialogue: 0,0:06:59.99,0:07:03.75,Default,,0000,0000,0000,,you are arguing about the pros and cons or\Nsomething. Ultimately, the answer is just Dialogue: 0,0:07:03.75,0:07:07.15,Default,,0000,0000,0000,,it depends. Like there's not a best\Nlanguage, it's like well, what's the best Dialogue: 0,0:07:07.15,0:07:11.33,Default,,0000,0000,0000,,language for the situation with all the,\Nwith all the feature. So broadly speaking, Dialogue: 0,0:07:11.33,0:07:16.21,Default,,0000,0000,0000,,compiler code does tend to run faster and\Nwhen you put, when you compile C++ code Dialogue: 0,0:07:16.21,0:07:21.16,Default,,0000,0000,0000,,and produce that EXE, it's sort of in a\Nsense lean. A lot of detail and decisions Dialogue: 0,0:07:21.16,0:07:26.84,Default,,0000,0000,0000,,has been stripped out as much as possible.\NOn the other hand, dynamic or interpreter Dialogue: 0,0:07:26.84,0:07:32.10,Default,,0000,0000,0000,,languages tend to have more features. More\Nfeatures that make their programmers job a Dialogue: 0,0:07:32.10,0:07:37.29,Default,,0000,0000,0000,,little bit easier or put in another way.\NBroadly speaking, programmers can tend to Dialogue: 0,0:07:37.29,0:07:42.19,Default,,0000,0000,0000,,get more work done per hour in dynamic\Nlanguages than they do in compiled Dialogue: 0,0:07:42.19,0:07:47.89,Default,,0000,0000,0000,,languages. However there is no free lunch.\NIt is also the case that dynamic language Dialogue: 0,0:07:47.89,0:07:53.20,Default,,0000,0000,0000,,code tends to run slower on the CPU in\Nterms of just getting work done compared Dialogue: 0,0:07:53.20,0:07:58.50,Default,,0000,0000,0000,,to a compiled language, compiled source\Ncode that was going to do the same thing. Dialogue: 0,0:07:58.67,0:08:03.05,Default,,0000,0000,0000,,So, an example of this, a great example of\Nthis is memory management. So, memory Dialogue: 0,0:08:03.05,0:08:07.89,Default,,0000,0000,0000,,management refers to the problem in the\Ncode of knowing how many bytes are needed Dialogue: 0,0:08:07.89,0:08:12.32,Default,,0000,0000,0000,,to store something And in particular, for\Nhow long. Well, I need these bytes for Dialogue: 0,0:08:12.32,0:08:17.10,Default,,0000,0000,0000,,here on line six but maybe on line twenty.\NI don't need them anymore and I can reuse Dialogue: 0,0:08:17.10,0:08:21.42,Default,,0000,0000,0000,,those bytes for something else. And that\Nis actually a kind of a complicated Dialogue: 0,0:08:21.42,0:08:26.08,Default,,0000,0000,0000,,problem. In C and C++ memory management is\Nto a degree manual and that just means Dialogue: 0,0:08:26.08,0:08:31.10,Default,,0000,0000,0000,,that the programmer, they're producing all\Nthese lines of codes to do stuff and there Dialogue: 0,0:08:31.10,0:08:36.01,Default,,0000,0000,0000,,is going to be times when they maybe to\Nadd some lines to do some thinking to help Dialogue: 0,0:08:36.01,0:08:40.44,Default,,0000,0000,0000,,guide the memory management so there is\Nsome programmer effort required. In Dialogue: 0,0:08:40.44,0:08:45.29,Default,,0000,0000,0000,,contrast most dynamic language have what's\Ncalled automatic memory management and Dialogue: 0,0:08:45.29,0:08:50.46,Default,,0000,0000,0000,,this means that. No programmer input is\Nrequired that the lower on the stacks that Dialogue: 0,0:08:50.46,0:08:55.60,Default,,0000,0000,0000,,the language is gonna notice automatically\Nwhen memory is needed; when memory is not Dialogue: 0,0:08:55.60,0:09:00.71,Default,,0000,0000,0000,,needed anymore it can be recycled and just\Ntake on that whole problem. So, this fits Dialogue: 0,0:09:00.71,0:09:04.60,Default,,0000,0000,0000,,within the, the, the trend of dynamic\Nlanguages that I was mentioning earlier. Dialogue: 0,0:09:04.60,0:09:08.64,Default,,0000,0000,0000,,So this is an example of how well, you\Nknow, because the programmers has less to Dialogue: 0,0:09:08.64,0:09:12.84,Default,,0000,0000,0000,,do they're able to just get stuff done a\Nlittle quicker, so memory management is a Dialogue: 0,0:09:12.84,0:09:16.78,Default,,0000,0000,0000,,great example of that. However, you can\Nalso imagine this is one of the things Dialogue: 0,0:09:16.78,0:09:21.03,Default,,0000,0000,0000,,that makes dynamic language codes run a\Nlittle slower because the CPU now has this Dialogue: 0,0:09:21.03,0:09:25.38,Default,,0000,0000,0000,,additional bookkeeping problem where it's\Nlooking at memory and trying to figure out Dialogue: 0,0:09:25.38,0:09:31.21,Default,,0000,0000,0000,,of when it can be reused. So, very broadly\Nspeaking the trend for computer Dialogue: 0,0:09:31.21,0:09:37.77,Default,,0000,0000,0000,,programming today is towards dynamic\Nlanguages that the trade off that. The Dialogue: 0,0:09:37.77,0:09:42.45,Default,,0000,0000,0000,,programmer will get things done a little\Nquicker at the expense of using a little Dialogue: 0,0:09:42.45,0:09:47.13,Default,,0000,0000,0000,,more CPU or maybe a little more memory,\Nthat's a pretty attractive payoff for many Dialogue: 0,0:09:47.30,0:09:51.86,Default,,0000,0000,0000,,for many problems. In this, maybe a little\Nunintuitive you can think off. We'll Dialogue: 0,0:09:51.86,0:09:56.14,Default,,0000,0000,0000,,what's the scariest quality for a computer\Nprogram and oftentimes, it's the Dialogue: 0,0:09:56.14,0:10:00.54,Default,,0000,0000,0000,,programmer that having skilled programmers\Nworking on a problem who, you know, Dialogue: 0,0:10:00.54,0:10:05.01,Default,,0000,0000,0000,,working on those, working on these do\Nmain. A lot of times there are hard to Dialogue: 0,0:10:05.01,0:10:10.05,Default,,0000,0000,0000,,find and so using up their hours. Using\Nfew of their hours looks attractive. In Dialogue: 0,0:10:10.05,0:10:15.21,Default,,0000,0000,0000,,contrast the CPU only we want programs to\Nrun as fast as possible but Cpus are Dialogue: 0,0:10:15.21,0:10:18.90,Default,,0000,0000,0000,,fairly, and if it got some fairly,\Neffective and there was even this funny Dialogue: 0,0:10:18.90,0:10:22.99,Default,,0000,0000,0000,,effect where Moore's Law keeps making it\Nmore truth. Where the CPU in a fact each Dialogue: 0,0:10:22.99,0:10:26.78,Default,,0000,0000,0000,,year gets a little bit cheaper, but if you\Nthink of the balance between the Dialogue: 0,0:10:26.78,0:10:30.46,Default,,0000,0000,0000,,programmer cost and the CPU cost of\Ngetting something done, that means in Dialogue: 0,0:10:30.46,0:10:34.20,Default,,0000,0000,0000,,terms of the share of the pie, the\Nprogrammer is in a fact of getting more Dialogue: 0,0:10:34.20,0:10:38.28,Default,,0000,0000,0000,,expensive each year. A little bit more\Nscarce. So, this fits the pattern that on, Dialogue: 0,0:10:38.28,0:10:42.35,Default,,0000,0000,0000,,on, on, on whole, dynamic languages are\Nbecoming a little bit more popular. Just Dialogue: 0,0:10:42.35,0:10:46.50,Default,,0000,0000,0000,,the last thing I'll mention is that\Nthere's, I think a thing called a JIT, a Dialogue: 0,0:10:46.50,0:10:50.98,Default,,0000,0000,0000,,Just in Time compiler and this is sort of\Nthe natural synthesis of the compiler and Dialogue: 0,0:10:50.98,0:10:55.35,Default,,0000,0000,0000,,interpretative strategies of trying to get\Nthe best of both worlds. It's like, well, Dialogue: 0,0:10:55.35,0:10:59.14,Default,,0000,0000,0000,,we'd like to have a dynamic language with\Nall these features, all these Dialogue: 0,0:10:59.14,0:11:03.88,Default,,0000,0000,0000,,programmer-friendly features but we wanted\Nto run fast and so the JIT will take parts Dialogue: 0,0:11:03.88,0:11:07.83,Default,,0000,0000,0000,,of the code and try and compile them on\Nthe fly and so I try I to sort of Dialogue: 0,0:11:07.83,0:11:13.24,Default,,0000,0000,0000,,[inaudible] the two approaches. It turns\Nout this works pretty well. So all modern Dialogue: 0,0:11:13.24,0:11:18.64,Default,,0000,0000,0000,,browsers now have jets for JavaScript code\Nso actually when you are running Dialogue: 0,0:11:18.64,0:11:24.96,Default,,0000,0000,0000,,JavaScript code even for this class inside\Nof the browser there was a jet that was in Dialogue: 0,0:11:24.96,0:11:30.22,Default,,0000,0000,0000,,a very physical way on the fly, taking\Nthose scraps of JavaScript code and Dialogue: 0,0:11:30.22,0:11:35.39,Default,,0000,0000,0000,,compiling them on the fly, Anyway it, You\Ndo not get exactly the formats of compiled Dialogue: 0,0:11:35.39,0:11:39.22,Default,,0000,0000,0000,,code but it gets fairly close. So, this\Nis, this is actually how most dynamic Dialogue: 0,0:11:39.22,0:11:43.10,Default,,0000,0000,0000,,languages were at first. And I'll say\Nwell, it's an act the value of research Dialogue: 0,0:11:43.10,0:11:43.46,Default,,0000,0000,0000,,but it.