1 00:00:00,000 --> 00:00:02,377 2 00:00:02,377 --> 00:00:04,710 DAVID MALAN: As folks finish signing up, let me bite off 3 00:00:04,710 --> 00:00:06,450 a couple of the smaller questions here. 4 00:00:06,450 --> 00:00:11,630 So one of the questions was, what is a Content Delivery Network, or CDN? 5 00:00:11,630 --> 00:00:14,320 So CDN really is a generic term describing 6 00:00:14,320 --> 00:00:18,620 servers whose purpose in life is to deliver content, which simply means 7 00:00:18,620 --> 00:00:22,260 they are web servers that have hard drives or some other form of storage 8 00:00:22,260 --> 00:00:25,320 that people put files on, generally static files, 9 00:00:25,320 --> 00:00:26,870 and by static I mean unchanging. 10 00:00:26,870 --> 00:00:27,740 You write them once. 11 00:00:27,740 --> 00:00:28,440 You upload them. 12 00:00:28,440 --> 00:00:29,190 And it's an image. 13 00:00:29,190 --> 00:00:30,250 It's static text. 14 00:00:30,250 --> 00:00:33,340 It's not a dynamic interactive website necessarily. 15 00:00:33,340 --> 00:00:37,160 And the CDN's purpose in life is just spit out those files, 16 00:00:37,160 --> 00:00:40,640 when requested, to browsers and do it ideally in a very efficient way, 17 00:00:40,640 --> 00:00:43,850 possibly by using a lot more RAM than might be typical just so that it 18 00:00:43,850 --> 00:00:46,140 can respond very quickly to requests. 19 00:00:46,140 --> 00:00:48,930 And Akamai initially built its business on this kind of idea. 20 00:00:48,930 --> 00:00:52,630 Amazon and Microsoft and Google all have similar services as well. 21 00:00:52,630 --> 00:00:55,627 So there's not all that much that's fundamentally 22 00:00:55,627 --> 00:00:57,710 different from servers with which you're familiar, 23 00:00:57,710 --> 00:00:59,410 but they tend to be global as well. 24 00:00:59,410 --> 00:01:02,190 So using various DNS tricks or load balancing tricks, 25 00:01:02,190 --> 00:01:04,687 do they make it easy to distribute your data globally 26 00:01:04,687 --> 00:01:07,270 because there will be different servers in different countries 27 00:01:07,270 --> 00:01:09,530 or continents for different users. 28 00:01:09,530 --> 00:01:13,360 So we, for instance, distribute a lot of our course videos via Amazon's CDN 29 00:01:13,360 --> 00:01:15,470 so that we can push it out without having 30 00:01:15,470 --> 00:01:19,646 thousands of people come to Harvard.edu servers to try to download the same. 31 00:01:19,646 --> 00:01:22,020 And indeed, when we tried that latter approach years ago, 32 00:01:22,020 --> 00:01:25,180 the servers buckled under the load for some of the largest of files. 33 00:01:25,180 --> 00:01:25,679 Griff? 34 00:01:25,679 --> 00:01:27,780 AUDIENCE: I was just going to say [INAUDIBLE]. 35 00:01:27,780 --> 00:01:31,904 36 00:01:31,904 --> 00:01:40,330 And many of the locations that we try to [INAUDIBLE] are blocked [INAUDIBLE]. 37 00:01:40,330 --> 00:01:42,690 So have CDN or having [INAUDIBLE]. 38 00:01:42,690 --> 00:01:49,380 39 00:01:49,380 --> 00:01:50,880 Otherwise videos will be blocked. 40 00:01:50,880 --> 00:01:52,824 I'm sure you've had this experience before. 41 00:01:52,824 --> 00:01:53,324 [INAUDIBLE] 42 00:01:53,324 --> 00:01:56,170 43 00:01:56,170 --> 00:01:57,420 DAVID MALAN: Yeah, absolutely. 44 00:01:57,420 --> 00:02:00,510 So that's a good work around for when popular consumer services, 45 00:02:00,510 --> 00:02:02,330 like YouTube, are indeed blocked. 46 00:02:02,330 --> 00:02:06,259 And even Netflix you can think of as a CDN of some sort. 47 00:02:06,259 --> 00:02:09,003 And in fact, to address some of that same issue for cost reasons, 48 00:02:09,003 --> 00:02:14,460 though, or for bandwidth reasons, they have, at least they used to have, 49 00:02:14,460 --> 00:02:17,460 a Netflix appliance that you could actually have ISPs installed locally. 50 00:02:17,460 --> 00:02:22,210 So that if Comcast, for instance, was getting tired of having the same movie 51 00:02:22,210 --> 00:02:26,449 files, for instance, downloaded over for their network from some other network, 52 00:02:26,449 --> 00:02:28,240 or if this is just burdening their network, 53 00:02:28,240 --> 00:02:32,690 they could actually cache the files locally, which is some form of CDN 54 00:02:32,690 --> 00:02:33,190 as well. 55 00:02:33,190 --> 00:02:37,164 So that users end up talking to that local cache server instead. 56 00:02:37,164 --> 00:02:39,664 The security of the internet of things-- so just to clarify, 57 00:02:39,664 --> 00:02:44,132 what does the world mean when they say Internet of Things these days-- IOT? 58 00:02:44,132 --> 00:02:45,590 It's kind of the buzzwords du jour. 59 00:02:45,590 --> 00:02:49,190 60 00:02:49,190 --> 00:02:50,122 Alicia? 61 00:02:50,122 --> 00:02:52,366 AUDIENCE: [INAUDIBLE] 62 00:02:52,366 --> 00:02:54,240 DAVID MALAN: Yeah, for some reason, my go-tos 63 00:02:54,240 --> 00:02:56,340 are always the things in the kitchen, too. 64 00:02:56,340 --> 00:03:00,440 Yeah, it's like putting everything on the internet-- Nest thermostats, which 65 00:03:00,440 --> 00:03:04,434 I do have and which I'm a fan of, and other such devices, 66 00:03:04,434 --> 00:03:06,850 like your refrigerator, if it's got a little touch screen, 67 00:03:06,850 --> 00:03:11,880 and the smoke alarms, which that did not go over well for Nest initially. 68 00:03:11,880 --> 00:03:15,240 Bad to release a product where safety is at stake when 69 00:03:15,240 --> 00:03:16,900 you have buggy software in it. 70 00:03:16,900 --> 00:03:19,247 People go up on that fiasco. 71 00:03:19,247 --> 00:03:21,080 But internet of things really just describes 72 00:03:21,080 --> 00:03:22,650 putting more things on the internet. 73 00:03:22,650 --> 00:03:25,860 And I think the question earlier was, can we speak to the security of it? 74 00:03:25,860 --> 00:03:28,310 I dare say I'm fairly pessimistic when it comes to this. 75 00:03:28,310 --> 00:03:31,480 I think we humans have made the exact same mistakes in the world of phones 76 00:03:31,480 --> 00:03:35,070 that we did years ago with PCs and Macs and desktop computers more generally, 77 00:03:35,070 --> 00:03:37,190 where we don't write very good software. 78 00:03:37,190 --> 00:03:40,300 And there's innumerable articles out there about various devices 79 00:03:40,300 --> 00:03:43,100 that are still shipping with default passwords of admin 80 00:03:43,100 --> 00:03:46,890 or password or no password, or some engineer 81 00:03:46,890 --> 00:03:49,510 has hard coded something into a home router, 82 00:03:49,510 --> 00:03:51,580 and no one thought to disable that. 83 00:03:51,580 --> 00:03:53,590 And the list goes on and on. 84 00:03:53,590 --> 00:03:56,850 So I dare say the internet of things won't be very good at security 85 00:03:56,850 --> 00:03:58,900 because we humans haven't gotten all that much 86 00:03:58,900 --> 00:04:00,840 better at these kinds of issues. 87 00:04:00,840 --> 00:04:05,630 But it's interesting to consider the sort of new threats that are imposed. 88 00:04:05,630 --> 00:04:08,670 In fact, I remember it was a wonderful gift from a friend of mine, 89 00:04:08,670 --> 00:04:12,220 when I had first gotten a couple of cats years ago. 90 00:04:12,220 --> 00:04:16,950 He kindly gifted to me this cat feeder that itself was like electronic. 91 00:04:16,950 --> 00:04:19,860 So if you travel, it can feed the cats automatically. 92 00:04:19,860 --> 00:04:23,940 And it had this audit feature, whereby it had a little webcam built 93 00:04:23,940 --> 00:04:27,890 in so you could actually see the food bowl, which is good for reassurance 94 00:04:27,890 --> 00:04:30,280 that the thing's not jammed or you know call a neighbor 95 00:04:30,280 --> 00:04:31,946 if the cats aren't actually getting fed. 96 00:04:31,946 --> 00:04:33,960 So it's a compelling use case for a camera. 97 00:04:33,960 --> 00:04:39,010 But the way it worked was in order to see your live webcam 98 00:04:39,010 --> 00:04:43,950 feed from your cat food feeder, it was going through some server abroad. 99 00:04:43,950 --> 00:04:47,960 So you would go to some random website dog come in whatever country, 100 00:04:47,960 --> 00:04:49,950 and that's how you would watch your live feed. 101 00:04:49,950 --> 00:04:53,170 So it wasn't that you were connecting to your home's IP address, 102 00:04:53,170 --> 00:04:55,890 and you weren't running a web server in your home. 103 00:04:55,890 --> 00:04:59,430 Rather the camera was transmitting this data, similar in spirit to Dropbox, 104 00:04:59,430 --> 00:05:00,599 to some central server. 105 00:05:00,599 --> 00:05:03,390 And if you want to see those bits, you log into that central server 106 00:05:03,390 --> 00:05:06,100 as well, which means any creepy employee of this company 107 00:05:06,100 --> 00:05:09,029 has literally a window into my home. 108 00:05:09,029 --> 00:05:10,820 So it creeped me out, and I couldn't do it. 109 00:05:10,820 --> 00:05:12,700 So I returned it. 110 00:05:12,700 --> 00:05:15,950 And it's gotten me thinking ever since then about home security 111 00:05:15,950 --> 00:05:17,450 cameras, things that are on the web. 112 00:05:17,450 --> 00:05:20,990 Like if you are visiting your own home security camera's data 113 00:05:20,990 --> 00:05:24,350 feed on someone else's website, they too have access to it. 114 00:05:24,350 --> 00:05:26,930 And so these are particularly concerning things. 115 00:05:26,930 --> 00:05:27,830 Avi? 116 00:05:27,830 --> 00:05:29,039 AUDIENCE: [INAUDIBLE] 117 00:05:29,039 --> 00:05:30,080 DAVID MALAN: What's that? 118 00:05:30,080 --> 00:05:30,440 AUDIENCE: [INAUDIBLE] 119 00:05:30,440 --> 00:05:30,750 DAVID MALAN: No. 120 00:05:30,750 --> 00:05:33,958 Because it had a wide enough field of vision where it would capture the bowl, 121 00:05:33,958 --> 00:05:35,910 but also anything over there. 122 00:05:35,910 --> 00:05:37,725 And maybe just at waist height or whatnot, 123 00:05:37,725 --> 00:05:39,850 but it was just like unnecessary information for me 124 00:05:39,850 --> 00:05:42,370 to just be handing over to someone 24/7, I felt. 125 00:05:42,370 --> 00:05:46,673 AUDIENCE: [INAUDIBLE] Smart TV. 126 00:05:46,673 --> 00:05:51,930 127 00:05:51,930 --> 00:05:52,680 DAVID MALAN: Yeah. 128 00:05:52,680 --> 00:05:55,080 No, I'll admit to being paranoid enough where I do not 129 00:05:55,080 --> 00:05:57,590 connect my smart TVs to the like the internet 130 00:05:57,590 --> 00:05:59,860 because it creeps me out that one, many of them 131 00:05:59,860 --> 00:06:02,164 have cameras now for what I think are stupid features, 132 00:06:02,164 --> 00:06:05,080 like waving your hand to change the channel or the volume or whatever, 133 00:06:05,080 --> 00:06:08,730 which can't possibly work reliably in 2016. 134 00:06:08,730 --> 00:06:09,830 So there's that. 135 00:06:09,830 --> 00:06:12,740 Samsung took a lot of heat a year or two ago now 136 00:06:12,740 --> 00:06:16,380 for their smart TVs, in whose privacy policy 137 00:06:16,380 --> 00:06:18,981 it was disclosed-- it was something along the lines of-- it 138 00:06:18,981 --> 00:06:19,980 was a brilliant wording. 139 00:06:19,980 --> 00:06:25,760 It was like we recommend that you not have personal conversations within view 140 00:06:25,760 --> 00:06:26,580 of this TV. 141 00:06:26,580 --> 00:06:30,080 It was something like that, where they were disclosing it, 142 00:06:30,080 --> 00:06:31,240 albeit not on the box. 143 00:06:31,240 --> 00:06:33,750 It was in like the tiny, little printed brochure. 144 00:06:33,750 --> 00:06:36,860 Because for the TV to be able to respond to this 145 00:06:36,860 --> 00:06:39,030 or to be able to respond to your voice a la "hey, 146 00:06:39,030 --> 00:06:42,640 Siri," it's got to be listening all the time. 147 00:06:42,640 --> 00:06:45,190 Alexa, from Amazon, creeps me out for the same reason 148 00:06:45,190 --> 00:06:46,940 because if its constantly listening, which 149 00:06:46,940 --> 00:06:50,050 is billed as a feature, well, who all knows what else its listening to. 150 00:06:50,050 --> 00:06:54,410 And the fact that watching TV in bed or on the sofa, like I don't want this 151 00:06:54,410 --> 00:06:59,210 like constantly projecting whatever it sees onto the internet and even 152 00:06:59,210 --> 00:07:00,290 the voice stuff too. 153 00:07:00,290 --> 00:07:02,580 So I try to disable all of that. 154 00:07:02,580 --> 00:07:04,214 And even here, we humans are bad. 155 00:07:04,214 --> 00:07:06,380 Just two years ago, there was this wonderful article 156 00:07:06,380 --> 00:07:09,880 about Samsung's smart TVs which were being so incredibly dumb. 157 00:07:09,880 --> 00:07:14,180 They were transmitting their data on TCP port 443, which 158 00:07:14,180 --> 00:07:19,370 recall is the secure port for HTTPS, but they weren't encrypting the data 159 00:07:19,370 --> 00:07:20,610 on that port. 160 00:07:20,610 --> 00:07:25,770 So it was a dummy engineer sort of knew that, oh, 161 00:07:25,770 --> 00:07:28,660 you're supposed to run secure traffic through port 443 162 00:07:28,660 --> 00:07:31,160 but didn't realize you also have to enable encryption. 163 00:07:31,160 --> 00:07:34,290 Like it's not enough just to use that number on your virtual envelopes. 164 00:07:34,290 --> 00:07:37,790 And so here, too, all of the data-- and some researcher somewhere noticed this. 165 00:07:37,790 --> 00:07:39,920 Like all of the voice commands or whatever 166 00:07:39,920 --> 00:07:43,090 it was were leaving the TV unencrypted, so that any creepy person 167 00:07:43,090 --> 00:07:46,860 in your Wi-Fi network or in with physical access to your network 168 00:07:46,860 --> 00:07:50,420 could see what's coming out of your TV. 169 00:07:50,420 --> 00:07:52,660 So, yeah, internet of things is frightening. 170 00:07:52,660 --> 00:07:54,920 It just means putting more bad buggy software 171 00:07:54,920 --> 00:07:57,380 in hardware in our physical presence. 172 00:07:57,380 --> 00:07:59,290 So be aware and be mindful of these things, 173 00:07:59,290 --> 00:08:01,040 because I do think we can exercise some judgment. 174 00:08:01,040 --> 00:08:03,180 So if you think that baby monitor's a great idea 175 00:08:03,180 --> 00:08:05,090 to put over your child all the time, realize 176 00:08:05,090 --> 00:08:06,923 that those bits might be getting transmitted 177 00:08:06,923 --> 00:08:09,897 to some creepy company or some third party, and maybe that's not really 178 00:08:09,897 --> 00:08:11,730 a threat because who's really going to care? 179 00:08:11,730 --> 00:08:14,370 But if the server is compromised and now you 180 00:08:14,370 --> 00:08:16,370 do have someone else having eyes into your home, 181 00:08:16,370 --> 00:08:18,411 this is going to become all the more common. 182 00:08:18,411 --> 00:08:19,286 AUDIENCE: [INAUDIBLE] 183 00:08:19,286 --> 00:08:56,736 184 00:08:56,736 --> 00:08:59,110 DAVID MALAN: Yeah, this is kind of the next frontier of-- 185 00:08:59,110 --> 00:08:59,985 AUDIENCE: [INAUDIBLE] 186 00:08:59,985 --> 00:09:08,185 187 00:09:08,185 --> 00:09:10,310 DAVID MALAN: And this one, I daresay, is inevitable 188 00:09:10,310 --> 00:09:12,370 just because all it takes per our discussion 189 00:09:12,370 --> 00:09:17,290 yesterday for one association of you with that history 190 00:09:17,290 --> 00:09:20,382 to be made before you can reconstruct the entirety of your history, right? 191 00:09:20,382 --> 00:09:22,340 If you've been photographing someone for years, 192 00:09:22,340 --> 00:09:24,090 but you've never figured out who they are, 193 00:09:24,090 --> 00:09:27,180 all it takes is for one time for someone to capture a photo, 194 00:09:27,180 --> 00:09:30,270 associate it with their identity, and now we can look back in history 195 00:09:30,270 --> 00:09:33,010 and be like, oh, we have these other thousands of photos of this individual. 196 00:09:33,010 --> 00:09:33,885 AUDIENCE: [INAUDIBLE] 197 00:09:33,885 --> 00:09:36,026 198 00:09:36,026 --> 00:09:38,025 DAVID MALAN: Yeah, now you can check their face. 199 00:09:38,025 --> 00:09:41,745 200 00:09:41,745 --> 00:09:42,620 AUDIENCE: [INAUDIBLE] 201 00:09:42,620 --> 00:09:45,200 202 00:09:45,200 --> 00:09:47,560 DAVID MALAN: Yeah, and it doesn't help that most of us 203 00:09:47,560 --> 00:09:52,360 are proactively tagging ourselves on Facebook and other social media. 204 00:09:52,360 --> 00:09:55,820 So we are creating this database as we speak. 205 00:09:55,820 --> 00:09:59,220 Yeah, no, this one I unfortunately think, pessimistically, is inevitable. 206 00:09:59,220 --> 00:10:01,490 We're not going to be able to avoid it, especially when the cameras are 207 00:10:01,490 --> 00:10:03,672 being put-- I mean, the UK's had this for years. 208 00:10:03,672 --> 00:10:05,130 But it's really just for recording. 209 00:10:05,130 --> 00:10:08,680 Now facial recognition takes it to a whole new level. 210 00:10:08,680 --> 00:10:10,560 I'm already impressed too how good Facebook's 211 00:10:10,560 --> 00:10:14,410 getting at like tagging friends, when even their head is slightly askew 212 00:10:14,410 --> 00:10:16,020 and it's not a great shot. 213 00:10:16,020 --> 00:10:18,160 I mean, it's getting better and better. 214 00:10:18,160 --> 00:10:19,390 So beware. 215 00:10:19,390 --> 00:10:22,404 Some of this stuff, I think, is in our future. 216 00:10:22,404 --> 00:10:24,320 Speaking of, how do you write stuff like this? 217 00:10:24,320 --> 00:10:28,607 So programming-- so what I thought we'd do here 218 00:10:28,607 --> 00:10:30,940 is really just give everyone a taste of what programming 219 00:10:30,940 --> 00:10:33,740 is, albeit in a playful context, using a graphical program that we 220 00:10:33,740 --> 00:10:35,720 use in our undergraduate class called Scratch. 221 00:10:35,720 --> 00:10:39,070 This is a graphical environment that you might have gleaned some images of, 222 00:10:39,070 --> 00:10:41,120 as you registered for an account. 223 00:10:41,120 --> 00:10:44,310 Even though it's playful and technically meant for ages 12 and up, 224 00:10:44,310 --> 00:10:48,390 it is actually wonderfully representative of a typical programming 225 00:10:48,390 --> 00:10:51,450 language-- a certain type of programming language called a procedural 226 00:10:51,450 --> 00:10:55,250 or an imperative programming language-- and as such, 227 00:10:55,250 --> 00:11:01,220 it's very similar in spirit to Java, JavaScript, Python, PHP, Ruby, C++, C#, 228 00:11:01,220 --> 00:11:03,454 any number of languages that you might have heard of. 229 00:11:03,454 --> 00:11:05,370 But it does it in a much more playful context. 230 00:11:05,370 --> 00:11:09,030 But it'll allows us to talk about examples of code 231 00:11:09,030 --> 00:11:11,040 without actually seeing more arcane code. 232 00:11:11,040 --> 00:11:13,680 For instance, just to give you a sense of context, 233 00:11:13,680 --> 00:11:19,510 if I wanted to write a program in a language called C, 234 00:11:19,510 --> 00:11:21,820 I would open up a text editor like this. 235 00:11:21,820 --> 00:11:24,540 And this happens to be a program called Vim, 236 00:11:24,540 --> 00:11:28,390 but it could just as soon be a program like Text Edit or Notepad. 237 00:11:28,390 --> 00:11:30,000 All you need is a text editor. 238 00:11:30,000 --> 00:11:33,120 And I'm going to type some magical incantation like this in this language 239 00:11:33,120 --> 00:11:36,250 called C-- int main void. 240 00:11:36,250 --> 00:11:40,770 And then I'm going to have some curly braces and now a print f hello world, 241 00:11:40,770 --> 00:11:45,940 and now I'm going to say, let's say, return 0. 242 00:11:45,940 --> 00:11:49,240 So some of you might recognize symbols and syntax like this. 243 00:11:49,240 --> 00:11:51,380 But for those who don't, you can perhaps guess 244 00:11:51,380 --> 00:11:54,461 what this does, even if you just ignore anything you don't understand. 245 00:11:54,461 --> 00:11:56,210 Take a guess as to what this program does, 246 00:11:56,210 --> 00:11:57,626 if you've never programmed before. 247 00:11:57,626 --> 00:12:03,020 248 00:12:03,020 --> 00:12:03,780 Take a guess? 249 00:12:03,780 --> 00:12:04,732 AUDIENCE: Writes hello world. 250 00:12:04,732 --> 00:12:06,440 DAVID MALAN: Yeah, it prints hello world. 251 00:12:06,440 --> 00:12:10,530 I don't really know what return means or int main void or include standard io.h. 252 00:12:10,530 --> 00:12:13,570 But printf, albeit, print sounds familiar. 253 00:12:13,570 --> 00:12:15,090 Hello world looks like a sentence. 254 00:12:15,090 --> 00:12:16,610 So let's see what happens. 255 00:12:16,610 --> 00:12:19,390 Now, this is a file called hello.c. 256 00:12:19,390 --> 00:12:23,010 And to run it, I would normally on my Mac or PC double click it. 257 00:12:23,010 --> 00:12:25,510 But this is a text-based environment so I can't do that. 258 00:12:25,510 --> 00:12:27,570 I actually have to run it. 259 00:12:27,570 --> 00:12:33,450 But to run it, I first have to make it or build it with a compiler. 260 00:12:33,450 --> 00:12:37,320 So GCC, Gnu Compiler Collection or a GNU C Compiler, 261 00:12:37,320 --> 00:12:43,110 is a program that has just turned hello.c into the equivalent zeros 262 00:12:43,110 --> 00:12:46,200 and ones that my Intel CPU you will understand. 263 00:12:46,200 --> 00:12:48,200 And if I run this with this magical incantation, 264 00:12:48,200 --> 00:12:51,680 a.out is just the silly default name for my program. 265 00:12:51,680 --> 00:12:56,920 Enter, indeed, as was posited, print hello world. 266 00:12:56,920 --> 00:12:58,490 So not all that interesting. 267 00:12:58,490 --> 00:13:04,530 Let's rewrite this in Java, so hello.Java, class hello, 268 00:13:04,530 --> 00:13:09,650 public static void main string args. 269 00:13:09,650 --> 00:13:13,290 Java's even stupider when it comes to starting the writing a program-- 270 00:13:13,290 --> 00:13:19,840 system.out.print line hello world. 271 00:13:19,840 --> 00:13:23,381 OK, that is the equivalent program in a language called Java. 272 00:13:23,381 --> 00:13:24,380 It's a little different. 273 00:13:24,380 --> 00:13:25,950 But you can kind of glean some similarities. 274 00:13:25,950 --> 00:13:27,250 There's still curly braces. 275 00:13:27,250 --> 00:13:29,067 There's the same string hello world. 276 00:13:29,067 --> 00:13:31,150 There's the word printf, although I could actually 277 00:13:31,150 --> 00:13:35,100 do this with-- print line would be a little more common in Java. 278 00:13:35,100 --> 00:13:36,670 Class is a new word. 279 00:13:36,670 --> 00:13:39,540 It hints at features called object-oriented programming, which Java 280 00:13:39,540 --> 00:13:41,370 offers, as do some other languages. 281 00:13:41,370 --> 00:13:43,780 But this is generally what a text-based language does. 282 00:13:43,780 --> 00:13:45,940 Thankfully, there's even simpler languages. 283 00:13:45,940 --> 00:13:49,880 So if I want to write a program in a language called PHP, 284 00:13:49,880 --> 00:13:59,140 I can simply do print hello world, and this one is now done in PHP. 285 00:13:59,140 --> 00:14:01,740 And you can do this in Python, Ruby, anyhow. 286 00:14:01,740 --> 00:14:04,764 So there's many different languages in the world of programming, 287 00:14:04,764 --> 00:14:06,930 much like there are many different spoken languages. 288 00:14:06,930 --> 00:14:10,650 And much like we could communicate in English or Spanish or Japanese 289 00:14:10,650 --> 00:14:12,930 or any number of other spoken languages, so can you 290 00:14:12,930 --> 00:14:16,520 write programs that at the end of the day do the same thing. 291 00:14:16,520 --> 00:14:20,030 These programs all print hello world, but you express them, 292 00:14:20,030 --> 00:14:22,600 you write those programs in different ways. 293 00:14:22,600 --> 00:14:24,070 So why? 294 00:14:24,070 --> 00:14:27,580 write I can understand that there's thousands or millions of years 295 00:14:27,580 --> 00:14:31,670 of history over which languages evolved independently in different cultures 296 00:14:31,670 --> 00:14:33,650 and kind of mutated over time. 297 00:14:33,650 --> 00:14:38,200 But we humans also invented pretty recently programming languages, 298 00:14:38,200 --> 00:14:39,120 relatively speaking. 299 00:14:39,120 --> 00:14:43,410 Why is there not one programming language with which you write software? 300 00:14:43,410 --> 00:14:45,969 AUDIENCE: [INAUDIBLE] 301 00:14:45,969 --> 00:14:47,010 DAVID MALAN: Competition? 302 00:14:47,010 --> 00:14:47,593 In what sense? 303 00:14:47,593 --> 00:14:49,162 AUDIENCE: [INAUDIBLE] 304 00:14:49,162 --> 00:14:52,120 DAVID MALAN: OK so people might have wanted to make money off of this-- 305 00:14:52,120 --> 00:14:53,953 so make a better language than someone else. 306 00:14:53,953 --> 00:14:57,880 What might it mean to be a better language or a competitor language? 307 00:14:57,880 --> 00:14:58,790 Yeah? 308 00:14:58,790 --> 00:14:59,484 [INAUDIBLE] 309 00:14:59,484 --> 00:15:00,359 AUDIENCE: [INAUDIBLE] 310 00:15:00,359 --> 00:15:20,140 311 00:15:20,140 --> 00:15:24,440 DAVID MALAN: Yeah, which is similar in spirit to the idea of competition. 312 00:15:24,440 --> 00:15:27,420 People decide have decided over time, hey, I can do this better, 313 00:15:27,420 --> 00:15:28,950 or we can do this better. 314 00:15:28,950 --> 00:15:30,630 And better might mean different things. 315 00:15:30,630 --> 00:15:34,150 It might mean that your software at the end of the day runs faster than someone 316 00:15:34,150 --> 00:15:35,250 else's. 317 00:15:35,250 --> 00:15:38,810 It might mean that your software is easier to write than other languages. 318 00:15:38,810 --> 00:15:41,060 And it might not be a competition in a business sense. 319 00:15:41,060 --> 00:15:43,185 A lot of languages have been developed by academics 320 00:15:43,185 --> 00:15:46,900 because we think we can do a better job at improving upon previous languages. 321 00:15:46,900 --> 00:15:52,340 And there are different approaches to languages. 322 00:15:52,340 --> 00:15:58,020 One of which would be called an interpreter versus a compiler. 323 00:15:58,020 --> 00:16:02,260 And what I just did a moment ago was to write a program 324 00:16:02,260 --> 00:16:03,960 in C, my very first program. 325 00:16:03,960 --> 00:16:06,740 And I ran it through a compiler, that thing called GCC. 326 00:16:06,740 --> 00:16:10,690 And what that means in real terms is that you write a program that 327 00:16:10,690 --> 00:16:13,830 looks like this in English-like syntax. 328 00:16:13,830 --> 00:16:16,170 It is definitely cryptic, but Katy was able to glean 329 00:16:16,170 --> 00:16:19,070 what it did-- print out hello world. 330 00:16:19,070 --> 00:16:21,620 You run it through a compiler. 331 00:16:21,620 --> 00:16:24,520 And then at a little bit of an oversimplification, what 332 00:16:24,520 --> 00:16:28,730 comes out of that is a whole bunch of zeros and ones 333 00:16:28,730 --> 00:16:31,240 that the Intel CPU understands. 334 00:16:31,240 --> 00:16:35,610 And the compiler is specific to the CPU so that if you have, 335 00:16:35,610 --> 00:16:39,100 back in the day, a Mac or a PC or some other kind of device, 336 00:16:39,100 --> 00:16:41,920 the compiler would spit out zeros and ones that the Mac understands 337 00:16:41,920 --> 00:16:44,550 or the PC understands or the Linux computer understands. 338 00:16:44,550 --> 00:16:46,780 It's also tied, in part, to the operating system, 339 00:16:46,780 --> 00:16:48,430 not just the underlying CPU. 340 00:16:48,430 --> 00:16:52,200 Most consumer computers these days have Intel CPUs. 341 00:16:52,200 --> 00:16:55,070 So they're using the same underlying hardware, 342 00:16:55,070 --> 00:16:59,180 but the operating system is certainly the different across different types 343 00:16:59,180 --> 00:17:01,239 of computers-- Macs, PCs, and the like. 344 00:17:01,239 --> 00:17:03,030 And so this is generally what happens here. 345 00:17:03,030 --> 00:17:05,119 And what does it mean for Intel to be inside? 346 00:17:05,119 --> 00:17:07,839 Well, among the things that Intel CPU, or any CPA does, 347 00:17:07,839 --> 00:17:10,550 is it has a certain set of instructions that it understands. 348 00:17:10,550 --> 00:17:13,200 And I had proposed yesterday they're pretty basic instructions, 349 00:17:13,200 --> 00:17:16,500 like addition, subtraction, multiplication, move something 350 00:17:16,500 --> 00:17:18,650 from here over here in memory, load something 351 00:17:18,650 --> 00:17:21,839 from here to here in memory-- very simple operations. 352 00:17:21,839 --> 00:17:24,010 And in the interest of abstraction, let me just 353 00:17:24,010 --> 00:17:27,270 stipulate you can get from admission of subtraction 354 00:17:27,270 --> 00:17:31,247 and multiplication all the way up to Photoshop and YouTube and playing 355 00:17:31,247 --> 00:17:32,080 videos and the like. 356 00:17:32,080 --> 00:17:33,350 There's a layering there. 357 00:17:33,350 --> 00:17:35,690 But a compiler is necessary to go from something 358 00:17:35,690 --> 00:17:39,970 that's pretty human readable, if cryptic looking to the uninitiated, 359 00:17:39,970 --> 00:17:41,560 to those zeros and ones. 360 00:17:41,560 --> 00:17:47,240 An interpreted language, by contrast, rather skips this step. 361 00:17:47,240 --> 00:17:50,020 And actually I didn't quite leave enough space on the board here, 362 00:17:50,020 --> 00:17:55,860 so let's-- CPU, from there to there. 363 00:17:55,860 --> 00:18:00,534 An interpreted language might look the same-- or rather in a language 364 00:18:00,534 --> 00:18:01,950 that you're planning to interpret. 365 00:18:01,950 --> 00:18:05,390 You run it through an interpreter. 366 00:18:05,390 --> 00:18:07,920 And at the risk of oversimplifying here, too, 367 00:18:07,920 --> 00:18:13,075 let me just say that it essentially gets run directly on the CPU. 368 00:18:13,075 --> 00:18:14,450 There's some stuff happening. 369 00:18:14,450 --> 00:18:17,780 Really, what the interpreter is doing is reading your code top 370 00:18:17,780 --> 00:18:19,110 to bottom, left to right. 371 00:18:19,110 --> 00:18:23,590 And any time it sees an instruction it recognizes, it inside of it 372 00:18:23,590 --> 00:18:27,350 has zeros and ones that the CPU understands. 373 00:18:27,350 --> 00:18:29,553 So the interpreter is what's running on the CPU, 374 00:18:29,553 --> 00:18:32,930 and it's interpreting your program line by line. 375 00:18:32,930 --> 00:18:36,180 By contrast, when you compile a program with a compiler, 376 00:18:36,180 --> 00:18:39,080 it's your zeros and ones that are running on the CPU, 377 00:18:39,080 --> 00:18:41,010 and that's a reasonable distinction. 378 00:18:41,010 --> 00:18:47,280 So historically, languages like C and C++, older languages, were compiled. 379 00:18:47,280 --> 00:18:50,850 And a lot of more modern languages tend to be interpreted. 380 00:18:50,850 --> 00:18:53,750 Technically, you can compile or interpret any type of language. 381 00:18:53,750 --> 00:18:57,770 It depends on if the software exists, but they correlate 382 00:18:57,770 --> 00:18:59,620 with certain historical traditions. 383 00:18:59,620 --> 00:19:02,600 So c and C++ have tended to be compiled languages. 384 00:19:02,600 --> 00:19:08,330 More modern languages, like Python and Ruby and PHP, have been interpreted. 385 00:19:08,330 --> 00:19:11,830 Java is kind of a weird middleman, whereby you do compile it, 386 00:19:11,830 --> 00:19:14,230 but you compile it not into zeros and ones per se, 387 00:19:14,230 --> 00:19:16,040 but into something called byte codes. 388 00:19:16,040 --> 00:19:21,440 And byte codes are instructions that the Java virtual machine understands. 389 00:19:21,440 --> 00:19:24,810 So among Sun Microsystem's contributions the world years ago, 390 00:19:24,810 --> 00:19:28,460 when they invented Java, is instead of assuming an Intel CPU, 391 00:19:28,460 --> 00:19:31,840 they essentially created their own CPU in software 392 00:19:31,840 --> 00:19:37,620 so that their Java code could run on Macs, on PCs, on Linux computers. 393 00:19:37,620 --> 00:19:41,270 But you had to have the Java virtual machine software, the Java Runtime 394 00:19:41,270 --> 00:19:43,550 Environment, running on your computer. 395 00:19:43,550 --> 00:19:46,330 But that's still used today in different contexts. 396 00:19:46,330 --> 00:19:49,180 But this is a reasonable type of categorization-- interpreted 397 00:19:49,180 --> 00:19:51,530 and compiling your software. 398 00:19:51,530 --> 00:19:54,160 So let's just do a quick laundry list of languages, if only 399 00:19:54,160 --> 00:19:59,200 to get it out there so as to dispel any confusion as to what languages are. 400 00:19:59,200 --> 00:20:03,040 So C, C++, C#, take it from there. 401 00:20:03,040 --> 00:20:05,338 What else have we heard of? 402 00:20:05,338 --> 00:20:08,080 AUDIENCE: [INAUDIBLE] 403 00:20:08,080 --> 00:20:13,500 DAVID MALAN: Go, Java, I heard JavaScript, I think. 404 00:20:13,500 --> 00:20:16,200 Fun fact-- not at all related to one another. 405 00:20:16,200 --> 00:20:18,750 JavaScript came after, and the marketing people 406 00:20:18,750 --> 00:20:21,220 decided that, oh, Java's so trendy, why don't we 407 00:20:21,220 --> 00:20:23,950 call our language JavaScript, essentially dupe people 408 00:20:23,950 --> 00:20:26,780 into thinking they're related and get this one popular too. 409 00:20:26,780 --> 00:20:30,128 Turns out it became popular but has no relation to Java. 410 00:20:30,128 --> 00:20:31,490 AUDIENCE: [INAUDIBLE] 411 00:20:31,490 --> 00:20:34,475 DAVID MALAN: React would be a framework not a language per se. 412 00:20:34,475 --> 00:20:35,350 AUDIENCE: [INAUDIBLE] 413 00:20:35,350 --> 00:20:37,201 DAVID MA LAN: Python, 414 00:20:37,201 --> 00:20:37,700 415 00:20:37,700 --> 00:20:38,600 AUDIENCE: [INAUDIBLE] 416 00:20:38,600 --> 00:20:40,430 DAVID MALAN: Ruby-- I am actually amazed. 417 00:20:40,430 --> 00:20:47,270 We're actually doing these alphabetically accidentally-- amazing. 418 00:20:47,270 --> 00:20:49,320 Python, I heard Ruby. 419 00:20:49,320 --> 00:20:52,962 I can only take languages starting with S or later. 420 00:20:52,962 --> 00:20:54,192 AUDIENCE: SQL. 421 00:20:54,192 --> 00:20:56,616 DAVID MALAN: SQL, we'll talk more about that later. 422 00:20:56,616 --> 00:20:57,490 AUDIENCE: [INAUDIBLE] 423 00:20:57,490 --> 00:21:00,340 DAVID MALAN: Perl-- oh, dammit, you broke my system. 424 00:21:00,340 --> 00:21:01,375 Perl. 425 00:21:01,375 --> 00:21:02,250 AUDIENCE: [INAUDIBLE] 426 00:21:02,250 --> 00:21:07,130 DAVID MALAN: No, so PHP-- Django is a framework. 427 00:21:07,130 --> 00:21:09,700 So we'll talk about that later-- not a language. 428 00:21:09,700 --> 00:21:12,340 And we'll distinguish what that means later. 429 00:21:12,340 --> 00:21:13,300 AUDIENCE: [INAUDIBLE] 430 00:21:13,300 --> 00:21:14,549 DAVID MALAN: What's that, VBA? 431 00:21:14,549 --> 00:21:15,770 Yeah, Visual Basic. 432 00:21:15,770 --> 00:21:18,117 Yeah, so VB or VB Script. 433 00:21:18,117 --> 00:21:18,891 AUDIENCE: .NET. 434 00:21:18,891 --> 00:21:21,211 DAVID MALAN: .NET isn't a language per se. 435 00:21:21,211 --> 00:21:23,460 It's a collection of stuff that you would usually use, 436 00:21:23,460 --> 00:21:28,560 like Visual Basic or C# with, so I'd put that into the framework category. 437 00:21:28,560 --> 00:21:30,915 Other languages come to mind? 438 00:21:30,915 --> 00:21:31,790 AUDIENCE: [INAUDIBLE] 439 00:21:31,790 --> 00:21:33,630 DAVID MALAN: Swift is a new one from Apple 440 00:21:33,630 --> 00:21:36,340 designed to make iPhone programming and Mac programming easier. 441 00:21:36,340 --> 00:21:39,890 Objective-C is the earlier language that they used for many years 442 00:21:39,890 --> 00:21:42,940 on Macs and iPhones. 443 00:21:42,940 --> 00:21:43,880 AUDIENCE: [INAUDIBLE] 444 00:21:43,880 --> 00:21:46,410 DAVID MALAN: Julia, oh, I don't know that one. 445 00:21:46,410 --> 00:21:47,076 This? 446 00:21:47,076 --> 00:21:47,950 AUDIENCE: [INAUDIBLE] 447 00:21:47,950 --> 00:21:50,590 DAVID MALAN: OK, nice. 448 00:21:50,590 --> 00:21:53,440 Others? 449 00:21:53,440 --> 00:21:54,870 AUDIENCE: [INAUDIBLE] 450 00:21:54,870 --> 00:22:01,670 DAVID MALAN: Yeah, so BASIC, Pascal, COBOL-- 451 00:22:01,670 --> 00:22:04,140 we used to capitalize all languages-- FORTRAN. 452 00:22:04,140 --> 00:22:07,979 453 00:22:07,979 --> 00:22:10,382 It's a lot, and it's kind of overwhelming. 454 00:22:10,382 --> 00:22:13,280 And many programmers will know many languages, 455 00:22:13,280 --> 00:22:16,050 I daresay far more than a typical human would 456 00:22:16,050 --> 00:22:18,561 understand spoken or written languages. 457 00:22:18,561 --> 00:22:19,060 So 458 00:22:19,060 --> 00:22:19,920 Why is that? 459 00:22:19,920 --> 00:22:23,110 Well, I think Anissa made the claim earlier that different languages are 460 00:22:23,110 --> 00:22:24,486 better for certain things. 461 00:22:24,486 --> 00:22:25,610 And that's indeed the case. 462 00:22:25,610 --> 00:22:29,160 And most anything we discuss today we'll be a sweeping generalization 463 00:22:29,160 --> 00:22:32,540 because there's a lot of religiousness in the technical world, 464 00:22:32,540 --> 00:22:36,300 where people will bring to the table their own bias or preferences 465 00:22:36,300 --> 00:22:37,056 or experiences. 466 00:22:37,056 --> 00:22:39,430 And this too is an important thing to realize, especially 467 00:22:39,430 --> 00:22:42,997 when hiring technical folks or discussing things with engineers. 468 00:22:42,997 --> 00:22:45,330 They're going to bring their own solutions to the table, 469 00:22:45,330 --> 00:22:48,592 and it's perfectly acceptable if someone is recommending something 470 00:22:48,592 --> 00:22:51,550 just because they know it well, they've used it well, they know the ins 471 00:22:51,550 --> 00:22:55,310 and outs, because that alone can be a positive and save cost and so forth. 472 00:22:55,310 --> 00:22:59,680 But it can also be a downside if someone's knowledge or expertise 473 00:22:59,680 --> 00:23:02,840 is dated, if they're using the wrong tools for the job. 474 00:23:02,840 --> 00:23:05,227 For instance, like back in the day, I first 475 00:23:05,227 --> 00:23:07,310 learned web programming in a language called Perl. 476 00:23:07,310 --> 00:23:09,400 And this was 20 or so years ago. 477 00:23:09,400 --> 00:23:12,190 No one really uses Perl for web programming anymore. 478 00:23:12,190 --> 00:23:12,690 You can. 479 00:23:12,690 --> 00:23:14,648 It certainly still works, and they've continued 480 00:23:14,648 --> 00:23:16,270 to modernize it and add features. 481 00:23:16,270 --> 00:23:19,870 But just no one really does it, and so it would be a strange choice but not 482 00:23:19,870 --> 00:23:21,700 an indefensible one. 483 00:23:21,700 --> 00:23:25,120 Using is C possible for making websites. 484 00:23:25,120 --> 00:23:27,910 That would be very, very strange these days 485 00:23:27,910 --> 00:23:31,300 and harder to justify because you have to write so much more 486 00:23:31,300 --> 00:23:34,972 code in a language like C to get real work done, 487 00:23:34,972 --> 00:23:36,680 because it just wasn't designed for that. 488 00:23:36,680 --> 00:23:41,900 By contrast, PHP was designed for a web, and it was actually 489 00:23:41,900 --> 00:23:43,770 designed fairly sloppily initially. 490 00:23:43,770 --> 00:23:46,280 But it made web programming so, so easy. 491 00:23:46,280 --> 00:23:48,270 And one of the reasons it's been so accessible 492 00:23:48,270 --> 00:23:52,470 is because it's been so deliberately intertwined with web development. 493 00:23:52,470 --> 00:23:57,720 More recently has Python and Ruby gotten popular for web development, 494 00:23:57,720 --> 00:23:59,990 but neither of them were designed for the web 495 00:23:59,990 --> 00:24:02,510 per se in quite the same way as PHP has. 496 00:24:02,510 --> 00:24:06,480 So per our upcoming chat later, there've been a lot of libraries or frameworks 497 00:24:06,480 --> 00:24:07,230 that have emerged. 498 00:24:07,230 --> 00:24:09,410 People have written code to make your life easier 499 00:24:09,410 --> 00:24:13,230 if you want to use Python or Ruby for web programming. 500 00:24:13,230 --> 00:24:15,960 Rails, for instance-- Ruby on Rails is a popular expression, 501 00:24:15,960 --> 00:24:18,410 and it describes a framework that you allows 502 00:24:18,410 --> 00:24:20,732 you to use Ruby for web programming. 503 00:24:20,732 --> 00:24:22,190 So the short answer is, it depends. 504 00:24:22,190 --> 00:24:24,845 And if had to make a bold claim for web programming 505 00:24:24,845 --> 00:24:27,220 these days, which will be our focus later this afternoon, 506 00:24:27,220 --> 00:24:29,410 JavaScript is prerequisite because, thank god, 507 00:24:29,410 --> 00:24:33,510 there's only like one language that you can really use on all browsers' client 508 00:24:33,510 --> 00:24:36,620 side, more on that later, but running inside of the confines of a web 509 00:24:36,620 --> 00:24:37,120 browser. 510 00:24:37,120 --> 00:24:39,320 So you pretty much only get JavaScript there. 511 00:24:39,320 --> 00:24:44,960 But also super popular on the back end, so to speak, would be Python, Ruby, 512 00:24:44,960 --> 00:24:51,260 PHP, C# in the Windows world, and Java, I would say. 513 00:24:51,260 --> 00:24:52,400 And that's changing. 514 00:24:52,400 --> 00:24:54,660 And even that is just kind of current trends. 515 00:24:54,660 --> 00:24:58,970 Go is increasingly popular, and other languages still could be used. 516 00:24:58,970 --> 00:25:01,040 And there's some not even on the list here. 517 00:25:01,040 --> 00:25:03,548 So these are really just tendencies. 518 00:25:03,548 --> 00:25:04,396 [INAUDIBLE] 519 00:25:04,396 --> 00:25:04,820 AUDIENCE: [INAUDIBLE] 520 00:25:04,820 --> 00:25:05,486 DAVID MALAN: No. 521 00:25:05,486 --> 00:25:09,480 So per yesterday, I would emphasize that HTML is a markup languages. 522 00:25:09,480 --> 00:25:12,089 It's only about aesthetics and structuring of data. 523 00:25:12,089 --> 00:25:13,880 It, doesn't have the ability, as we'll soon 524 00:25:13,880 --> 00:25:17,830 see, to express yourself logically. 525 00:25:17,830 --> 00:25:21,200 And there's a couple little exceptions to that in CSS. 526 00:25:21,200 --> 00:25:23,990 But no, it's not a programming language. 527 00:25:23,990 --> 00:25:28,210 You could not write-- well, you could make a web page that says hello world. 528 00:25:28,210 --> 00:25:32,240 You cannot write a program that runs on the CPU of a computer that says hello 529 00:25:32,240 --> 00:25:33,340 world with HTML. 530 00:25:33,340 --> 00:25:34,215 AUDIENCE: [INAUDIBLE] 531 00:25:34,215 --> 00:25:40,280 532 00:25:40,280 --> 00:25:45,214 DAVID MALAN: That would be a-- well, it's slightly apples and oranges. 533 00:25:45,214 --> 00:25:46,130 I know what they mean. 534 00:25:46,130 --> 00:25:52,170 Java is a horrible language for making web pages because it never caught on. 535 00:25:52,170 --> 00:25:53,767 It was designed as a wonderful idea. 536 00:25:53,767 --> 00:25:55,350 You could write your software in Java. 537 00:25:55,350 --> 00:25:58,990 You could then embed what's called a Java applet inside of a web browser. 538 00:25:58,990 --> 00:26:02,540 The problem is that browsers never really supported this very well. 539 00:26:02,540 --> 00:26:06,690 Apple has had a little fit with Oracle, and it 540 00:26:06,690 --> 00:26:09,640 doesn't make it easy to even use Java on Macs these days. 541 00:26:09,640 --> 00:26:12,690 And it was always damn slow to load a so-called Java 542 00:26:12,690 --> 00:26:13,890 applet in the web browser. 543 00:26:13,890 --> 00:26:16,870 It wasn't necessarily as accessible as native browser support was. 544 00:26:16,870 --> 00:26:19,400 So Java applets are dead, so far as the web are concerned. 545 00:26:19,400 --> 00:26:21,170 It has been the case for some time. 546 00:26:21,170 --> 00:26:25,110 So if there was legacy software written in Java, not a good thing for the web 547 00:26:25,110 --> 00:26:25,710 anyway. 548 00:26:25,710 --> 00:26:30,600 Using HTML 5 technically refers only to the language we talked about yesterday. 549 00:26:30,600 --> 00:26:36,397 But it's also arguably an umbrella term for HTML 5 and CSS and JavaScript. 550 00:26:36,397 --> 00:26:37,480 And that would make sense. 551 00:26:37,480 --> 00:26:39,730 So they're kind of oversimplifying when they say that. 552 00:26:39,730 --> 00:26:42,310 But that would be the casual way of saying it. 553 00:26:42,310 --> 00:26:43,210 Good question. 554 00:26:43,210 --> 00:26:43,710 Yeah? 555 00:26:43,710 --> 00:26:45,110 AUDIENCE: [INAUDIBLE] 556 00:26:45,110 --> 00:26:48,840 DAVID MALAN: Yeah, Scala, too-- also very popular, 557 00:26:48,840 --> 00:26:51,650 especially with data-driven applications. 558 00:26:51,650 --> 00:26:53,960 But in short, there's not necessarily one right answer. 559 00:26:53,960 --> 00:26:55,880 But there probably are some wrong answers. 560 00:26:55,880 --> 00:26:57,540 And the way to glean what's appropriate here, 561 00:26:57,540 --> 00:27:00,623 especially if you're vetting a proposal from some engineers or your trying 562 00:27:00,623 --> 00:27:03,410 to decide whom to hire, is frankly, especially if you're 563 00:27:03,410 --> 00:27:07,390 relatively non-technical, is just ask the advice of someone technical 564 00:27:07,390 --> 00:27:11,570 you know to vet their resume s maybe Google around as to the technologies 565 00:27:11,570 --> 00:27:13,770 the person or persons are proposing to bring 566 00:27:13,770 --> 00:27:16,340 to bear on the solution, just to get a sense of 567 00:27:16,340 --> 00:27:18,240 whether or not they're making good decisions. 568 00:27:18,240 --> 00:27:21,406 And we'll see this afternoon, there's any number of other lower-level design 569 00:27:21,406 --> 00:27:23,620 decisions independent of language that can also 570 00:27:23,620 --> 00:27:28,340 kind of hint at the quality of someone's thought process or experience as well. 571 00:27:28,340 --> 00:27:34,590 Fortunately, in the phone world-- so let me actually clarify a couple of these. 572 00:27:34,590 --> 00:27:43,860 So let me propose that back end, the back end, front end, back end, 573 00:27:43,860 --> 00:27:50,940 back end, back end, and then M for mobile, and also Java would be mobile. 574 00:27:50,940 --> 00:27:55,220 So thankfully, in the world of mobile applications, 575 00:27:55,220 --> 00:27:57,880 you pretty much only have Swft-- you only 576 00:27:57,880 --> 00:28:01,250 have Swift and Objective-C on iPhones. 577 00:28:01,250 --> 00:28:03,437 Or in the world of Android you have Java. 578 00:28:03,437 --> 00:28:05,520 And those are by far, the biggest phone providers, 579 00:28:05,520 --> 00:28:08,103 so those are kind of the only two scenarios to consider today. 580 00:28:08,103 --> 00:28:09,580 However, there's a middle ground. 581 00:28:09,580 --> 00:28:15,820 You can implement mobile applications using HTML 5 and JavaScript and CSS. 582 00:28:15,820 --> 00:28:18,360 And in fact, a common strategy initially, especially 583 00:28:18,360 --> 00:28:20,550 for startups who don't have the money or the time 584 00:28:20,550 --> 00:28:24,230 or the expertise to develop not only an iPhone application and also an Android 585 00:28:24,230 --> 00:28:27,130 application and maybe Windows Phone or a couple of other things, 586 00:28:27,130 --> 00:28:32,890 is instead not to write any code in Java or Objective-C or Swift, 587 00:28:32,890 --> 00:28:36,200 but instead implement essentially a mobile-friendly website 588 00:28:36,200 --> 00:28:39,530 and then use third-party software that gives you 589 00:28:39,530 --> 00:28:42,614 a tiny bit of Objective-C code or Swift code or Java code. 590 00:28:42,614 --> 00:28:44,530 But then you follow their instructions and you 591 00:28:44,530 --> 00:28:49,535 embed your web-based application inside of a tiny bit of Objective-C, Swift, 592 00:28:49,535 --> 00:28:51,360 or Java code that someone else wrote. 593 00:28:51,360 --> 00:28:57,870 You run a special command that creates for you a native iPhone or Android 594 00:28:57,870 --> 00:29:01,200 application that you can upload to the App Store or the Google Play Store 595 00:29:01,200 --> 00:29:04,590 and so users can actually download it or even pay for it in the store. 596 00:29:04,590 --> 00:29:07,600 But really that's just giving you a big rectangular region 597 00:29:07,600 --> 00:29:12,482 in your app, the contents of which are actually just a web page. 598 00:29:12,482 --> 00:29:15,440 So the upside of this is you don't have to know any of these languages. 599 00:29:15,440 --> 00:29:17,190 You can do all the stuff we did yesterday, 600 00:29:17,190 --> 00:29:19,650 plus a bit more when we talk about JavaScript layer today. 601 00:29:19,650 --> 00:29:22,620 And you can build it once, literally, and it'll 602 00:29:22,620 --> 00:29:25,100 work on all different platforms. 603 00:29:25,100 --> 00:29:28,361 So the upside of that is obvious in so far as you now need no expertise here. 604 00:29:28,361 --> 00:29:30,360 You also don't need to hire twice as many people 605 00:29:30,360 --> 00:29:34,180 to develop twice as many apps for iPhone and Android. 606 00:29:34,180 --> 00:29:37,160 But what's a downside perhaps? 607 00:29:37,160 --> 00:29:39,590 Why doesn't everyone do this? 608 00:29:39,590 --> 00:29:41,650 Why are these Ms even on the list? 609 00:29:41,650 --> 00:29:45,680 610 00:29:45,680 --> 00:29:48,170 Yeah, you can't quite do as much cool stuff. 611 00:29:48,170 --> 00:29:51,040 So, for instance, web-based applications tend 612 00:29:51,040 --> 00:29:54,180 not to have as much access to the hardware itself. 613 00:29:54,180 --> 00:29:57,190 So if a web-based application wants to know your location, 614 00:29:57,190 --> 00:29:59,780 for like a map-based tool, GPS-based tool, 615 00:29:59,780 --> 00:30:01,872 the user is going to be forcibly prompted, 616 00:30:01,872 --> 00:30:03,830 hey, this web page wants to know your location. 617 00:30:03,830 --> 00:30:04,420 Is that OK? 618 00:30:04,420 --> 00:30:06,253 You might not want to allow that experience. 619 00:30:06,253 --> 00:30:09,420 That's not a great you US, or user experience, mildly annoying. 620 00:30:09,420 --> 00:30:12,600 You might not have physical access at all to the camera. 621 00:30:12,600 --> 00:30:14,647 Like a web page or a web-based application 622 00:30:14,647 --> 00:30:16,230 can't necessarily turn on your camera. 623 00:30:16,230 --> 00:30:17,840 It would be a little creepy if you visit a website 624 00:30:17,840 --> 00:30:19,350 and suddenly your camera turns on. 625 00:30:19,350 --> 00:30:21,820 So there's those kinds of defenses mechanisms in place. 626 00:30:21,820 --> 00:30:25,510 The frameworks I alluded to earlier that allow 627 00:30:25,510 --> 00:30:29,060 you to wrap your program in someone else's code 628 00:30:29,060 --> 00:30:31,030 and create the illusion of a native application 629 00:30:31,030 --> 00:30:34,440 sometimes do give you access to the hardware, but not all of it. 630 00:30:34,440 --> 00:30:37,780 And it tends to be a little slower to run web-based applications. 631 00:30:37,780 --> 00:30:40,310 Facebook's mobile app initially was web-based. 632 00:30:40,310 --> 00:30:44,950 And if you use it at all, you might have forgotten how slow their phone 633 00:30:44,950 --> 00:30:46,105 app originally was. 634 00:30:46,105 --> 00:30:48,230 And that was because it was really just a web page. 635 00:30:48,230 --> 00:30:50,320 So when you clicked a link, it was like reloading more content. 636 00:30:50,320 --> 00:30:51,360 It wasn't native. 637 00:30:51,360 --> 00:30:54,450 So native applications, so to speak, written in these three languages, 638 00:30:54,450 --> 00:30:55,760 just tend to feel zippier. 639 00:30:55,760 --> 00:30:58,120 They tend to fail faster, more performance. 640 00:30:58,120 --> 00:31:03,338 And they're much, much, much better for games and such using native. 641 00:31:03,338 --> 00:31:06,670 Native means written in one of these languages. 642 00:31:06,670 --> 00:31:10,815 And web app would be written in HTML, JavaScript, and CSS. 643 00:31:10,815 --> 00:31:13,510 644 00:31:13,510 --> 00:31:14,770 Yeah? 645 00:31:14,770 --> 00:31:19,560 AUDIENCE: Is the big picture [INAUDIBLE]? 646 00:31:19,560 --> 00:31:24,550 647 00:31:24,550 --> 00:31:26,622 DAVID MALAN: Define big picture. 648 00:31:26,622 --> 00:31:27,830 You mean the total landscape? 649 00:31:27,830 --> 00:31:29,690 AUDIENCE: Yeah, total landscape. 650 00:31:29,690 --> 00:31:33,141 This right here [INAUDIBLE]. 651 00:31:33,141 --> 00:31:34,432 DAVID MALAN: Yeah, it's bigger. 652 00:31:34,432 --> 00:31:36,950 653 00:31:36,950 --> 00:31:37,560 Hundreds? 654 00:31:37,560 --> 00:31:40,184 I mean there's probably some that are not on the Wikipedia page 655 00:31:40,184 --> 00:31:42,170 I'm about to pull up to try to overwhelm you. 656 00:31:42,170 --> 00:31:44,730 Oh, here it is-- list of programming languages. 657 00:31:44,730 --> 00:31:54,230 So those are the A's, the B's, and there is one called B, which came before C. 658 00:31:54,230 --> 00:31:56,090 Here's the D's. 659 00:31:56,090 --> 00:31:57,070 Here's the landscape. 660 00:31:57,070 --> 00:32:02,130 If I can punt to a Wikipedia answer, but most of these are fairly specialized, 661 00:32:02,130 --> 00:32:03,870 outdated, silly. 662 00:32:03,870 --> 00:32:06,980 Pizza language-- I don't even know what that one is. 663 00:32:06,980 --> 00:32:08,010 R is popular. 664 00:32:08,010 --> 00:32:09,634 We could have tossed that on the board. 665 00:32:09,634 --> 00:32:13,870 That's popular for data analysis stuff these days. 666 00:32:13,870 --> 00:32:16,860 And there's some silly things-- Unreal scripts, presumably 667 00:32:16,860 --> 00:32:18,590 for a gaming engine. 668 00:32:18,590 --> 00:32:20,810 Very few Z's and Y's, so that's where you 669 00:32:20,810 --> 00:32:23,740 want to go if you want to come up with a new name perhaps. 670 00:32:23,740 --> 00:32:26,950 So that's more complete landscape, and I'm 671 00:32:26,950 --> 00:32:30,320 guessing there are some missing from there still. 672 00:32:30,320 --> 00:32:33,132 So you have all of these ingredients, all of these languages. 673 00:32:33,132 --> 00:32:35,090 What does it mean to be a programming language? 674 00:32:35,090 --> 00:32:36,673 What are some of the basic constructs? 675 00:32:36,673 --> 00:32:41,480 Well, at the risk of being-- let's see how might we implement this? 676 00:32:41,480 --> 00:32:44,240 Yesterday's example of the phone book. 677 00:32:44,240 --> 00:32:46,290 Let's writes that program. 678 00:32:46,290 --> 00:32:49,110 So recall that I was searching for Mike Smith, 679 00:32:49,110 --> 00:32:52,090 and I wanted to somehow find Mike Smith in the phone book. 680 00:32:52,090 --> 00:32:54,330 Let's see if we can't translate the human intuition 681 00:32:54,330 --> 00:32:57,210 we had for our third algorithm, the fastest algorithm, 682 00:32:57,210 --> 00:32:58,780 into something code-like. 683 00:32:58,780 --> 00:33:01,840 And indeed a language, not on the board because it doesn't exist, 684 00:33:01,840 --> 00:33:05,930 is called pseudo code, and this is just arbitrary English-like syntax. 685 00:33:05,930 --> 00:33:07,200 There is no standard for it. 686 00:33:07,200 --> 00:33:10,830 But it just should be roughly intuitive and human readable to anyone. 687 00:33:10,830 --> 00:33:12,460 It's no special syntax for this. 688 00:33:12,460 --> 00:33:14,440 There's no curly braces or any of that. 689 00:33:14,440 --> 00:33:17,720 So what might have the first step been? 690 00:33:17,720 --> 00:33:20,340 Pick up phone book. 691 00:33:20,340 --> 00:33:24,020 What's the second step from yesterday? 692 00:33:24,020 --> 00:33:27,330 Looking for Mike Smith. 693 00:33:27,330 --> 00:33:28,380 Flip pages? 694 00:33:28,380 --> 00:33:32,720 OK, so let me say this feels way too vague and abstract. 695 00:33:32,720 --> 00:33:35,841 So let's undo. 696 00:33:35,841 --> 00:33:38,340 And that would seem to induce an infinite loop, if you will. 697 00:33:38,340 --> 00:33:39,840 Flip pages, what does that mean? 698 00:33:39,840 --> 00:33:41,140 I kind of do that endlessly. 699 00:33:41,140 --> 00:33:43,720 We have to be more precise now. 700 00:33:43,720 --> 00:33:45,090 Half pages-- so OK. 701 00:33:45,090 --> 00:33:50,670 So how about open, let me just say, to middle of phone book. 702 00:33:50,670 --> 00:33:52,510 That feels reasonably precise. 703 00:33:52,510 --> 00:33:54,640 We could then really be nit picking and be like, 704 00:33:54,640 --> 00:33:56,550 what do mean open the phone book? 705 00:33:56,550 --> 00:33:58,765 But open to the middle of the phone book, then what? 706 00:33:58,765 --> 00:34:02,950 707 00:34:02,950 --> 00:34:04,820 AUDIENCE: [INAUDIBLE] 708 00:34:04,820 --> 00:34:10,920 DAVID MALAN: So look at pages, decide if name to left or right 709 00:34:10,920 --> 00:34:13,239 feels like a reasonable way of expressing it. 710 00:34:13,239 --> 00:34:15,949 And now I have kind of a decision point. 711 00:34:15,949 --> 00:34:18,360 These are all instructions or statements, 712 00:34:18,360 --> 00:34:19,719 or I might call them functions. 713 00:34:19,719 --> 00:34:20,989 These are actions. 714 00:34:20,989 --> 00:34:22,880 Now I have to think. 715 00:34:22,880 --> 00:34:25,030 What's the question I need to ask myself? 716 00:34:25,030 --> 00:34:26,389 AUDIENCE: [INAUDIBLE] 717 00:34:26,389 --> 00:34:31,850 DAVID MALAN: Yeah so is Mike Smith on page? 718 00:34:31,850 --> 00:34:36,489 If yes, then call Mike, for instance. 719 00:34:36,489 --> 00:34:41,690 Else, if no-- and actually, let me try to simplify this because I'm 720 00:34:41,690 --> 00:34:43,280 being unnecessarily verbose. 721 00:34:43,280 --> 00:34:51,330 Let me change this to if Mike is on page, call Mike. 722 00:34:51,330 --> 00:34:56,139 Else, if Mike is to left-- so now we can kind of clean things up into cases, 723 00:34:56,139 --> 00:34:58,190 if you will, or forks in the road. 724 00:34:58,190 --> 00:35:01,016 If Mike is to the left, what do I want to do? 725 00:35:01,016 --> 00:35:03,189 AUDIENCE: [INAUDIBLE] 726 00:35:03,189 --> 00:35:04,230 DAVID MALAN: Go left, OK. 727 00:35:04,230 --> 00:35:08,440 So how about tear phone book in half. 728 00:35:08,440 --> 00:35:14,120 And now search left half for Mike. 729 00:35:14,120 --> 00:35:16,410 How do I search the left half for Mike? 730 00:35:16,410 --> 00:35:21,047 Well, what's kind of interesting is I already have an algorithm for search. 731 00:35:21,047 --> 00:35:22,130 And I could clean this up. 732 00:35:22,130 --> 00:35:24,088 There's different ways of expressing ourselves. 733 00:35:24,088 --> 00:35:27,820 But what I've just highlighted in blue is exactly the same algorithm 734 00:35:27,820 --> 00:35:28,720 that I need. 735 00:35:28,720 --> 00:35:32,580 So let's stipulate for today that when I say search left half for Mike, 736 00:35:32,580 --> 00:35:34,610 that is sufficient detail. 737 00:35:34,610 --> 00:35:36,090 And we can clarify this as follows. 738 00:35:36,090 --> 00:35:40,410 Back in the day, languages like BASIC, one of the earlier languages, 739 00:35:40,410 --> 00:35:43,020 used to number its lines. 740 00:35:43,020 --> 00:35:48,980 And so let me just go ahead and number these lines for discussion sake. 741 00:35:48,980 --> 00:35:51,050 Oops, that's a bug. 742 00:35:51,050 --> 00:35:53,760 743 00:35:53,760 --> 00:36:04,090 How about keep left half. 744 00:36:04,090 --> 00:36:08,610 Go to step two, to be specific. 745 00:36:08,610 --> 00:36:12,310 So that seems to induce the sort of cyclical behavior that we want. 746 00:36:12,310 --> 00:36:13,650 What should step nine be? 747 00:36:13,650 --> 00:36:17,775 748 00:36:17,775 --> 00:36:18,650 AUDIENCE: [INAUDIBLE] 749 00:36:18,650 --> 00:36:25,710 750 00:36:25,710 --> 00:36:27,850 DAVID MALAN: Keep right half. 751 00:36:27,850 --> 00:36:28,400 Good. 752 00:36:28,400 --> 00:36:32,550 11, go to step two. 753 00:36:32,550 --> 00:36:34,338 And is that it? 754 00:36:34,338 --> 00:36:44,422 755 00:36:44,422 --> 00:36:45,890 AUDIENCE: [INAUDIBLE] 756 00:36:45,890 --> 00:36:46,282 757 00:36:46,282 --> 00:36:48,240 DAVID MALAN: Yeah, we should probably add that. 758 00:36:48,240 --> 00:36:54,310 So end-- and actually, this is a good example of now I've created a problem. 759 00:36:54,310 --> 00:36:56,830 Thankfully, in modern languages you don't number your lines, 760 00:36:56,830 --> 00:36:58,413 so you don't have to worry about this. 761 00:36:58,413 --> 00:37:00,975 But for the curious or if you ever remember, 762 00:37:00,975 --> 00:37:03,600 the language BASIC years ago used to have this convention where 763 00:37:03,600 --> 00:37:05,500 your first line of code would be 10. 764 00:37:05,500 --> 00:37:07,180 Your second would be 20. 765 00:37:07,180 --> 00:37:08,870 Your next would be 30. 766 00:37:08,870 --> 00:37:09,970 Your next would be 40. 767 00:37:09,970 --> 00:37:11,650 Why might that have been? 768 00:37:11,650 --> 00:37:12,620 AUDIENCE: [INAUDIBLE] 769 00:37:12,620 --> 00:37:14,786 DAVID MALAN: Yes, so when you screw up, you actually 770 00:37:14,786 --> 00:37:18,030 have 9 mistakes you can make before you have to start re-numbering things. 771 00:37:18,030 --> 00:37:22,330 So that was one approach years ago Yeah, we should probably have an end. 772 00:37:22,330 --> 00:37:25,360 How about, we'll cheat, then end, just to cram it in there for now. 773 00:37:25,360 --> 00:37:27,790 But there's one case I'm not considering. 774 00:37:27,790 --> 00:37:30,850 There's a fork in the road I've not addressed. 775 00:37:30,850 --> 00:37:32,075 Yeah, Grace? 776 00:37:32,075 --> 00:37:32,950 AUDIENCE: [INAUDIBLE] 777 00:37:32,950 --> 00:37:38,090 DAVID MALAN: Yeah, so else if Mike is to right, else if Mike is on page, 778 00:37:38,090 --> 00:37:38,620 call Mike. 779 00:37:38,620 --> 00:37:41,650 So I kind of need-- and it's a little non-obvious 780 00:37:41,650 --> 00:37:44,470 based on how I've written it how I weave this logic in. 781 00:37:44,470 --> 00:37:47,470 So I'm going to cut a little bit of a corner and say else if out 782 00:37:47,470 --> 00:37:52,010 of pages, give up or something. 783 00:37:52,010 --> 00:37:55,320 And I say I'm cutting a page because I can't tear. 784 00:37:55,320 --> 00:37:56,677 I should have it up here, right? 785 00:37:56,677 --> 00:37:59,760 Because I can't tear the phone book in half if there's only one page left. 786 00:37:59,760 --> 00:38:01,551 But let's assume that the spirit of this is 787 00:38:01,551 --> 00:38:03,530 to capture all four cases which we now have. 788 00:38:03,530 --> 00:38:05,210 Otherwise there might have been undefined behavior. 789 00:38:05,210 --> 00:38:07,550 And indeed, if you've ever been running Mac OS or Windows 790 00:38:07,550 --> 00:38:10,216 software, where like you suddenly see the stupid beach ball just 791 00:38:10,216 --> 00:38:13,920 spinning and spinning, or the program crashes, or it hangs-- yesterday 792 00:38:13,920 --> 00:38:16,170 we proposed that if it's just hanging or slowing down, 793 00:38:16,170 --> 00:38:18,380 it might be because of virtual memory and swapping. 794 00:38:18,380 --> 00:38:22,315 But if it seems like it's not working correctly, not just slowly, 795 00:38:22,315 --> 00:38:24,840 it might be that someone didn't anticipate a situation. 796 00:38:24,840 --> 00:38:28,080 And programs will crash if they encounter, for instance, 797 00:38:28,080 --> 00:38:30,936 the equivalent of like an out-of-service branch, 798 00:38:30,936 --> 00:38:32,560 and there's no code there to handle it. 799 00:38:32,560 --> 00:38:34,751 It might just crash because you haven't anticipated 800 00:38:34,751 --> 00:38:36,250 a scenario like that last one there. 801 00:38:36,250 --> 00:38:38,694 What if Mike's not in the phone book? 802 00:38:38,694 --> 00:38:39,860 So this is just pseudo code. 803 00:38:39,860 --> 00:38:42,068 And we could have written this in any number of ways. 804 00:38:42,068 --> 00:38:44,190 But it rather captures the spirit mechanically 805 00:38:44,190 --> 00:38:45,760 of what we wanted to do yesterday. 806 00:38:45,760 --> 00:38:48,870 So now let's transition to a sillier but just 807 00:38:48,870 --> 00:38:53,356 as real environment for programming called Scratch, as follows. 808 00:38:53,356 --> 00:38:55,230 I'm going to go here, and we'll give everyone 809 00:38:55,230 --> 00:38:56,630 a moment to play around in a bit. 810 00:38:56,630 --> 00:38:58,630 But let me give a couple of examples first. 811 00:38:58,630 --> 00:39:00,690 This is Scratch's programming environment. 812 00:39:00,690 --> 00:39:03,730 And there's four main areas. 813 00:39:03,730 --> 00:39:06,330 There's the stage up here, this big white rectangle, 814 00:39:06,330 --> 00:39:08,490 where this cat named Scratch lives. 815 00:39:08,490 --> 00:39:11,139 There is down here the Sprites Palette, so you can actually 816 00:39:11,139 --> 00:39:12,180 have multiple characters. 817 00:39:12,180 --> 00:39:15,610 You can change Scratch to a dog or whatever else. 818 00:39:15,610 --> 00:39:19,120 There's this palette of menu options in the middle which are puzzle pieces. 819 00:39:19,120 --> 00:39:22,750 Each of those puzzle pieces represents a programming concept. 820 00:39:22,750 --> 00:39:27,480 And on the right is the scripts area, where you actually drag and drop 821 00:39:27,480 --> 00:39:28,590 these puzzle pieces. 822 00:39:28,590 --> 00:39:32,830 And notice at the top of the stage here, there's 823 00:39:32,830 --> 00:39:34,990 this green flag and the stop sign. 824 00:39:34,990 --> 00:39:37,174 Those mean go and stop respectively. 825 00:39:37,174 --> 00:39:39,090 And that's how we're going to run our program. 826 00:39:39,090 --> 00:39:42,048 And so what's nice about Scratch is that it very quickly lets us get up 827 00:39:42,048 --> 00:39:42,590 and running. 828 00:39:42,590 --> 00:39:47,120 In particular, there's these categories of puzzle pieces up here. 829 00:39:47,120 --> 00:39:50,400 I'm going click on the Control block-- no rather, the Events Block. 830 00:39:50,400 --> 00:39:53,190 And I'm going to drag and drop this one anywhere I want. 831 00:39:53,190 --> 00:39:55,190 But I'm going to keep it nice and clean and just 832 00:39:55,190 --> 00:39:56,830 start in the top left-hand corner. 833 00:39:56,830 --> 00:39:59,460 And notice the says one green click flag clicked. 834 00:39:59,460 --> 00:40:03,360 And notice it's got a little nub to connect to other puzzle pieces, 835 00:40:03,360 --> 00:40:08,080 and I'm going to go to Looks, and I'm going to choose this one, Say Hello 836 00:40:08,080 --> 00:40:09,150 For Two Seconds. 837 00:40:09,150 --> 00:40:11,160 But notice these white boxes are editable, 838 00:40:11,160 --> 00:40:16,490 so I'm just going to say Hello World, let's just say for one second. 839 00:40:16,490 --> 00:40:22,760 And now watch the cat on the left as I click the green flag. 840 00:40:22,760 --> 00:40:23,930 I've programmed. 841 00:40:23,930 --> 00:40:25,210 Now it's a simple program. 842 00:40:25,210 --> 00:40:27,680 But it's the Scratch equivalent to the Hello World program 843 00:40:27,680 --> 00:40:29,120 we just did a moment ago. 844 00:40:29,120 --> 00:40:30,690 So this isn't all that interesting. 845 00:40:30,690 --> 00:40:32,540 What might we like him to do instead? 846 00:40:32,540 --> 00:40:37,880 Well, let me, how about, do something again and again? 847 00:40:37,880 --> 00:40:40,140 So how about the repeat block. 848 00:40:40,140 --> 00:40:42,200 And notice that I can disconnect these things. 849 00:40:42,200 --> 00:40:44,730 And even though it doesn't look like anything fits in there, 850 00:40:44,730 --> 00:40:47,450 it sort of magnetically wants to go in there. 851 00:40:47,450 --> 00:40:52,520 So I can let it snap into place, and now I can let this snap into place. 852 00:40:52,520 --> 00:40:57,275 And now just because I'm going to have him say hello world 10 times, 853 00:40:57,275 --> 00:40:58,150 click the green flag. 854 00:40:58,150 --> 00:41:00,980 855 00:41:00,980 --> 00:41:05,540 Hmm, what's going on? 856 00:41:05,540 --> 00:41:07,790 this as expected? 857 00:41:07,790 --> 00:41:09,080 AUDIENCE: [INAUDIBLE] 858 00:41:09,080 --> 00:41:10,340 DAVID MALAN: He's not pausing. 859 00:41:10,340 --> 00:41:13,000 But that's what I kind of hoped for. 860 00:41:13,000 --> 00:41:14,960 But I haven't been precise enough, right? 861 00:41:14,960 --> 00:41:17,380 Because if he's saying hello world for one second, 862 00:41:17,380 --> 00:41:20,740 but then immediately it's doing it again and then eight more times, 863 00:41:20,740 --> 00:41:22,930 I never told him to pause. 864 00:41:22,930 --> 00:41:24,490 So how do I prevent that? 865 00:41:24,490 --> 00:41:28,470 Well, let me go to Looks, and Show And Hide isn't what I want. 866 00:41:28,470 --> 00:41:30,870 That it's going to make the cat disappear. 867 00:41:30,870 --> 00:41:33,141 So how could I change this logically? 868 00:41:33,141 --> 00:41:38,750 869 00:41:38,750 --> 00:41:42,779 And there's also, if I go to Control-- is it Control? 870 00:41:42,779 --> 00:41:43,612 [INTERPOSING VOICES] 871 00:41:43,612 --> 00:41:47,410 872 00:41:47,410 --> 00:41:49,494 DAVID MALAN: Yeah, so it looks like it's too late. 873 00:41:49,494 --> 00:41:50,451 I can't fit that there. 874 00:41:50,451 --> 00:41:52,560 But again, magnetically, it will want to go there. 875 00:41:52,560 --> 00:41:54,390 So it will just grow to fit. 876 00:41:54,390 --> 00:41:56,910 So now I'm explicitly saying, wait one second. 877 00:41:56,910 --> 00:41:59,990 And let's see if this happens. 878 00:41:59,990 --> 00:42:02,880 Ah, so now it's giving him a chance to breathe, so to speak, 879 00:42:02,880 --> 00:42:04,890 whereby it's saying it for one second. 880 00:42:04,890 --> 00:42:08,090 But rather than immediately like close and open his mouth, so to speak, 881 00:42:08,090 --> 00:42:12,010 it's letting him close it for wait a second, then reopen it to say, 882 00:42:12,010 --> 00:42:12,906 hello world. 883 00:42:12,906 --> 00:42:14,530 All right, so that's all fine and good. 884 00:42:14,530 --> 00:42:16,321 But it's not nearly as cute as it could be. 885 00:42:16,321 --> 00:42:17,770 I'm going to go under Sounds here. 886 00:42:17,770 --> 00:42:20,250 And it just so happens we have access to a sound block. 887 00:42:20,250 --> 00:42:21,880 [MEOW] 888 00:42:21,880 --> 00:42:27,130 And if I instead rip this out, and let me find the sound palette. 889 00:42:27,130 --> 00:42:31,750 And let me play the sound meow and hit Play. 890 00:42:31,750 --> 00:42:34,750 [MEOW] 891 00:42:34,750 --> 00:42:36,250 892 00:42:36,250 --> 00:42:37,988 Uh-oh, what happened there? 893 00:42:37,988 --> 00:42:41,200 894 00:42:41,200 --> 00:42:42,560 Let me try this. 895 00:42:42,560 --> 00:42:43,620 Now I'm puzzled. 896 00:42:43,620 --> 00:42:46,474 Let me play sound meow until done. 897 00:42:46,474 --> 00:42:49,670 [MEOWING] 898 00:42:49,670 --> 00:42:52,065 Not very natural but better 899 00:42:52,065 --> 00:42:52,895 [MEOWING] 900 00:42:52,895 --> 00:42:54,068 Let me steal this block. 901 00:42:54,068 --> 00:42:57,870 902 00:42:57,870 --> 00:42:58,370 [MEOW] 903 00:42:58,370 --> 00:42:59,326 [PAUSE] 904 00:42:59,326 --> 00:43:01,238 [MEOW] 905 00:43:01,238 --> 00:43:03,780 Slightly more realistic. 906 00:43:03,780 --> 00:43:05,900 Why did it not work the first time? 907 00:43:05,900 --> 00:43:11,336 Remember, let me undo this, drag this in and hit Play. 908 00:43:11,336 --> 00:43:13,360 [MEOW] 909 00:43:13,360 --> 00:43:14,200 I'm confused. 910 00:43:14,200 --> 00:43:15,687 Why is this not working? 911 00:43:15,687 --> 00:43:18,490 912 00:43:18,490 --> 00:43:23,006 What could possibly explain this issue? 913 00:43:23,006 --> 00:43:23,880 AUDIENCE: [INAUDIBLE] 914 00:43:23,880 --> 00:43:25,910 DAVID MALAN: Yeah, maybe the sound byte's-- it's only one second, 915 00:43:25,910 --> 00:43:26,784 so it's pretty brief. 916 00:43:26,784 --> 00:43:29,230 917 00:43:29,230 --> 00:43:34,390 But conjecture why I'm not hearing it 10 times nonetheless? 918 00:43:34,390 --> 00:43:34,890 What's that? 919 00:43:34,890 --> 00:43:37,626 AUDIENCE: [INAUDIBLE] 920 00:43:37,626 --> 00:43:39,910 AUDIENCE: [INAUDIBLE] 921 00:43:39,910 --> 00:43:41,758 DAVID MALAN: Yeah. 922 00:43:41,758 --> 00:43:42,819 AUDIENCE: [INAUDIBLE] 923 00:43:42,819 --> 00:43:45,110 DAVID MALAN: Yeah, at the risk of like oversimplifying, 924 00:43:45,110 --> 00:43:48,410 my Mac operates at 3.1 gigahertz, which means 925 00:43:48,410 --> 00:43:51,850 it does 3.1 billion things per second. 926 00:43:51,850 --> 00:43:55,370 And what I'm really telling it to do is only 10 things. 927 00:43:55,370 --> 00:43:58,519 But I'm not letting it wait until it finishes the song. 928 00:43:58,519 --> 00:44:01,560 So it's like this loop-- and I certainly can't move my finger this fast-- 929 00:44:01,560 --> 00:44:03,190 is doing this 10 times. 930 00:44:03,190 --> 00:44:06,800 And by the time it's done with all 10, the sound is still playing anyway, 931 00:44:06,800 --> 00:44:09,130 so it has the effect of really just playing it 932 00:44:09,130 --> 00:44:12,080 once because it's happening that fast. 933 00:44:12,080 --> 00:44:19,160 The play sound until done is designed to block execution in that loop 934 00:44:19,160 --> 00:44:21,280 until the sound is done playing. 935 00:44:21,280 --> 00:44:24,040 And so even though it's going around pretty fast, 936 00:44:24,040 --> 00:44:26,500 and that's why it sounds a little unnatural, 937 00:44:26,500 --> 00:44:29,540 at least it's waiting until the sound is done to continue 938 00:44:29,540 --> 00:44:31,570 to the next iteration of the loop. 939 00:44:31,570 --> 00:44:35,030 But waiting one second forces it to linger even longer. 940 00:44:35,030 --> 00:44:38,240 So it starts to sound even more natural still. 941 00:44:38,240 --> 00:44:39,624 So this is just sound. 942 00:44:39,624 --> 00:44:41,540 What about movement, and what about animation? 943 00:44:41,540 --> 00:44:44,220 How might you make games or in general interactivity? 944 00:44:44,220 --> 00:44:46,470 Well, let's again grab a control block. 945 00:44:46,470 --> 00:44:49,650 And let's just say forever this time, which is a different type of loop, 946 00:44:49,650 --> 00:44:51,210 if you will, or cycle. 947 00:44:51,210 --> 00:44:53,850 And let's go to Motion. 948 00:44:53,850 --> 00:44:55,467 Move 10 steps. 949 00:44:55,467 --> 00:44:56,800 And let's see what happens here. 950 00:44:56,800 --> 00:44:59,840 951 00:44:59,840 --> 00:45:02,297 Now I can-- thankfully, this is designed for children 952 00:45:02,297 --> 00:45:04,130 so he can never quite leave the stage fully. 953 00:45:04,130 --> 00:45:05,620 So we can drag him back. 954 00:45:05,620 --> 00:45:08,580 But the program's still running because it's in an infinite loop. 955 00:45:08,580 --> 00:45:11,980 And notice, it's colored in yellow, which means that the program is indeed 956 00:45:11,980 --> 00:45:12,680 still running. 957 00:45:12,680 --> 00:45:15,440 958 00:45:15,440 --> 00:45:19,890 What's going to happen if I change the 10 to 50, would you think? 959 00:45:19,890 --> 00:45:24,220 960 00:45:24,220 --> 00:45:27,130 What would the visual effect be? 961 00:45:27,130 --> 00:45:28,280 Yeah, faster, right? 962 00:45:28,280 --> 00:45:30,860 Because this is cycling again and again. 963 00:45:30,860 --> 00:45:33,590 And every time the loop goes through, it moves 10 steps. 964 00:45:33,590 --> 00:45:35,506 I don't know what a step is, but it's probably 965 00:45:35,506 --> 00:45:37,100 a pixel or a dot on the screen. 966 00:45:37,100 --> 00:45:39,540 So let me change the 10 to 50. 967 00:45:39,540 --> 00:45:45,260 And if now in every iteration he's moving 50 steps, woo, it's pretty fast. 968 00:45:45,260 --> 00:45:49,330 Let's do 100. 969 00:45:49,330 --> 00:45:50,910 And now it's really fast. 970 00:45:50,910 --> 00:46:01,000 But let's add some logic now, whereby, let's say, sensing-- actually, 971 00:46:01,000 --> 00:46:02,270 let me grab control. 972 00:46:02,270 --> 00:46:07,144 So let me add an if, which is some conditional logic, and then sensing, 973 00:46:07,144 --> 00:46:08,310 because I know this is here. 974 00:46:08,310 --> 00:46:16,350 If touching edge, let me change to a different direction. 975 00:46:16,350 --> 00:46:19,730 How about-- OK, that was an accident but cute. 976 00:46:19,730 --> 00:46:21,110 Let's stop that. 977 00:46:21,110 --> 00:46:24,030 Let's have him change 180 degrees. 978 00:46:24,030 --> 00:46:26,540 So let me-- how do I' reset the cat? 979 00:46:26,540 --> 00:46:30,089 He's in a funky place now. 980 00:46:30,089 --> 00:46:31,755 Well we'll just let him go down instead. 981 00:46:31,755 --> 00:46:34,400 982 00:46:34,400 --> 00:46:37,800 So now he's bouncing off the screen. 983 00:46:37,800 --> 00:46:38,850 But this is as expected. 984 00:46:38,850 --> 00:46:41,980 I didn't quite intend for it to be diagonal, but so be it. 985 00:46:41,980 --> 00:46:44,680 And now we can add another little feature here. 986 00:46:44,680 --> 00:46:50,440 Let me go to Sound, Play Sound Meow. 987 00:46:50,440 --> 00:46:53,790 988 00:46:53,790 --> 00:46:56,650 [MEOWING] 989 00:46:56,650 --> 00:46:58,650 And now we can be a little more ridiculous here. 990 00:46:58,650 --> 00:47:02,478 This is now where we're venturing into non-academic territory. 991 00:47:02,478 --> 00:47:03,644 Let me click the microphone. 992 00:47:03,644 --> 00:47:06,310 993 00:47:06,310 --> 00:47:08,170 I'm going to allow my microphone to work. 994 00:47:08,170 --> 00:47:10,850 995 00:47:10,850 --> 00:47:13,460 Delete that. 996 00:47:13,460 --> 00:47:15,090 Ouch! 997 00:47:15,090 --> 00:47:17,020 All right, so that's a waveform of my voice. 998 00:47:17,020 --> 00:47:20,670 I'm going to delete the part where it was just silent for a moment. 999 00:47:20,670 --> 00:47:22,730 Now let's go over here. 1000 00:47:22,730 --> 00:47:26,023 Recording One-- I didn't give it a clever name. 1001 00:47:26,023 --> 00:47:26,522 Ouch! 1002 00:47:26,522 --> 00:47:27,458 Ouch! 1003 00:47:27,458 --> 00:47:28,370 Ouch! 1004 00:47:28,370 --> 00:47:28,870 Ouch! 1005 00:47:28,870 --> 00:47:29,332 Ouch! 1006 00:47:29,332 --> 00:47:29,831 Ouch! 1007 00:47:29,831 --> 00:47:30,940 Ouch! 1008 00:47:30,940 --> 00:47:36,160 So you laugh, but this is what programming is fun for. 1009 00:47:36,160 --> 00:47:38,129 It gets very annoying very quickly. 1010 00:47:38,129 --> 00:47:39,670 So let's ramp things up a little bit. 1011 00:47:39,670 --> 00:47:42,870 I have some pre-fabbed examples here to demonstrate a few points. 1012 00:47:42,870 --> 00:47:46,250 For instance, this one here, still a cat, still involving sound. 1013 00:47:46,250 --> 00:47:47,812 But this one works as follows. 1014 00:47:47,812 --> 00:47:49,580 [ROARING] 1015 00:47:49,580 --> 00:47:51,820 [MEOW] 1016 00:47:51,820 --> 00:47:53,800 See Inside will show me the program. 1017 00:47:53,800 --> 00:47:56,740 So this one, [MEOW] behaves like this. 1018 00:47:56,740 --> 00:47:58,390 We're kind of spoiled. 1019 00:47:58,390 --> 00:48:02,070 But does someone want to propose how this program works? 1020 00:48:02,070 --> 00:48:05,098 Read code for first time perhaps. 1021 00:48:05,098 --> 00:48:07,912 [MEOWING] 1022 00:48:07,912 --> 00:48:10,260 1023 00:48:10,260 --> 00:48:10,991 Yeah? 1024 00:48:10,991 --> 00:48:13,450 AUDIENCE: [INAUDIBLE] 1025 00:48:13,450 --> 00:48:16,688 DAVID MALAN: Yeah, so if you pet this cat with the cursor-- 1026 00:48:16,688 --> 00:48:18,026 [ROAR] 1027 00:48:18,026 --> 00:48:18,920 [MEOW] 1028 00:48:18,920 --> 00:48:22,565 So it's a nice way of combining now a forever loop, so a looping construct, 1029 00:48:22,565 --> 00:48:25,310 but not just an if, but an if-else. 1030 00:48:25,310 --> 00:48:27,750 So there's two forks in this road not just one. 1031 00:48:27,750 --> 00:48:35,790 Let's try another example here, where let's do 1032 00:48:35,790 --> 00:48:40,040 this one to show the precursor of this. 1033 00:48:40,040 --> 00:48:46,420 This one, by contrast, does nothing at first until you do what? 1034 00:48:46,420 --> 00:48:47,528 Till-- 1035 00:48:47,528 --> 00:48:49,320 [MEOWING] 1036 00:48:49,320 --> 00:48:52,480 This is kind of the opposite, where you do want to pet the at. 1037 00:48:52,480 --> 00:48:56,040 Let's take things up a notch with, say, counting sheep, which 1038 00:48:56,040 --> 00:48:57,636 gives us a new capability altogether. 1039 00:48:57,636 --> 00:49:01,210 1040 00:49:01,210 --> 00:49:03,940 Now, even though we haven't seen these blocks before, what does 1041 00:49:03,940 --> 00:49:05,340 this program apparently do? 1042 00:49:05,340 --> 00:49:09,196 1043 00:49:09,196 --> 00:49:11,079 AUDIENCE: [INAUDIBLE] 1044 00:49:11,079 --> 00:49:13,120 DAVID MALAN: Yes this is kind of a play on words. 1045 00:49:13,120 --> 00:49:16,036 So instead of you counting sheep, the sheep does the counting. 1046 00:49:16,036 --> 00:49:17,910 But it introduces a new type of puzzle piece. 1047 00:49:17,910 --> 00:49:19,868 This orange thing is what we'd call a variable. 1048 00:49:19,868 --> 00:49:22,790 So like in algebra you have x and y and z, and they store values, 1049 00:49:22,790 --> 00:49:25,710 like numbers, in this case, too, I'm declaring a variable. 1050 00:49:25,710 --> 00:49:28,000 But it's more interestingly named than x, y, z. 1051 00:49:28,000 --> 00:49:31,920 And indeed in programming it's common to name your variables in a more 1052 00:49:31,920 --> 00:49:34,420 descriptive way, like counter, setting it equal to zero 1053 00:49:34,420 --> 00:49:40,960 and then increasing it by one, so that all this sheep does to infinity 1054 00:49:40,960 --> 00:49:43,840 is counts really, really high. 1055 00:49:43,840 --> 00:49:48,350 Though there's actually-- you can see a bug pretty fast. 1056 00:49:48,350 --> 00:49:52,880 Let me remove the wait. 1057 00:49:52,880 --> 00:49:54,840 So now he's counting faster. 1058 00:49:54,840 --> 00:49:57,140 Let me increase the counter even faster. 1059 00:49:57,140 --> 00:50:05,202 1060 00:50:05,202 --> 00:50:06,799 Let's see if I can really break this. 1061 00:50:06,799 --> 00:50:08,423 Let's see how high the sheep can count. 1062 00:50:08,423 --> 00:50:12,180 1063 00:50:12,180 --> 00:50:13,437 This is a really big number. 1064 00:50:13,437 --> 00:50:16,420 1065 00:50:16,420 --> 00:50:19,027 Come on, break. 1066 00:50:19,027 --> 00:50:20,235 The sheep is not cooperating. 1067 00:50:20,235 --> 00:50:24,860 1068 00:50:24,860 --> 00:50:27,160 My number's bigger than that, I think. 1069 00:50:27,160 --> 00:50:29,280 I can't quite tell what's going on here. 1070 00:50:29,280 --> 00:50:32,349 I'm trying to simulate a fundamental limitation of computing, 1071 00:50:32,349 --> 00:50:33,015 and I'm failing. 1072 00:50:33,015 --> 00:50:36,720 1073 00:50:36,720 --> 00:50:39,820 Computers can count really high is the take away of this example. 1074 00:50:39,820 --> 00:50:41,897 At some point, per our discussion yesterday 1075 00:50:41,897 --> 00:50:43,980 of how many bits are typically used to store data, 1076 00:50:43,980 --> 00:50:47,230 it turns out that computers-- and I'm not quite sure what's happening here. 1077 00:50:47,230 --> 00:50:48,980 I think Scratch is simplifying this for us 1078 00:50:48,980 --> 00:50:50,860 and only showing as part of the number. 1079 00:50:50,860 --> 00:50:54,180 Computers typically only use 32 bits, maybe 64 bits, 1080 00:50:54,180 --> 00:50:57,180 to represent numbers, which is to say that they can only count so high. 1081 00:50:57,180 --> 00:51:01,050 And what I was hoping would happen here is that the sheep would actually 1082 00:51:01,050 --> 00:51:05,250 start misbehaving and start counting negative numbers or some other funky 1083 00:51:05,250 --> 00:51:06,040 behavior. 1084 00:51:06,040 --> 00:51:07,290 It seems not to be doing that. 1085 00:51:07,290 --> 00:51:08,420 So it's a little resilient to this. 1086 00:51:08,420 --> 00:51:10,669 But at the end of the day, this is a fundamental limit 1087 00:51:10,669 --> 00:51:11,950 of most computer programs. 1088 00:51:11,950 --> 00:51:15,522 If you only have 32 bits or 64 bits, which is of course finite, 1089 00:51:15,522 --> 00:51:17,980 you only have a finite number of numbers you can represent. 1090 00:51:17,980 --> 00:51:20,540 That might be a really big number, but it's still finite. 1091 00:51:20,540 --> 00:51:22,730 And so there have been some very real-world examples 1092 00:51:22,730 --> 00:51:26,060 of this being a problem, whereby counters overflow, so to speak. 1093 00:51:26,060 --> 00:51:29,900 You get to 4 billion, and then suddenly the counter goes back to zero. 1094 00:51:29,900 --> 00:51:32,550 And frankly, even if you're not quite the technophile, 1095 00:51:32,550 --> 00:51:37,090 you might recall that 16 years ago we humans made exactly this mistake 1096 00:51:37,090 --> 00:51:42,855 on an even larger scale with a much simpler problem, which was what? 1097 00:51:42,855 --> 00:51:43,730 AUDIENCE: [INAUDIBLE] 1098 00:51:43,730 --> 00:51:44,830 DAVID MALAN: Yeah, y2k. 1099 00:51:44,830 --> 00:51:48,320 Thankfully, thanks to languages like COBOL and FORTRAN, 1100 00:51:48,320 --> 00:51:51,507 enough the world was fixed before the apocalypse happened in the year 2000. 1101 00:51:51,507 --> 00:51:53,840 But what was the essence of the problem back then, which 1102 00:51:53,840 --> 00:51:57,385 was a programming problem? 1103 00:51:57,385 --> 00:51:58,260 AUDIENCE: [INAUDIBLE] 1104 00:51:58,260 --> 00:52:04,390 1105 00:52:04,390 --> 00:52:07,297 DAVID MALAN: Exactly, and why would that have been? 1106 00:52:07,297 --> 00:52:08,172 AUDIENCE: [INAUDIBLE] 1107 00:52:08,172 --> 00:52:11,540 1108 00:52:11,540 --> 00:52:13,830 DAVID MALAN: That's true, but why? 1109 00:52:13,830 --> 00:52:18,760 That is true, but that was a side effect of a design decision in software. 1110 00:52:18,760 --> 00:52:19,660 Grace? 1111 00:52:19,660 --> 00:52:20,635 AUDIENCE: [INAUDIBLE] 1112 00:52:20,635 --> 00:52:21,760 DAVID MALAN: Yeah, exactly. 1113 00:52:21,760 --> 00:52:24,030 These two digits for the year because most 1114 00:52:24,030 --> 00:52:27,047 computer software was invented in the '60s or later. 1115 00:52:27,047 --> 00:52:29,380 And surely no one thought, especially in the government, 1116 00:52:29,380 --> 00:52:32,240 that we'd still be running the same software 30-plus years later. 1117 00:52:32,240 --> 00:52:34,430 But of course, as 2000 approached, we were still 1118 00:52:34,430 --> 00:52:36,280 running some especially old systems. 1119 00:52:36,280 --> 00:52:38,570 We were getting closer and closer to the year 1120 00:52:38,570 --> 00:52:44,950 not rolling from 1999 to 2000, but from 1999 to 1000 1121 00:52:44,950 --> 00:52:47,910 because you are only looking at those last two digits. 1122 00:52:47,910 --> 00:52:51,020 So a lot of software had to be written in languages 1123 00:52:51,020 --> 00:52:54,810 beyond even these because people had to go back and fix this. 1124 00:52:54,810 --> 00:52:59,350 Now, it was plenty efficient, and you saved memory by only using two digits. 1125 00:52:59,350 --> 00:53:02,390 But nowadays this would certainly be an asinine decision in software 1126 00:53:02,390 --> 00:53:05,290 because you all too easily start to bump up against these barriers. 1127 00:53:05,290 --> 00:53:08,110 We're already running into an issue whereby historically 1128 00:53:08,110 --> 00:53:15,180 clocks in computers are stored as the number of seconds from January 1, 1970, 1129 00:53:15,180 --> 00:53:19,060 just because-- an arbitrary sort of moment in time, the epoch, so to speak, 1130 00:53:19,060 --> 00:53:20,460 in computing. 1131 00:53:20,460 --> 00:53:24,320 This is not great because you can only count so high 1132 00:53:24,320 --> 00:53:27,250 with numbers that are of finite bits. 1133 00:53:27,250 --> 00:53:32,231 And so even clocks are at risk of rolling over for similar reasons 1134 00:53:32,231 --> 00:53:32,730 as well. 1135 00:53:32,730 --> 00:53:34,470 It's sort of y2k in a different way. 1136 00:53:34,470 --> 00:53:35,720 Was there a hand a moment ago? 1137 00:53:35,720 --> 00:53:36,799 Avi? 1138 00:53:36,799 --> 00:53:37,674 AUDIENCE: [INAUDIBLE] 1139 00:53:37,674 --> 00:53:43,610 1140 00:53:43,610 --> 00:53:46,140 DAVID MALAN: Either they don't, and it's just not supported, 1141 00:53:46,140 --> 00:53:49,410 or you have to use libraries that essentially 1142 00:53:49,410 --> 00:53:53,030 use multiple numbers to represent one number. 1143 00:53:53,030 --> 00:53:56,220 So maybe the first variable would represent the first digits in a number, 1144 00:53:56,220 --> 00:53:58,640 and the second number would represent the other digits in the number. 1145 00:53:58,640 --> 00:54:00,690 And you have to somehow do the appropriate math 1146 00:54:00,690 --> 00:54:02,231 to combine those values somehow. 1147 00:54:02,231 --> 00:54:02,730 But-- 1148 00:54:02,730 --> 00:54:03,605 AUDIENCE: [INAUDIBLE] 1149 00:54:03,605 --> 00:54:05,219 1150 00:54:05,219 --> 00:54:07,760 DAVID MALAN: They would still use special software typically. 1151 00:54:07,760 --> 00:54:10,360 So most modern computers nowadays are 64 bits, which 1152 00:54:10,360 --> 00:54:12,230 means you can count up much higher. 1153 00:54:12,230 --> 00:54:16,910 Specifically, you can count up to two to the 64, which is a number that big. 1154 00:54:16,910 --> 00:54:20,390 If you need bigger numbers still, which program certainly 1155 00:54:20,390 --> 00:54:22,870 support, for instance, here is this calculator I'm using. 1156 00:54:22,870 --> 00:54:24,870 It clearly can count even higher than that. 1157 00:54:24,870 --> 00:54:27,760 That's because they're using multi-byte precision 1158 00:54:27,760 --> 00:54:31,650 arithmetic, which means you use multiple bytes not just four or eight. 1159 00:54:31,650 --> 00:54:33,610 You use even more than that. 1160 00:54:33,610 --> 00:54:34,990 But it's not built into the CPU. 1161 00:54:34,990 --> 00:54:37,390 It has to be done in software. 1162 00:54:37,390 --> 00:54:39,480 So let's take a look at another couple of examples 1163 00:54:39,480 --> 00:54:42,080 of what you can do with this. 1164 00:54:42,080 --> 00:54:45,540 How about this guy, which is interesting because it uses yet another feature 1165 00:54:45,540 --> 00:54:47,830 of a typical programming language. 1166 00:54:47,830 --> 00:54:49,250 [BARKING] 1167 00:54:49,250 --> 00:54:50,860 Here's what he does. 1168 00:54:50,860 --> 00:54:54,762 [BARKING] 1169 00:54:54,762 --> 00:54:56,360 And that's enough to get annoying. 1170 00:54:56,360 --> 00:55:01,540 If I hit the space bar, the program is still running, but he is muted. 1171 00:55:01,540 --> 00:55:02,380 Why? 1172 00:55:02,380 --> 00:55:04,630 Well, notice a couple of features of this program. 1173 00:55:04,630 --> 00:55:07,830 One, this program actually has two scripts, so to speak. 1174 00:55:07,830 --> 00:55:09,880 It is multi-threaded, if you will. 1175 00:55:09,880 --> 00:55:15,187 A program is multithreaded if it can do multiple things at a time in parallel. 1176 00:55:15,187 --> 00:55:17,520 The fact that these two scripts are physically separated 1177 00:55:17,520 --> 00:55:19,350 captures that idea. 1178 00:55:19,350 --> 00:55:22,840 And there's an interrelationship between the two of them. 1179 00:55:22,840 --> 00:55:27,000 In particular, what does the script on the right do in layman's terms? 1180 00:55:27,000 --> 00:55:36,216 1181 00:55:36,216 --> 00:55:38,090 What does the script on the right seem to do? 1182 00:55:38,090 --> 00:55:43,670 1183 00:55:43,670 --> 00:55:44,170 Anyone? 1184 00:55:44,170 --> 00:55:47,536 1185 00:55:47,536 --> 00:55:48,460 AUDIENCE: [INAUDIBLE] 1186 00:55:48,460 --> 00:55:49,751 DAVID MALAN: Sets the baseline? 1187 00:55:49,751 --> 00:55:51,630 OK, but what does that mean? 1188 00:55:51,630 --> 00:55:52,970 Be more specific. 1189 00:55:52,970 --> 00:55:54,158 The one on the right though. 1190 00:55:54,158 --> 00:55:55,033 AUDIENCE: [INAUDIBLE] 1191 00:55:55,033 --> 00:55:59,059 1192 00:55:59,059 --> 00:56:00,308 DAVID MALAN: Your right, yeah. 1193 00:56:00,308 --> 00:56:02,555 1194 00:56:02,555 --> 00:56:03,430 AUDIENCE: [INAUDIBLE] 1195 00:56:03,430 --> 00:56:07,130 1196 00:56:07,130 --> 00:56:08,936 DAVID MALAN: Under what circumstances? 1197 00:56:08,936 --> 00:56:10,095 AUDIENCE: [INAUDIBLE] 1198 00:56:10,095 --> 00:56:11,970 DAVID MALAN: At the start, and in particular, 1199 00:56:11,970 --> 00:56:14,040 there's a fork in the road there, so to speak. 1200 00:56:14,040 --> 00:56:16,090 It's a one-way fork, so there's a decision point. 1201 00:56:16,090 --> 00:56:20,716 It only says, hi, hi, hi, if what is the case? 1202 00:56:20,716 --> 00:56:22,000 AUDIENCE: [INAUDIBLE] 1203 00:56:22,000 --> 00:56:23,300 DAVID MALAN: If muted is zero. 1204 00:56:23,300 --> 00:56:29,600 So I'm taking some liberties here using zero to represent false or no or off. 1205 00:56:29,600 --> 00:56:35,580 And one I'm arbitrarily going to equate with true or on or such. 1206 00:56:35,580 --> 00:56:40,230 And so when I say, if muted equals zero, that means if muted is false. 1207 00:56:40,230 --> 00:56:43,496 So what if it's not muted, is the corresponding logic, 1208 00:56:43,496 --> 00:56:46,370 then play the sound and think hi, hi, hi, and then wait a few seconds 1209 00:56:46,370 --> 00:56:48,730 and then do it again and again and again. 1210 00:56:48,730 --> 00:56:51,050 On the left-hand side, how would you describe 1211 00:56:51,050 --> 00:56:53,342 the functionality of that script? 1212 00:56:53,342 --> 00:56:55,025 AUDIENCE: [INAUDIBLE] 1213 00:56:55,025 --> 00:56:55,900 DAVID MALAN: Exactly. 1214 00:56:55,900 --> 00:56:58,940 If I press the space bar, for which it's listening constantly 1215 00:56:58,940 --> 00:57:03,160 in that forever loop, change the value of muted from zero to one, 1216 00:57:03,160 --> 00:57:04,730 else change it from one to zero. 1217 00:57:04,730 --> 00:57:07,680 So it's a way of flipping the state of that variable. 1218 00:57:07,680 --> 00:57:10,422 So just by convention, there's nothing for enforcing this. 1219 00:57:10,422 --> 00:57:13,130 I could use the numbers two and three or nine and 10 or whatever. 1220 00:57:13,130 --> 00:57:15,830 I'm using zero and one by convention. 1221 00:57:15,830 --> 00:57:20,690 It seems to be changing or toggling, if you will, the zero to a one or a one 1222 00:57:20,690 --> 00:57:23,579 to a zero based on whether the space bar is pressed, 1223 00:57:23,579 --> 00:57:24,870 which means if I hit it again-- 1224 00:57:24,870 --> 00:57:26,160 [BARKING] 1225 00:57:26,160 --> 00:57:28,330 -the sea lion keeps talking. 1226 00:57:28,330 --> 00:57:30,490 Now he's off. 1227 00:57:30,490 --> 00:57:31,226 Now he's on 1228 00:57:31,226 --> 00:57:31,726 [BARKING] 1229 00:57:31,726 --> 00:57:33,934 And you can liken this to most any piece of hardware. 1230 00:57:33,934 --> 00:57:37,200 Like on your Android phone or iPhone, f you hit mute or pause, 1231 00:57:37,200 --> 00:57:40,359 really there's probably just some kind of loop waiting and waiting. 1232 00:57:40,359 --> 00:57:41,400 Hey, is he hitting pause? 1233 00:57:41,400 --> 00:57:42,090 Is he hitting pause? 1234 00:57:42,090 --> 00:57:42,923 Is he hitting pause? 1235 00:57:42,923 --> 00:57:44,970 If so, pause the music. 1236 00:57:44,970 --> 00:57:48,650 Or by contrast, and we can see this with one final example, 1237 00:57:48,650 --> 00:57:52,680 software is often not sitting in a loop like this, which is generally 1238 00:57:52,680 --> 00:57:54,640 not best practice because in many languages 1239 00:57:54,640 --> 00:57:57,910 it will actually slow the computer down if you're just constantly doing this. 1240 00:57:57,910 --> 00:58:03,110 Instead it can be event based, whereby you tell the screening in advance, 1241 00:58:03,110 --> 00:58:06,241 hey when the user hits the space bar, let me know. 1242 00:58:06,241 --> 00:58:09,240 And you leave it to the operating system or some other piece of software 1243 00:58:09,240 --> 00:58:11,610 to let you know that, at which point you do something. 1244 00:58:11,610 --> 00:58:14,600 And in particular, we can see it with this example here. 1245 00:58:14,600 --> 00:58:17,825 Here are two puppets that work as follows. 1246 00:58:17,825 --> 00:58:20,460 1247 00:58:20,460 --> 00:58:23,520 This guy-- so just to be clear, we now have two sprites. 1248 00:58:23,520 --> 00:58:26,520 So the blue guy is selected in the bottom left-hand corner here. 1249 00:58:26,520 --> 00:58:29,600 The blue guy's purpose in life is to say Polo 1250 00:58:29,600 --> 00:58:32,700 when he receives something called an event, per my mention 1251 00:58:32,700 --> 00:58:34,810 of event-based programming. 1252 00:58:34,810 --> 00:58:43,070 The orange guy apparently does what when I hit the space bar? 1253 00:58:43,070 --> 00:58:44,510 AUDIENCE: [INAUDIBLE] 1254 00:58:44,510 --> 00:58:45,730 DAVID MALAN: He says Marco. 1255 00:58:45,730 --> 00:58:48,600 But he also broadcasts an event. 1256 00:58:48,600 --> 00:58:54,290 So the blue guy has registered himself as a listener for this event. 1257 00:58:54,290 --> 00:58:57,260 The orange guy is responsible for broadcasting event. 1258 00:58:57,260 --> 00:59:00,050 And it's not quite a verbal broadcast. 1259 00:59:00,050 --> 00:59:01,370 It's sort of a software thing. 1260 00:59:01,370 --> 00:59:04,730 You're just visually coincidentally seeing him also say Marco, 1261 00:59:04,730 --> 00:59:07,610 but that's not what the blue guy is listening for. 1262 00:59:07,610 --> 00:59:10,480 The blue guy's listening for this thing called an event. 1263 00:59:10,480 --> 00:59:13,110 And the result here is that nothing happens at first, 1264 00:59:13,110 --> 00:59:14,570 but the program is running. 1265 00:59:14,570 --> 00:59:17,880 But how do I make this program do something interesting? 1266 00:59:17,880 --> 00:59:18,860 Hit the space bar. 1267 00:59:18,860 --> 00:59:20,790 The orange guy hears the space bar. 1268 00:59:20,790 --> 00:59:21,620 He says, Marco. 1269 00:59:21,620 --> 00:59:26,560 The blue guy receives that event, and he says Polo in succession. 1270 00:59:26,560 --> 00:59:30,030 And so this is one way of having two sprites, in this case, 1271 00:59:30,030 --> 00:59:32,980 or really two threads, more generally speaking, 1272 00:59:32,980 --> 00:59:37,140 intercommunicate by way of what's called event-based programming. 1273 00:59:37,140 --> 00:59:40,020 And it's a different paradigm from just sitting there in a loop 1274 00:59:40,020 --> 00:59:43,000 forever, listening for something to happen. 1275 00:59:43,000 --> 00:59:45,240 Now, we can be much more sophisticated than this. 1276 00:59:45,240 --> 00:59:49,350 We can have multiple threads interacting in this way. 1277 00:59:49,350 --> 00:59:53,330 This is an example of two sprites, both with forever blocks. 1278 00:59:53,330 --> 00:59:56,630 But the cat clearly has an advantage here because it turns out, 1279 00:59:56,630 --> 01:00:00,690 Scratch has a block that says point in the direction of another sprite. 1280 01:00:00,690 --> 01:00:03,501 And so eventually, he will ever so closely-- 1281 01:00:03,501 --> 01:00:04,000 [ROAR] 1282 01:00:04,000 --> 01:00:06,530 --catch up to the bird eventually. 1283 01:00:06,530 --> 01:00:09,620 And you can see how that's implemented in the source code there. 1284 01:00:09,620 --> 01:00:11,210 But then you can go even further. 1285 01:00:11,210 --> 01:00:14,270 And in fact, one of our students implemented this one. 1286 01:00:14,270 --> 01:00:17,290 Lest you be underwhelmed by these examples, one of our students 1287 01:00:17,290 --> 01:00:21,100 reimplemented this game, which you might remember from yesteryear. 1288 01:00:21,100 --> 01:00:24,995 And if I full screen this and click Go, 1289 01:00:24,995 --> 01:00:27,320 1290 01:00:27,320 --> 01:00:32,040 It was Blake Walsh [INAUDIBLE] one of our [INAUDIBLE]. 1291 01:00:32,040 --> 01:00:35,525 So beyond getting distracted by the '80s here, 1292 01:00:35,525 --> 01:00:39,007 let's consider how this program's probably working. 1293 01:00:39,007 --> 01:00:40,340 I'm hitting my arrow keys right. 1294 01:00:40,340 --> 01:00:44,220 That's the only form of control I have. 1295 01:00:44,220 --> 01:00:48,640 So how is Blake noticing that I'm hitting left key or the right key 1296 01:00:48,640 --> 01:00:51,340 or the down key or the up key? 1297 01:00:51,340 --> 01:00:53,542 What logic does it normally have? 1298 01:00:53,542 --> 01:00:58,519 Listener-- well, listeners potentially, yes, or a loop. 1299 01:00:58,519 --> 01:00:59,935 So one of those two models, right? 1300 01:00:59,935 --> 01:01:03,600 There's either a forever loop saying, hey, is the user hitting the left key? 1301 01:01:03,600 --> 01:01:05,450 If so, do something, move. 1302 01:01:05,450 --> 01:01:08,000 Else don't do anything. 1303 01:01:08,000 --> 01:01:09,720 And what's going to happen here? 1304 01:01:09,720 --> 01:01:14,932 We've not seen, this but Scratch as a block that says is if touching. 1305 01:01:14,932 --> 01:01:16,140 And actually we did see this. 1306 01:01:16,140 --> 01:01:17,630 We just saw that block and used it a moment ago 1307 01:01:17,630 --> 01:01:19,340 when the cat caught up to the bird. 1308 01:01:19,340 --> 01:01:20,594 It was touching the bird. 1309 01:01:20,594 --> 01:01:22,260 That's what triggered the sound to play. 1310 01:01:22,260 --> 01:01:24,740 And so what's kind of nice is once you have a bit of understanding 1311 01:01:24,740 --> 01:01:26,580 of programming, you can look at something, 1312 01:01:26,580 --> 01:01:30,090 even as relatively complicated as this, and infer 1313 01:01:30,090 --> 01:01:31,590 how it's probably implemented. 1314 01:01:31,590 --> 01:01:34,210 For instance, these cars-- those three cars on the very bottom 1315 01:01:34,210 --> 01:01:37,540 track-- how is that working? 1316 01:01:37,540 --> 01:01:39,830 Well, there's probably a forever loop. 1317 01:01:39,830 --> 01:01:43,920 And every time the loop happens, there's like move 10 or move 50, 1318 01:01:43,920 --> 01:01:44,710 or whatever it is. 1319 01:01:44,710 --> 01:01:46,520 And they're all moving to the left. 1320 01:01:46,520 --> 01:01:48,750 And then there's probably an if condition that says, 1321 01:01:48,750 --> 01:01:53,070 once you're off the screen, secretly go back to the other side. 1322 01:01:53,070 --> 01:01:55,380 So those three cars, I'm guessing-- and we 1323 01:01:55,380 --> 01:01:58,390 could check the code-- are probably the same three cars. 1324 01:01:58,390 --> 01:02:02,025 They're just sort of magically being reused by repositioning them there. 1325 01:02:02,025 --> 01:02:03,650 And that's happening with all the cars. 1326 01:02:03,650 --> 01:02:05,220 And why are they operating at different speeds? 1327 01:02:05,220 --> 01:02:06,470 Why are they not all the same? 1328 01:02:06,470 --> 01:02:09,832 1329 01:02:09,832 --> 01:02:13,040 Yeah, maybe there's different blocks, different loops for each of those cars. 1330 01:02:13,040 --> 01:02:15,160 And that's why they're moving at different speeds. 1331 01:02:15,160 --> 01:02:18,907 And then to be honest, as sort of complex as the game 1332 01:02:18,907 --> 01:02:21,990 might seem at first glance, there's not much more to explain there, right? 1333 01:02:21,990 --> 01:02:24,040 We talked about sprites touching others. 1334 01:02:24,040 --> 01:02:27,382 That's how you detect a car or if you hit the lily pad. 1335 01:02:27,382 --> 01:02:29,840 If you're unfamiliar with what the heck this thing even is, 1336 01:02:29,840 --> 01:02:34,020 the point of this game, if I can demonstrate this reliably-- and this 1337 01:02:34,020 --> 01:02:34,760 might be a bug. 1338 01:02:34,760 --> 01:02:38,190 I don't think this is going to be stuck on the-- I never caught this on play. 1339 01:02:38,190 --> 01:02:40,900 I never just sat here talking about it. 1340 01:02:40,900 --> 01:02:41,810 There we go. 1341 01:02:41,810 --> 01:02:45,942 Now I'm on this log here. 1342 01:02:45,942 --> 01:02:48,367 1343 01:02:48,367 --> 01:02:49,700 I think it's very underwhelming. 1344 01:02:49,700 --> 01:02:51,660 I don't think anything actually happens. 1345 01:02:51,660 --> 01:02:55,000 Well, maybe if get all seven of the lily pads covered there. 1346 01:02:55,000 --> 01:02:56,910 Anyhow, there's really not much to this game. 1347 01:02:56,910 --> 01:02:57,920 It looks complex. 1348 01:02:57,920 --> 01:03:00,920 So how in the world do you go about building something like this? 1349 01:03:00,920 --> 01:03:03,080 Well, I'm guessing when Blake set out to do this, 1350 01:03:03,080 --> 01:03:07,080 he certainly didn't try to build the whole thing all at once. 1351 01:03:07,080 --> 01:03:10,410 For instance, if you were going to build this game knowing only what you know 1352 01:03:10,410 --> 01:03:12,390 right now, where do you even begin? 1353 01:03:12,390 --> 01:03:14,951 1354 01:03:14,951 --> 01:03:16,950 What would be your first step if you were making 1355 01:03:16,950 --> 01:03:19,442 a to-do list for building a Frogger? 1356 01:03:19,442 --> 01:03:20,501 AUDIENCE: [INAUDIBLE] 1357 01:03:20,501 --> 01:03:22,250 DAVID MALAN: Set up the boundary, so maybe 1358 01:03:22,250 --> 01:03:24,541 do the aesthetics first, like make some kind of graphic 1359 01:03:24,541 --> 01:03:26,280 in Photoshop just to give you the road. 1360 01:03:26,280 --> 01:03:28,462 Because the road isn't changing. 1361 01:03:28,462 --> 01:03:30,670 The screen is physically moving right now the breeze. 1362 01:03:30,670 --> 01:03:32,092 But the road isn't moving. 1363 01:03:32,092 --> 01:03:34,800 The purple stuff, the black stuff, the green stuff are all fixed. 1364 01:03:34,800 --> 01:03:35,841 So those are just images. 1365 01:03:35,841 --> 01:03:38,360 1366 01:03:38,360 --> 01:03:40,455 What comes next? 1367 01:03:40,455 --> 01:03:41,330 AUDIENCE: [INAUDIBLE] 1368 01:03:41,330 --> 01:03:44,870 1369 01:03:44,870 --> 01:03:47,640 DAVID MALAN: Yeah. 1370 01:03:47,640 --> 01:03:50,840 OK, so the basic story, and what's one of the first pieces of the story 1371 01:03:50,840 --> 01:03:52,080 you could bite off? 1372 01:03:52,080 --> 01:03:56,690 Like what might version one of your game do and only do? 1373 01:03:56,690 --> 01:03:57,820 Maybe just the cars, right? 1374 01:03:57,820 --> 01:03:59,650 And frankly, I wouldn't try all the cars. 1375 01:03:59,650 --> 01:04:01,870 I'm going to pick one of these yellow and red cars. 1376 01:04:01,870 --> 01:04:04,930 I'm going to figure out how to just initially put it 1377 01:04:04,930 --> 01:04:06,100 over there on the right. 1378 01:04:06,100 --> 01:04:07,220 And then let me just make it move. 1379 01:04:07,220 --> 01:04:08,560 And it wouldn't take you very long, right? 1380 01:04:08,560 --> 01:04:10,476 I moved that cat from the middle of the screen 1381 01:04:10,476 --> 01:04:13,340 to the right of the screen pretty fast with just a couple of blocks, 1382 01:04:13,340 --> 01:04:14,700 a couple of puzzle pieces. 1383 01:04:14,700 --> 01:04:17,230 And then I might have to think about, all right, when he's off the screen, 1384 01:04:17,230 --> 01:04:18,570 now I need to put him back. 1385 01:04:18,570 --> 01:04:21,510 But you could imagine after five minutes, 20 minutes, an hour, 1386 01:04:21,510 --> 01:04:24,240 like figuring out how to move this one car. 1387 01:04:24,240 --> 01:04:27,010 Then you could probably duplicate or somehow clone that block 1388 01:04:27,010 --> 01:04:29,720 and make sure he spaced a little farther away from the other cars 1389 01:04:29,720 --> 01:04:32,160 and do it twice, then do it three times. 1390 01:04:32,160 --> 01:04:36,020 And then move on to the purple cars here and do the same thing again. 1391 01:04:36,020 --> 01:04:38,430 Then move on to the white and green, and then the trucks. 1392 01:04:38,430 --> 01:04:40,250 It's all really the same kind of thing. 1393 01:04:40,250 --> 01:04:42,000 Now, in a language like Scratch, you might 1394 01:04:42,000 --> 01:04:43,990 end up duplicating a whole bunch of code, 1395 01:04:43,990 --> 01:04:45,573 using the same things again and again. 1396 01:04:45,573 --> 01:04:48,420 In more modern programming languages there's a way to reuse code. 1397 01:04:48,420 --> 01:04:52,380 So you only implement one piece of code that moves a car, 1398 01:04:52,380 --> 01:04:54,750 and you somehow parameterize it or configure 1399 01:04:54,750 --> 01:04:59,820 it to be configurable to use yellow car, purple car, blue car, big truck, 1400 01:04:59,820 --> 01:05:01,100 and maybe the speed too. 1401 01:05:01,100 --> 01:05:04,380 So maybe the black box that is your movement code 1402 01:05:04,380 --> 01:05:08,240 accepts as input the color of the car and maybe the speed of the car 1403 01:05:08,240 --> 01:05:09,580 and maybe the direction, too. 1404 01:05:09,580 --> 01:05:12,180 But you can reuse that code, and that would be good practice. 1405 01:05:12,180 --> 01:05:14,910 And then after that, what about the frog? 1406 01:05:14,910 --> 01:05:16,876 Well, we could implement it on a separate day. 1407 01:05:16,876 --> 01:05:18,250 So that was my Saturday homework. 1408 01:05:18,250 --> 01:05:20,400 On Sunday I might implement the frog. 1409 01:05:20,400 --> 01:05:23,170 And using events or for loops, I just have to somehow respond 1410 01:05:23,170 --> 01:05:24,960 to up, down, left, or right. 1411 01:05:24,960 --> 01:05:26,910 And maybe he can go absolutely anywhere. 1412 01:05:26,910 --> 01:05:30,780 There is no notion of water initially because I just want the thing to work. 1413 01:05:30,780 --> 01:05:34,589 Then I go and implement the black water here, which I didn't fall into it, 1414 01:05:34,589 --> 01:05:36,880 but I'm pretty sure I'm not allowed to walk on to that. 1415 01:05:36,880 --> 01:05:37,940 Let's see. 1416 01:05:37,940 --> 01:05:39,693 So this is probably another feature. 1417 01:05:39,693 --> 01:05:43,267 1418 01:05:43,267 --> 01:05:44,100 It's not even black. 1419 01:05:44,100 --> 01:05:45,000 It's purple on my screen. 1420 01:05:45,000 --> 01:05:46,375 It's black on the projector here. 1421 01:05:46,375 --> 01:05:48,560 So it actually looks like water and so forth. 1422 01:05:48,560 --> 01:05:52,580 And so this would be generally known as hierarchical decomposition or 1423 01:05:52,580 --> 01:05:56,810 functional decomposition, like how can you go about taking a big problem 1424 01:05:56,810 --> 01:06:00,930 and breaking it up into smaller, much more palatable tasks, 1425 01:06:00,930 --> 01:06:02,570 maybe tasks that we could distribute? 1426 01:06:02,570 --> 01:06:05,940 So Nicolas does one thing, and Avi does another and so forth. 1427 01:06:05,940 --> 01:06:09,130 So that collectively we bring together the collective solution 1428 01:06:09,130 --> 01:06:09,930 to this problem. 1429 01:06:09,930 --> 01:06:12,590 And so that's pretty representative. 1430 01:06:12,590 --> 01:06:15,790 The very first program I wrote in Scratch in grad school years 1431 01:06:15,790 --> 01:06:21,170 ago was this, which has been modernized by one of our TFs now to be more green. 1432 01:06:21,170 --> 01:06:26,940 I implemented what's called Oscar Time, whereby trash falls from the sky, 1433 01:06:26,940 --> 01:06:30,845 and you're supposed to drag it into the trash, at which point, Oscar appears. 1434 01:06:30,845 --> 01:06:34,450 But as of 2015, we are green now. 1435 01:06:34,450 --> 01:06:39,050 So there's now been added a recycling bin and compost bin. 1436 01:06:39,050 --> 01:06:43,070 And this was meant to help subliminally teach the undergrads-- oh, that's 1437 01:06:43,070 --> 01:06:44,750 just not possible. 1438 01:06:44,750 --> 01:06:49,470 That is-- subliminally teach people what is compostable. 1439 01:06:49,470 --> 01:06:51,880 Anyhow, I can say from personal experience, 1440 01:06:51,880 --> 01:06:56,330 part of the process of coding is also debugging. 1441 01:06:56,330 --> 01:06:58,350 Oh, that's [INAUDIBLE]. 1442 01:06:58,350 --> 01:07:00,370 There's nothing-- I hate the song now. 1443 01:07:00,370 --> 01:07:03,250 Like hours and hours of playing with this game, 1444 01:07:03,250 --> 01:07:06,120 trying to get it right-- never again. 1445 01:07:06,120 --> 01:07:09,010 Anyhow, but something like that, what are the building blocks? 1446 01:07:09,010 --> 01:07:11,760 Well, I don't quite remember because it was so many years ago now. 1447 01:07:11,760 --> 01:07:14,020 But I think I started with just the stage. 1448 01:07:14,020 --> 01:07:17,020 Like I got the aesthetics right and the lamppost and the trash can, just 1449 01:07:17,020 --> 01:07:19,228 because I wanted to have a mental model for the game. 1450 01:07:19,228 --> 01:07:21,410 Then I think I just had one piece of trash fall, 1451 01:07:21,410 --> 01:07:23,636 and it just fell from the same place every time. 1452 01:07:23,636 --> 01:07:26,760 Then I added the feature for dragging and dropping, so that I could lift it 1453 01:07:26,760 --> 01:07:28,130 and then it would fall again. 1454 01:07:28,130 --> 01:07:29,680 And that wasn't all that interesting. 1455 01:07:29,680 --> 01:07:32,880 And then I added the feature to detect if it's touching the trash 1456 01:07:32,880 --> 01:07:35,100 can, at which point I hide the trash. 1457 01:07:35,100 --> 01:07:38,100 Then I didn't want the trash always falling from the same spot, 1458 01:07:38,100 --> 01:07:39,399 so I added a bit of randomness. 1459 01:07:39,399 --> 01:07:41,690 And indeed Scratch and computer programs will generally 1460 01:07:41,690 --> 01:07:44,440 let you have randomness-- pseudo randomness technically-- 1461 01:07:44,440 --> 01:07:46,950 that allows you to move the position either here, 1462 01:07:46,950 --> 01:07:50,240 here, here, or here, based on a range of values that you give. 1463 01:07:50,240 --> 01:07:52,840 And so there too, I sort of took the equivalent of baby steps 1464 01:07:52,840 --> 01:07:56,470 until the net effect, hopefully, at least, I thought, was very impressive. 1465 01:07:56,470 --> 01:07:59,670 But it was the result of very small bite-sized tasks. 1466 01:07:59,670 --> 01:08:03,760 And this is a general principle of software design-- modularizing things 1467 01:08:03,760 --> 01:08:08,150 such that you make very small, progressive steps, so that one, 1468 01:08:08,150 --> 01:08:10,590 you feel emotionally like you're making some progress. 1469 01:08:10,590 --> 01:08:14,010 Two, if you made mistakes, bug, so to speak, 1470 01:08:14,010 --> 01:08:18,557 they're within very narrowly defined spaces-- very few lines of code. 1471 01:08:18,557 --> 01:08:20,890 And three, so that you can work with others, each of you 1472 01:08:20,890 --> 01:08:22,630 contributing little pieces of code. 1473 01:08:22,630 --> 01:08:25,330 And this would be generally best practice. 1474 01:08:25,330 --> 01:08:28,410 So why don't we go ahead and do this. 1475 01:08:28,410 --> 01:08:32,390 Let me pause from speaking and propose a challenge 1476 01:08:32,390 --> 01:08:36,090 or so, as follows-- maybe a left half/right half kind of challenge. 1477 01:08:36,090 --> 01:08:38,330 Would anyone on this side of the room like 1478 01:08:38,330 --> 01:08:42,160 to propose a very simple program using a cat and maybe 1479 01:08:42,160 --> 01:08:46,943 nothing more that we would like this half of the room to implement? 1480 01:08:46,943 --> 01:08:48,859 What would you have the other half of the room 1481 01:08:48,859 --> 01:08:51,922 implement using just one cat as an ingredient? 1482 01:08:51,922 --> 01:08:52,963 What you want them to do? 1483 01:08:52,963 --> 01:09:01,227 1484 01:09:01,227 --> 01:09:03,060 So while they're thinking of something, what 1485 01:09:03,060 --> 01:09:05,684 would you all to challenge the other half of the room in doing? 1486 01:09:05,684 --> 01:09:10,520 1487 01:09:10,520 --> 01:09:12,631 AUDIENCE: [INAUDIBLE] 1488 01:09:12,631 --> 01:09:13,630 DAVID MALAN: Duplicates? 1489 01:09:13,630 --> 01:09:14,505 AUDIENCE: [INAUDIBLE] 1490 01:09:14,505 --> 01:09:16,645 1491 01:09:16,645 --> 01:09:17,895 DAVID MALAN: Is this possible? 1492 01:09:17,895 --> 01:09:21,550 1493 01:09:21,550 --> 01:09:22,497 I like it. 1494 01:09:22,497 --> 01:09:25,790 1495 01:09:25,790 --> 01:09:27,049 Is it with the clone? 1496 01:09:27,049 --> 01:09:31,740 1497 01:09:31,740 --> 01:09:34,460 Let me just-- OK, I think this is possible. 1498 01:09:34,460 --> 01:09:37,265 And I will give you a hint, right half of the room. 1499 01:09:37,265 --> 01:09:40,390 I think you'll need to use this puzzle piece, which we've not talked about, 1500 01:09:40,390 --> 01:09:42,770 but does what it says-- Create Clone Of Yourself. 1501 01:09:42,770 --> 01:09:44,825 And so just to be clear, we want something-- 1502 01:09:44,825 --> 01:09:45,700 AUDIENCE: [INAUDIBLE] 1503 01:09:45,700 --> 01:09:49,750 1504 01:09:49,750 --> 01:09:51,279 DAVID MALAN: So I'll elaborate. 1505 01:09:51,279 --> 01:09:52,820 Like the cat should be moving around. 1506 01:09:52,820 --> 01:09:56,990 Every time he hits the edge, he should maybe double, so one becomes two. 1507 01:09:56,990 --> 01:09:59,189 And maybe add some randomness so that both copies 1508 01:09:59,189 --> 01:10:01,480 don't go in the same direction where we won't see them. 1509 01:10:01,480 --> 01:10:03,730 There's got to be some randomness to the angle. 1510 01:10:03,730 --> 01:10:04,970 You should've spoken first. 1511 01:10:04,970 --> 01:10:07,570 So what would you all now like to challenge 1512 01:10:07,570 --> 01:10:09,285 the other half of the room to do? 1513 01:10:09,285 --> 01:10:10,160 AUDIENCE: [INAUDIBLE] 1514 01:10:10,160 --> 01:10:14,840 1515 01:10:14,840 --> 01:10:17,730 DAVID MALAN: So how would this work exactly? 1516 01:10:17,730 --> 01:10:18,605 AUDIENCE: [INAUDIBLE] 1517 01:10:18,605 --> 01:10:20,945 1518 01:10:20,945 --> 01:10:22,320 DAVID MALAN: We can go with that. 1519 01:10:22,320 --> 01:10:24,610 So how about every time he bounces off the wall, 1520 01:10:24,610 --> 01:10:28,150 he shrinks in size, starting large and going small. 1521 01:10:28,150 --> 01:10:30,430 And feel free to call me over, but the lesson here 1522 01:10:30,430 --> 01:10:32,830 is one, to just give you a sense of the logical flow, 1523 01:10:32,830 --> 01:10:34,490 see how many different answers we get. 1524 01:10:34,490 --> 01:10:37,156 And it'll be a nice transition, I think, ultimately, into lunch. 1525 01:10:37,156 --> 01:10:37,924 Avi? 1526 01:10:37,924 --> 01:10:39,100 AUDIENCE: [INAUDIBLE] 1527 01:10:39,100 --> 01:10:40,850 DAVID MALAN: You're welcome to collaborate 1528 01:10:40,850 --> 01:10:42,140 with your partner next to you. 1529 01:10:42,140 --> 01:10:45,146 But let's get as many working implementations as possible. 1530 01:10:45,146 --> 01:10:47,520 But you're welcome to lean on someone else for some help. 1531 01:10:47,520 --> 01:10:50,200 And the goal here will be-- I would encourage you first 1532 01:10:50,200 --> 01:10:53,420 flip through all of the various puzzle pieces that are accessible, 1533 01:10:53,420 --> 01:10:56,341 just wrap your mind around what the ingredients are and then 1534 01:10:56,341 --> 01:10:57,840 think about how you might implement. 1535 01:10:57,840 --> 01:11:00,130 And if you would like to remember some of the examples 1536 01:11:00,130 --> 01:11:04,140 we just did, especially involving motion, if you go to today's slides, 1537 01:11:04,140 --> 01:11:06,870 after the Scratch URL is this one here. 1538 01:11:06,870 --> 01:11:09,750 This Studios URL will lead you to all of the examples 1539 01:11:09,750 --> 01:11:13,480 that we just flipped through, if you want to see those as well. 1540 01:11:13,480 --> 01:11:16,130 Despite my constant refreshing, we have just these five. 1541 01:11:16,130 --> 01:11:17,910 But that's OK. 1542 01:11:17,910 --> 01:11:20,200 Feel free to still add if you'd like. 1543 01:11:20,200 --> 01:11:25,580 So let's take a look at this one here and see. 1544 01:11:25,580 --> 01:11:28,260 OK, so Scratch seems to start quite small. 1545 01:11:28,260 --> 01:11:32,350 He seems to be just a fleck on the stage over there. 1546 01:11:32,350 --> 01:11:35,684 I'm going to go ahead and blindly do this. 1547 01:11:35,684 --> 01:11:42,950 1548 01:11:42,950 --> 01:11:43,930 Is this as expected? 1549 01:11:43,930 --> 01:11:50,352 1550 01:11:50,352 --> 01:11:52,330 AUDIENCE: [INAUDIBLE] 1551 01:11:52,330 --> 01:11:54,380 DAVID MALAN: Oh, wow. 1552 01:11:54,380 --> 01:11:55,726 That's an unexpected feature. 1553 01:11:55,726 --> 01:11:58,920 1554 01:11:58,920 --> 01:12:02,912 And now he's getting smaller, but he's so large, it's not very quickly. 1555 01:12:02,912 --> 01:12:06,980 1556 01:12:06,980 --> 01:12:09,156 This is the one called left side smaller. 1557 01:12:09,156 --> 01:12:14,154 1558 01:12:14,154 --> 01:12:15,070 When in doubt, reload. 1559 01:12:15,070 --> 01:12:18,220 1560 01:12:18,220 --> 01:12:19,800 So let's see how this was working. 1561 01:12:19,800 --> 01:12:24,370 So we have just one script here, and when space key pressed, 1562 01:12:24,370 --> 01:12:25,420 change size by 10. 1563 01:12:25,420 --> 01:12:28,550 I made the mistake of holding it down in perpetuity. 1564 01:12:28,550 --> 01:12:33,400 So forever repeat 10 times move 50 steps. 1565 01:12:33,400 --> 01:12:38,600 OK so if it's OK, let's critique or react to some of these blocks of code. 1566 01:12:38,600 --> 01:12:40,880 Repeat 10 times move 50 steps. 1567 01:12:40,880 --> 01:12:44,250 I do think there's an opportunity for improvement here. 1568 01:12:44,250 --> 01:12:47,990 What could we do to express this equivalently with less code, 1569 01:12:47,990 --> 01:12:50,500 so to speak? 1570 01:12:50,500 --> 01:12:51,910 AUDIENCE: [INAUDIBLE] 1571 01:12:51,910 --> 01:12:54,243 DAVID MALAN: Yeah, I would just replace this potentially 1572 01:12:54,243 --> 01:12:56,917 with one move 500 steps block just because it cleans it up. 1573 01:12:56,917 --> 01:12:58,500 And this would be a general principle. 1574 01:12:58,500 --> 01:13:01,890 If you can express as clearly but more specifically 1575 01:13:01,890 --> 01:13:04,600 some operation with less code, you should. 1576 01:13:04,600 --> 01:13:05,392 If on edge, bounce. 1577 01:13:05,392 --> 01:13:07,766 So that's what's getting the cat bouncing back and forth. 1578 01:13:07,766 --> 01:13:10,730 It looks like this middle if condition, if touching edge, then nothing, 1579 01:13:10,730 --> 01:13:12,896 that's probably just left over from a previous idea. 1580 01:13:12,896 --> 01:13:14,820 So that could be removed altogether. 1581 01:13:14,820 --> 01:13:19,840 And if touching edge, then play the drum number 12 for 0.25 beats 1582 01:13:19,840 --> 01:13:22,650 and then change size by negative five. 1583 01:13:22,650 --> 01:13:26,252 So that negative five is what keeps making the cat smaller and smaller, 1584 01:13:26,252 --> 01:13:27,960 unless you're holding down the space bar. 1585 01:13:27,960 --> 01:13:29,320 So let's play it once more. 1586 01:13:29,320 --> 01:13:31,070 That's a neat effect in the end. 1587 01:13:31,070 --> 01:13:34,270 So that's what the drum sounds like. 1588 01:13:34,270 --> 01:13:40,110 And if I hold the space, it gets bigger, then gets smaller, smaller, smaller, 1589 01:13:40,110 --> 01:13:42,950 and smaller, until I do this again. 1590 01:13:42,950 --> 01:13:46,040 Really cute variant adding the space bar there. 1591 01:13:46,040 --> 01:13:48,380 So let's take a look at another one here. 1592 01:13:48,380 --> 01:13:49,352 We have a nice stage. 1593 01:13:49,352 --> 01:13:52,310 So someone took to heart by suggestion you always start with the stage. 1594 01:13:52,310 --> 01:13:55,110 Already we have a nice backdrop here. 1595 01:13:55,110 --> 01:13:57,550 Let's hit Play. 1596 01:13:57,550 --> 01:14:02,850 So let's see, when I start as clone, move five. 1597 01:14:02,850 --> 01:14:05,815 Did I hit the-- oh, there we go. 1598 01:14:05,815 --> 01:14:08,700 1599 01:14:08,700 --> 01:14:09,741 Nice. 1600 01:14:09,741 --> 01:14:10,240 Nice. 1601 01:14:10,240 --> 01:14:13,216 1602 01:14:13,216 --> 01:14:15,439 Oh, my god. 1603 01:14:15,439 --> 01:14:16,480 It's kind of mesmerizing. 1604 01:14:16,480 --> 01:14:18,916 1605 01:14:18,916 --> 01:14:19,832 AUDIENCE: That's cool. 1606 01:14:19,832 --> 01:14:26,800 1607 01:14:26,800 --> 01:14:30,874 DAVID MALAN: And what effect do you see happening besides more cats? 1608 01:14:30,874 --> 01:14:33,780 1609 01:14:33,780 --> 01:14:34,520 This is adorable. 1610 01:14:34,520 --> 01:14:38,120 I think we're going to have to use this example s the fall. 1611 01:14:38,120 --> 01:14:39,600 Something's happening though. 1612 01:14:39,600 --> 01:14:42,840 1613 01:14:42,840 --> 01:14:44,570 Changing of direction. 1614 01:14:44,570 --> 01:14:46,860 AUDIENCE: [INAUDIBLE] 1615 01:14:46,860 --> 01:14:48,960 DAVID MALAN: Yeah, it seems to my eyes here 1616 01:14:48,960 --> 01:14:51,360 like it's all kind of getting slower, like it's 1617 01:14:51,360 --> 01:14:53,440 getting a little more like stuttery. 1618 01:14:53,440 --> 01:14:57,250 1619 01:14:57,250 --> 01:15:00,250 And honestly, I think we must have already hit the limit because. 1620 01:15:00,250 --> 01:15:05,860 If we're doubling every time, think how quickly after doubling 32 times, 1621 01:15:05,860 --> 01:15:09,180 how many cats would there be? 1622 01:15:09,180 --> 01:15:12,880 Start with one cat, double in 32 times. 1623 01:15:12,880 --> 01:15:13,610 4 billion, right? 1624 01:15:13,610 --> 01:15:16,068 There's only four answers mathematically the past two days. 1625 01:15:16,068 --> 01:15:19,430 So 4 billion cats, I'm pretty sure I don't see 4 billion cats because it 1626 01:15:19,430 --> 01:15:21,344 probably be just a bigger mass even. 1627 01:15:21,344 --> 01:15:23,510 So there probably is some limit, but even that limit 1628 01:15:23,510 --> 01:15:25,720 is pushing the limits of Scratch, but very well 1629 01:15:25,720 --> 01:15:28,930 done in terms of the spec and a nice pretty background. 1630 01:15:28,930 --> 01:15:31,150 Let's look at s third here. 1631 01:15:31,150 --> 01:15:32,490 Go back here. 1632 01:15:32,490 --> 01:15:37,710 Balloon cat, hit Play on this one. 1633 01:15:37,710 --> 01:15:38,990 Let's see inside. 1634 01:15:38,990 --> 01:15:41,630 Hit Play here. 1635 01:15:41,630 --> 01:15:48,504 When space key-- oh, very cute. 1636 01:15:48,504 --> 01:15:50,670 So he kind of pops when he gets smaller and smaller. 1637 01:15:50,670 --> 01:15:57,274 1638 01:15:57,274 --> 01:15:58,190 And then he does that. 1639 01:15:58,190 --> 01:16:00,110 Nice, very nice. 1640 01:16:00,110 --> 01:16:00,950 Let's go here. 1641 01:16:00,950 --> 01:16:03,590 This one's just in-- Cat dot, dot, dot. 1642 01:16:03,590 --> 01:16:05,484 See inside. 1643 01:16:05,484 --> 01:16:08,812 [MEOWING] 1644 01:16:08,812 --> 01:16:11,000 He seems to be getting progressively smaller. 1645 01:16:11,000 --> 01:16:13,750 1646 01:16:13,750 --> 01:16:17,472 And there does seem to be a lower bound on how small they let Scratch get. 1647 01:16:17,472 --> 01:16:24,200 1648 01:16:24,200 --> 01:16:27,894 Not in this one. 1649 01:16:27,894 --> 01:16:29,270 Cute. 1650 01:16:29,270 --> 01:16:30,470 All right, it's very nice. 1651 01:16:30,470 --> 01:16:35,148 And let's see two more-- Scratch Shrink. 1652 01:16:35,148 --> 01:16:38,004 [MEOWING] 1653 01:16:38,004 --> 01:16:41,812 1654 01:16:41,812 --> 01:16:42,890 There's more randomness. 1655 01:16:42,890 --> 01:16:44,460 It seems to be angles this time. 1656 01:16:44,460 --> 01:16:49,731 1657 01:16:49,731 --> 01:16:52,610 This is really cute. 1658 01:16:52,610 --> 01:16:57,150 If hit the space bar, it gets 200% again. 1659 01:16:57,150 --> 01:17:00,815 1660 01:17:00,815 --> 01:17:03,690 But there, too, you can see the limits of too much happening at once. 1661 01:17:03,690 --> 01:17:07,694 When I hold the space bar when he'd bouncing-- I 1662 01:17:07,694 --> 01:17:08,860 can't quite induce it again. 1663 01:17:08,860 --> 01:17:11,668 1664 01:17:11,668 --> 01:17:14,270 And even the sound is struggling to keep up. 1665 01:17:14,270 --> 01:17:14,770 Very nice. 1666 01:17:14,770 --> 01:17:17,227 And the last but not least, Runaway Sprite. 1667 01:17:17,227 --> 01:17:21,430 1668 01:17:21,430 --> 01:17:22,250 Another clone. 1669 01:17:22,250 --> 01:17:23,780 I love it. 1670 01:17:23,780 --> 01:17:24,730 It's mesmerizing. 1671 01:17:24,730 --> 01:17:27,070 I love it. 1672 01:17:27,070 --> 01:17:27,570 Oh. 1673 01:17:27,570 --> 01:17:31,302 1674 01:17:31,302 --> 01:17:32,697 That's really cool. 1675 01:17:32,697 --> 01:17:35,770 1676 01:17:35,770 --> 01:17:39,220 There's something very Simpsons like about it too somehow. 1677 01:17:39,220 --> 01:17:40,721 Well, congratulations to both sides. 1678 01:17:40,721 --> 01:17:42,094 And thank you for the challenges. 1679 01:17:42,094 --> 01:17:42,936 Those were terrific. 1680 01:17:42,936 --> 01:17:44,810 Why don't we go ahead and we'll take a break. 1681 01:17:44,810 --> 01:17:48,000 And at 1:30 we'll resume, taking a closer look at libraries, 1682 01:17:48,000 --> 01:17:53,080 at frameworks, and technologies more generally. 1683 01:17:53,080 --> 01:17:54,919