1 00:00:00,000 --> 00:00:03,465 [CLASSICAL MUSIC] 2 00:00:03,465 --> 00:00:10,395 3 00:00:10,395 --> 00:00:12,870 [MUSIC - SESAME STREET'S OSCAR THE GROUCH, "I LOVE TRASH"] 4 00:00:12,870 --> 00:00:17,830 OSCAR THE GROUCH: (SINGING) Oh, I love trash. 5 00:00:17,830 --> 00:00:21,850 Anything dirty or dingy or dusty. 6 00:00:21,850 --> 00:00:26,435 Anything ragged or rotten or rusty. 7 00:00:26,435 --> 00:00:30,130 Yes, I love trash. 8 00:00:30,130 --> 00:00:32,980 If you really want to see something trashy, look at this. 9 00:00:32,980 --> 00:00:37,210 I have here a sneaker that's tattered and worn. 10 00:00:37,210 --> 00:00:39,400 DAVID J. MALAN: So this is, believe it or not, 11 00:00:39,400 --> 00:00:43,420 the very first program I wrote using a programming language called Scratch. 12 00:00:43,420 --> 00:00:45,310 It's a graphical programming language that 13 00:00:45,310 --> 00:00:48,130 was developed by MIT'S lifelong Kindergarten Group. 14 00:00:48,130 --> 00:00:50,650 And it was designed, initially, as an environment 15 00:00:50,650 --> 00:00:55,030 with which to get students excited about computing about technology, especially 16 00:00:55,030 --> 00:00:56,350 after-school programs. 17 00:00:56,350 --> 00:00:58,570 But what's wonderfully exciting about it too, 18 00:00:58,570 --> 00:01:00,380 is that it's also wonderfully instructive 19 00:01:00,380 --> 00:01:02,692 when it comes to what programming is. 20 00:01:02,692 --> 00:01:05,650 And indeed, we'll be able to use this programming language, ultimately, 21 00:01:05,650 --> 00:01:09,040 to explore the whole world of programming. 22 00:01:09,040 --> 00:01:11,740 Now, what is programming? 23 00:01:11,740 --> 00:01:14,470 So programming is ultimately about making software. 24 00:01:14,470 --> 00:01:19,260 And software, of course, is what runs on our hardware, runs on our computers. 25 00:01:19,260 --> 00:01:22,570 Software is something you double-click and then see and can interact with. 26 00:01:22,570 --> 00:01:26,560 Software is the files that you open on your computer and interact with. 27 00:01:26,560 --> 00:01:31,120 And software, ultimately, is what is written using programming code. 28 00:01:31,120 --> 00:01:34,130 Now, the software itself ultimately runs in any number of devices. 29 00:01:34,130 --> 00:01:36,340 It might be your desktop PC or your Mac. 30 00:01:36,340 --> 00:01:38,540 It might be your iPhone or your Android phone. 31 00:01:38,540 --> 00:01:40,990 But at the end of the day, all of those devices 32 00:01:40,990 --> 00:01:45,670 are programmed by a human writing, quite simply, code. 33 00:01:45,670 --> 00:01:47,140 What is code exactly? 34 00:01:47,140 --> 00:01:51,010 Well, at the end of the day, code is really just a technical implementation 35 00:01:51,010 --> 00:01:53,470 of algorithms, where algorithms themselves 36 00:01:53,470 --> 00:01:56,380 are step-by-step instructions for solving some problem. 37 00:01:56,380 --> 00:01:58,726 Now, what kind of problems might we want to solve? 38 00:01:58,726 --> 00:02:00,600 Well, let's consider an old-school one first. 39 00:02:00,600 --> 00:02:04,360 40 00:02:04,360 --> 00:02:08,650 This here is an older technology, an old-school phonebook, inside of which 41 00:02:08,650 --> 00:02:11,350 are thousands of names and thousands of numbers. 42 00:02:11,350 --> 00:02:13,840 But it's a wonderful opportunity to think about a problem 43 00:02:13,840 --> 00:02:16,750 that we might want to solve, like looking someone up in a phonebook 44 00:02:16,750 --> 00:02:18,550 so that you can actually call them? 45 00:02:18,550 --> 00:02:21,970 Well, suppose I'm actually looking for someone like Mike Smith. 46 00:02:21,970 --> 00:02:25,030 Now, I can find Mike Smith in any number of ways in this phonebook, 47 00:02:25,030 --> 00:02:26,560 assuming he's actually in here. 48 00:02:26,560 --> 00:02:31,210 I might initially start very correctly and very foolishly, 49 00:02:31,210 --> 00:02:34,300 perhaps, at the first page, looking down for Mike. 50 00:02:34,300 --> 00:02:35,020 I don't see him. 51 00:02:35,020 --> 00:02:37,330 So I move to the second page, look down. 52 00:02:37,330 --> 00:02:39,961 And I don't see him at the third page, and so forth. 53 00:02:39,961 --> 00:02:41,710 And as I proceed through the phone book, I 54 00:02:41,710 --> 00:02:45,659 do claim that this algorithm, this set of instructions, step-by-step, 55 00:02:45,659 --> 00:02:47,200 for solving this problem, is correct. 56 00:02:47,200 --> 00:02:50,130 Because if Mike is here, I'm going to find him eventually. 57 00:02:50,130 --> 00:02:52,200 But of course, this is completely ridiculous. 58 00:02:52,200 --> 00:02:53,950 This is a completely inefficient algorithm 59 00:02:53,950 --> 00:02:55,150 for actually finding Mike Smith. 60 00:02:55,150 --> 00:02:55,690 Why? 61 00:02:55,690 --> 00:02:57,190 Well, it's going to take me forever to find him 62 00:02:57,190 --> 00:02:59,398 if he's all the way toward the end of the phone book. 63 00:02:59,398 --> 00:03:01,170 Wait, I know how to do this faster. 64 00:03:01,170 --> 00:03:02,980 I remember, from grade school, an old trick 65 00:03:02,980 --> 00:03:05,479 where, rather than counting by ones, you might count by two. 66 00:03:05,479 --> 00:03:09,010 So here I might do 2, 4, 6-- 67 00:03:09,010 --> 00:03:09,730 literally. 68 00:03:09,730 --> 00:03:11,110 [LAUGHS] 69 00:03:11,110 --> 00:03:12,910 This algorithm turns out, is much slower. 70 00:03:12,910 --> 00:03:17,350 6, 8, 10, 12, 14, 16, 18, and so forth. 71 00:03:17,350 --> 00:03:21,050 And at that rate, I'll certainly find Mike much faster, twice as fast, 72 00:03:21,050 --> 00:03:21,950 in fact. 73 00:03:21,950 --> 00:03:24,700 But is that algorithm, are those steps correct? 74 00:03:24,700 --> 00:03:26,140 Now, they're not quite correct. 75 00:03:26,140 --> 00:03:29,830 Because what if by chance I happened to be grabbing two pages 76 00:03:29,830 --> 00:03:32,290 and Mike happens to be sandwiched in between them? 77 00:03:32,290 --> 00:03:34,610 I might blow right past Mike's name in the phone book. 78 00:03:34,610 --> 00:03:36,889 So I better have at least a check, a sort of condition 79 00:03:36,889 --> 00:03:38,680 where I think to myself, wait a minute if I 80 00:03:38,680 --> 00:03:41,470 hit someone whose name starts with t instead of s, 81 00:03:41,470 --> 00:03:42,880 maybe I should double back. 82 00:03:42,880 --> 00:03:44,290 At least one page. 83 00:03:44,290 --> 00:03:47,989 Of course, no one out there-- if you even still use this technology-- 84 00:03:47,989 --> 00:03:49,780 is going to solve this problem in that way. 85 00:03:49,780 --> 00:03:51,140 What are you going to do instead? 86 00:03:51,140 --> 00:03:52,450 Well, if you're like me, you're probably going 87 00:03:52,450 --> 00:03:55,000 to instinctively go roughly to the middle of the phone book 88 00:03:55,000 --> 00:03:57,190 and look down there to see where you are. 89 00:03:57,190 --> 00:03:59,170 Odds are, if you're like me in this book here, 90 00:03:59,170 --> 00:04:01,590 you're going to find yourself in the M section. 91 00:04:01,590 --> 00:04:06,700 But Smith, of course, comes after M. And so we know Mike is to the right side 92 00:04:06,700 --> 00:04:07,390 here. 93 00:04:07,390 --> 00:04:11,257 And so that suggests that we could take a pretty big bite out of this problem. 94 00:04:11,257 --> 00:04:13,340 I don't need to start flipping one page at a time. 95 00:04:13,340 --> 00:04:16,254 I know Mike is not in this half of the phone book. 96 00:04:16,254 --> 00:04:19,089 And what's nice about this intuition is that, you know what? 97 00:04:19,089 --> 00:04:25,390 I can not only figuratively but shall we say, tear this problem in half. 98 00:04:25,390 --> 00:04:27,370 That wasn't really very hard at all this time. 99 00:04:27,370 --> 00:04:31,480 Throw 1/2 of the problem away, and I'm left with just 1/2 100 00:04:31,480 --> 00:04:33,270 of the very same problem, fundamentally. 101 00:04:33,270 --> 00:04:34,300 Now, what might I do? 102 00:04:34,300 --> 00:04:36,330 I don't want to resort to the slower approach. 103 00:04:36,330 --> 00:04:40,210 I want to leverage that intuition, divide and conquer this problem, 104 00:04:40,210 --> 00:04:42,610 look down and realize, oh, I'm in the T section, 105 00:04:42,610 --> 00:04:44,650 I went a little too far, but no big deal. 106 00:04:44,650 --> 00:04:50,230 Let's tear the problem in 2/3 and really, in 1/2. 107 00:04:50,230 --> 00:04:52,720 So I'm left with just 1/4 of the problem now. 108 00:04:52,720 --> 00:04:56,770 And I can repeat this algorithm again and again and again, 109 00:04:56,770 --> 00:05:02,140 until theoretically, I'm left with just Mike's number on this one sheet, 110 00:05:02,140 --> 00:05:04,255 or in this case, one scrap of paper. 111 00:05:04,255 --> 00:05:05,630 So what have I really done there? 112 00:05:05,630 --> 00:05:09,550 So the intuition, ultimately, is that rather than looking for Mike one page 113 00:05:09,550 --> 00:05:13,750 at a time, I'm instead leveraging the fact that that phone book is sorted. 114 00:05:13,750 --> 00:05:17,500 And I'm literally dividing and conquering the problem again and again 115 00:05:17,500 --> 00:05:21,850 and again so that if I started with 1,000 pages, I then go down to 500. 116 00:05:21,850 --> 00:05:26,230 I then go down to 250, 125, as opposed to starting at 1,000 117 00:05:26,230 --> 00:05:33,130 and going to 999, then 998, 997, which surely is going to take me much longer. 118 00:05:33,130 --> 00:05:36,100 Of course, that's not the real way to tear a phone book in half. 119 00:05:36,100 --> 00:05:40,420 So fortunately there are just two of these books left on earth. 120 00:05:40,420 --> 00:05:42,770 And we have the second one here. 121 00:05:42,770 --> 00:05:45,250 So indeed, if I want to go ahead and tear a problem in 1/2, 122 00:05:45,250 --> 00:05:47,615 the real way you do this-- shall we say? 123 00:05:47,615 --> 00:05:49,280 There we go-- is-- 124 00:05:49,280 --> 00:05:52,432 125 00:05:52,432 --> 00:05:54,360 [STRAINS] 126 00:05:54,360 --> 00:05:55,330 127 00:05:55,330 --> 00:05:56,380 --that way. 128 00:05:56,380 --> 00:06:01,190 But now back to some programming. 129 00:06:01,190 --> 00:06:02,910 So I just solved that problem. 130 00:06:02,910 --> 00:06:06,080 But what was the algorithm exactly that I used to solve it? 131 00:06:06,080 --> 00:06:08,570 In fact, can we distill some of the key components 132 00:06:08,570 --> 00:06:11,150 of what I did fairly intuitively and see if we 133 00:06:11,150 --> 00:06:13,460 can't then later apply those same principles 134 00:06:13,460 --> 00:06:15,740 to solving other problems altogether? 135 00:06:15,740 --> 00:06:17,135 Well, let's consider this. 136 00:06:17,135 --> 00:06:19,760 I propose that the very first thing I did was this in step one, 137 00:06:19,760 --> 00:06:21,200 I picked up the phone book. 138 00:06:21,200 --> 00:06:26,150 Step two, I opened to the middle of the phone book, and I looked at the names. 139 00:06:26,150 --> 00:06:27,650 But then I had to make a decision. 140 00:06:27,650 --> 00:06:30,620 Because I was, at that point, presented with some information 141 00:06:30,620 --> 00:06:31,770 as to what is on the page. 142 00:06:31,770 --> 00:06:37,240 And so step four, if Smith is among the names, on the page, then, step five, 143 00:06:37,240 --> 00:06:38,710 I was going to call Mike. 144 00:06:38,710 --> 00:06:41,990 Else if, step six, Smith is earlier in the book, that is, 145 00:06:41,990 --> 00:06:44,810 he's to the left alphabetically, well then, logically I 146 00:06:44,810 --> 00:06:48,980 should open to the middle of the left half of the book 147 00:06:48,980 --> 00:06:53,090 and then go back to step three, thereby looking at names again and continuing 148 00:06:53,090 --> 00:06:54,650 down this same set of steps. 149 00:06:54,650 --> 00:06:59,240 However, if after step six, I decide no, Smith is not earlier in the book 150 00:06:59,240 --> 00:07:01,550 and therefore, I should not do step seven and eight, 151 00:07:01,550 --> 00:07:05,000 well then, let me ask the question else if Smith is later in the book, 152 00:07:05,000 --> 00:07:07,790 then is he to the right of where I'm currently looking? 153 00:07:07,790 --> 00:07:11,420 And if so, opens in the middle of the right half of the book 154 00:07:11,420 --> 00:07:13,340 and then go back to step three. 155 00:07:13,340 --> 00:07:16,950 Because now I'm looking at a different page and a different set of names. 156 00:07:16,950 --> 00:07:19,767 However, if that's not the case that Mike's among the names, 157 00:07:19,767 --> 00:07:22,100 and it's not the case that Smith is earlier in the book, 158 00:07:22,100 --> 00:07:25,430 and it's not the case that Smith is later in the book, then what should 159 00:07:25,430 --> 00:07:27,290 I do, perhaps, in step 12? 160 00:07:27,290 --> 00:07:31,880 Well else or otherwise, I should incept their team just quit. 161 00:07:31,880 --> 00:07:35,900 Because logically, if Mike's not on this page, and he's not to the left, 162 00:07:35,900 --> 00:07:39,750 and he's not to the right, that he must not be in the book at all. 163 00:07:39,750 --> 00:07:41,700 And so what do we have here? 164 00:07:41,700 --> 00:07:44,000 Well, this is something that I would call code. 165 00:07:44,000 --> 00:07:48,057 It's not written in C or C++ or Java, or some other programming language you 166 00:07:48,057 --> 00:07:48,890 might have heard of. 167 00:07:48,890 --> 00:07:52,850 It's written in English of some sort, pretty succinct, terse English. 168 00:07:52,850 --> 00:07:55,340 And indeed, it doesn't follow any particular vocabulary. 169 00:07:55,340 --> 00:07:58,910 I just tried to say each of these lines as succinctly as I could. 170 00:07:58,910 --> 00:08:01,940 So we'll call it pseudo code, sort of code-like syntax 171 00:08:01,940 --> 00:08:04,670 that happens to be written in English, so you could write it 172 00:08:04,670 --> 00:08:05,960 in most any other language. 173 00:08:05,960 --> 00:08:08,210 But what's important is a few characteristics. 174 00:08:08,210 --> 00:08:11,420 One, just to keep things nice and orderly, I've numbered the lines. 175 00:08:11,420 --> 00:08:12,800 Now, I did that manually. 176 00:08:12,800 --> 00:08:15,140 Software can certainly do that automatically for us. 177 00:08:15,140 --> 00:08:18,020 But that helps me make sense of what comes after what. 178 00:08:18,020 --> 00:08:21,080 And in particular, it also allows me, in steps 8 and 11 179 00:08:21,080 --> 00:08:23,360 to make these back references and sort of go back 180 00:08:23,360 --> 00:08:26,240 to and re-execute some earlier lines. 181 00:08:26,240 --> 00:08:30,976 But there's also some similarities, I'd argue, among some of the verbs 182 00:08:30,976 --> 00:08:32,850 and some of the language here that I've used. 183 00:08:32,850 --> 00:08:35,419 Let's see if we can't highlight a few of those principles. 184 00:08:35,419 --> 00:08:38,570 So one, notice here in yellow, are a whole bunch 185 00:08:38,570 --> 00:08:41,090 of actions, a whole bunch of verbs, that are 186 00:08:41,090 --> 00:08:45,500 telling me to go do something, pick up, open to, look at, call, open, 187 00:08:45,500 --> 00:08:47,210 go back, quit. 188 00:08:47,210 --> 00:08:51,830 Those are all very specific procedures, or we'll call them functions, 189 00:08:51,830 --> 00:08:53,240 shall we say? 190 00:08:53,240 --> 00:08:55,790 What else is similar among these lines? 191 00:08:55,790 --> 00:08:58,610 Well, here I have if, else if, else if, and else. 192 00:08:58,610 --> 00:09:02,640 So let's henceforth call those conditions, or branches. 193 00:09:02,640 --> 00:09:04,010 Really, they're decision points. 194 00:09:04,010 --> 00:09:06,295 This is really a four-way decision point. 195 00:09:06,295 --> 00:09:08,420 And I have to go down either this road or that road 196 00:09:08,420 --> 00:09:12,230 or this other road or this fourth road when making a decision. 197 00:09:12,230 --> 00:09:15,130 But what do I use as input to make that decision? 198 00:09:15,130 --> 00:09:18,410 Well, let's consider these questions, really, that we're asking ourself. 199 00:09:18,410 --> 00:09:21,350 Is Smith among the names on the page in front of me? 200 00:09:21,350 --> 00:09:22,730 Is Smith earlier in the book? 201 00:09:22,730 --> 00:09:23,960 Is Smith later in the book? 202 00:09:23,960 --> 00:09:27,830 Well, a programmer would call those three phrases Boolean 203 00:09:27,830 --> 00:09:31,300 expressions, named after someone by the last name of Boole. 204 00:09:31,300 --> 00:09:35,780 And a Boolean expression, by definition, is either true or false, yes or no. 205 00:09:35,780 --> 00:09:39,060 So it's really a question that has a yes-no, or true-false answer. 206 00:09:39,060 --> 00:09:42,440 And indeed, each of these yellow phrases has an answer. 207 00:09:42,440 --> 00:09:45,320 Because I use that answer, yes or no, to decide 208 00:09:45,320 --> 00:09:48,170 whether or not to execute some subsequent lines. 209 00:09:48,170 --> 00:09:52,610 And in particular, notice that only if those Boolean expressions, and ergo, 210 00:09:52,610 --> 00:09:57,890 the whole branch is true and is to be taken, only then should 211 00:09:57,890 --> 00:10:05,270 I execute lines 5 and 7 and 8, and 10 and 11 and 13. 212 00:10:05,270 --> 00:10:07,700 And notice, per the indentation, that those lines are very 213 00:10:07,700 --> 00:10:10,850 deliberately associated with exactly those conditions. 214 00:10:10,850 --> 00:10:16,250 So you only do them if the line above them is true, or is yes. 215 00:10:16,250 --> 00:10:18,050 Lastly, there is this curiosity. 216 00:10:18,050 --> 00:10:21,580 And both line 8 and line 11 go back to step three. 217 00:10:21,580 --> 00:10:25,264 Well, henceforth, let's start calling this a loop or a cycle. 218 00:10:25,264 --> 00:10:27,680 Because conceptually, that's pretty much what's happening. 219 00:10:27,680 --> 00:10:31,640 I'm being told, in steps 8 and 11, to go back to some earlier step. 220 00:10:31,640 --> 00:10:33,800 But given that I came from that step, this 221 00:10:33,800 --> 00:10:36,080 is a loop, in the sense that I'm going to keep doing, 222 00:10:36,080 --> 00:10:38,120 perhaps, the same thing again and again. 223 00:10:38,120 --> 00:10:40,040 Maybe going left maybe going right, hopefully 224 00:10:40,040 --> 00:10:43,460 eventually exiting or calling Mike, because I've deliberately 225 00:10:43,460 --> 00:10:46,250 induced some kind of loop here. 226 00:10:46,250 --> 00:10:49,850 But these aren't the only ideas that we might see in a computer program. 227 00:10:49,850 --> 00:10:53,720 And indeed, that's what that was, finding Mike Smith in that phone book, 228 00:10:53,720 --> 00:10:57,890 that was, effectively, a computer program being executed by me, albeit, 229 00:10:57,890 --> 00:10:58,520 a human. 230 00:10:58,520 --> 00:11:02,320 But the code, or the pseudo-code that drove my thinking 231 00:11:02,320 --> 00:11:04,780 and drove my actions is exactly the same kind of logic 232 00:11:04,780 --> 00:11:08,260 that you might feed to an actual computer, whether it is a PC or a Mac 233 00:11:08,260 --> 00:11:10,360 or an iPhone or Android phone. 234 00:11:10,360 --> 00:11:15,010 Because what computer programs tend to share in common, no matter the language 235 00:11:15,010 --> 00:11:18,070 they're written in, are things like functions and loops 236 00:11:18,070 --> 00:11:20,080 and conditions and Boolean expressions. 237 00:11:20,080 --> 00:11:25,030 And even more features still, things called variables and threads and events 238 00:11:25,030 --> 00:11:26,080 and even more features. 239 00:11:26,080 --> 00:11:28,660 And so that's what we'll do here in on out, 240 00:11:28,660 --> 00:11:31,300 is explore not just programming fundamentals, 241 00:11:31,300 --> 00:11:33,820 but explore some of these fundamentals in the context 242 00:11:33,820 --> 00:11:35,710 of some actual languages. 243 00:11:35,710 --> 00:11:38,620 First, one of the oldest languages someone might know, 244 00:11:38,620 --> 00:11:42,250 and we're not going to go with it as far back as FORTRAN and COBOL 245 00:11:42,250 --> 00:11:45,910 or binary or familiar, rather, we'll start with this one here. 246 00:11:45,910 --> 00:11:48,830 This is a small program, just a few lines of code, 247 00:11:48,830 --> 00:11:52,290 so to speak, written in an older language called C. 248 00:11:52,290 --> 00:11:55,270 A language that's still very much in use but it's older, 249 00:11:55,270 --> 00:11:57,722 in that it's been around for some decades now. 250 00:11:57,722 --> 00:11:59,680 And it doesn't tend to have that many features. 251 00:11:59,680 --> 00:12:03,100 But it's nonetheless a very powerful language, on top of which, so to speak, 252 00:12:03,100 --> 00:12:05,740 more recent, more modern languages have been built. 253 00:12:05,740 --> 00:12:08,290 It looks pretty cryptic, I'll grant you that. 254 00:12:08,290 --> 00:12:11,470 There's like, this hashtag over there and these angled brackets 255 00:12:11,470 --> 00:12:14,770 and curly braces, parentheses, semi-colon, backslash n 256 00:12:14,770 --> 00:12:17,740 and a few other syntactic curiosities. 257 00:12:17,740 --> 00:12:19,600 But what do all those mean? 258 00:12:19,600 --> 00:12:23,470 Well, even if unsure at first glance, like odds are you are, 259 00:12:23,470 --> 00:12:26,780 you can probably take a guess as to what this program does. 260 00:12:26,780 --> 00:12:30,190 Suppose I did write this program as such and then 261 00:12:30,190 --> 00:12:34,780 somehow ran this program on my Mac or PC or phone, what's it going to do? 262 00:12:34,780 --> 00:12:39,190 Probably, yeah, I mean, even if you don't recognize all the syntax-- 263 00:12:39,190 --> 00:12:42,320 I do recognize the word Print or Print-F, whatever that is. 264 00:12:42,320 --> 00:12:45,280 But printing I'm familiar with. 265 00:12:45,280 --> 00:12:47,360 And I do see a phrase here-- "hello, world," 266 00:12:47,360 --> 00:12:49,360 but I'm not quite sure what that backslash n is. 267 00:12:49,360 --> 00:12:53,970 So I'm going to guess this program, when run, is going to print hello, world. 268 00:12:53,970 --> 00:12:55,960 And indeed, that's what it does. 269 00:12:55,960 --> 00:12:57,490 There's a bit of overhead here. 270 00:12:57,490 --> 00:13:00,520 Not just syntactically, but sort of conceptually. 271 00:13:00,520 --> 00:13:04,120 Because you, as a programmer, need to understand, what does this line do? 272 00:13:04,120 --> 00:13:05,200 What does this line do? 273 00:13:05,200 --> 00:13:06,580 What do these curly braces mean? 274 00:13:06,580 --> 00:13:08,830 Why is there the backslash n there and so forth? 275 00:13:08,830 --> 00:13:10,900 But those are all just things that you learn. 276 00:13:10,900 --> 00:13:14,190 For instance, if you've not spoken Japanese 277 00:13:14,190 --> 00:13:18,130 as a language or Spanish, or any number of other languages, the very first time 278 00:13:18,130 --> 00:13:22,630 you look at that written language, it might look like Greek to you, 279 00:13:22,630 --> 00:13:23,470 so to speak. 280 00:13:23,470 --> 00:13:26,445 And might, indeed, be Greek if you don't speak Greek. 281 00:13:26,445 --> 00:13:29,320 But that's just because you haven't recognized those patterns before. 282 00:13:29,320 --> 00:13:31,414 You haven't recognized those symbols before. 283 00:13:31,414 --> 00:13:33,580 And indeed, if right now you're staring at something 284 00:13:33,580 --> 00:13:37,120 that's completely unfamiliar and while you do recognize some patterns, 285 00:13:37,120 --> 00:13:38,954 it's not all very straightforward, that's 286 00:13:38,954 --> 00:13:40,870 just because you don't yet speak the language. 287 00:13:40,870 --> 00:13:42,340 You don't yet know the language. 288 00:13:42,340 --> 00:13:45,670 You don't yet know how to program in this particular language. 289 00:13:45,670 --> 00:13:48,160 But what's exciting about programming in general 290 00:13:48,160 --> 00:13:52,540 is that even though there are dozens, if not hundreds, of programming languages, 291 00:13:52,540 --> 00:13:56,290 in use today, they're much more accessible, 292 00:13:56,290 --> 00:14:00,040 I dare say, than written and spoken human languages. 293 00:14:00,040 --> 00:14:03,490 Rather, you'll find many, many, many similarities among programming 294 00:14:03,490 --> 00:14:06,400 languages such that once you know one and a few, 295 00:14:06,400 --> 00:14:08,530 can you relatively easily bootstrap yourself, 296 00:14:08,530 --> 00:14:12,190 teach yourself other languages that might have newer and fancier features 297 00:14:12,190 --> 00:14:14,680 and then just, therefore, make you more productive? 298 00:14:14,680 --> 00:14:17,513 Because at the end of the day, that's what programming is all about. 299 00:14:17,513 --> 00:14:20,950 It's about writing software and therefore, controlling hardware with it 300 00:14:20,950 --> 00:14:22,940 to solve problems on your behalf. 301 00:14:22,940 --> 00:14:26,510 Whether that problem is to make a telephone call on a mobile device, 302 00:14:26,510 --> 00:14:29,590 whether that problem is to send an email or search for something 303 00:14:29,590 --> 00:14:32,620 on the internet, all of those problems are solved 304 00:14:32,620 --> 00:14:34,740 by controlling hardware with software. 305 00:14:34,740 --> 00:14:38,650 And the means by which you do that is by programming writing code 306 00:14:38,650 --> 00:14:42,790 like this, that ultimately runs on those devices. 307 00:14:42,790 --> 00:14:47,380 And yet-- and yet, I can't help but recall 308 00:14:47,380 --> 00:14:51,730 that the computers I know or grew up with, somehow or other, only 309 00:14:51,730 --> 00:14:54,190 understand zeros and ones, right? 310 00:14:54,190 --> 00:14:57,100 They only understand the so-called binary system. 311 00:14:57,100 --> 00:15:00,220 And yet, this does not quite look like zeros and ones. 312 00:15:00,220 --> 00:15:03,910 So how is it that I, who can just barely understand this as a human, 313 00:15:03,910 --> 00:15:07,060 can program a computer using this and have it understand this, 314 00:15:07,060 --> 00:15:09,560 even though these, themselves, are not zeros and ones? 315 00:15:09,560 --> 00:15:14,110 In other words, how do we get this to that instead? 316 00:15:14,110 --> 00:15:16,300 Well, it turns out when writing a computer program, 317 00:15:16,300 --> 00:15:17,874 there's often multiple steps. 318 00:15:17,874 --> 00:15:19,540 And sometimes these steps are automated. 319 00:15:19,540 --> 00:15:22,840 But sometimes you have to type, you have to make them happen manually. 320 00:15:22,840 --> 00:15:26,560 And in general, the process of converting this code 321 00:15:26,560 --> 00:15:30,580 here, or source code, which tends to be English-like syntax that 322 00:15:30,580 --> 00:15:35,530 does follow a set of standards and use a certain vocabulary, this being C, 323 00:15:35,530 --> 00:15:41,710 the language known as C, I can convert this source code to machine code, that 324 00:15:41,710 --> 00:15:45,310 is zeros and ones that look like this by running this source 325 00:15:45,310 --> 00:15:49,000 code through a special type of program quite simply called a Compiler. 326 00:15:49,000 --> 00:15:52,300 A compiler is simply a program that compiles code, 327 00:15:52,300 --> 00:15:56,830 converts it from source code to machine code so that the human can write it, 328 00:15:56,830 --> 00:16:00,960 but the machine can ultimately understand it. 329 00:16:00,960 --> 00:16:02,610 Consider another example here. 330 00:16:02,610 --> 00:16:07,740 This program looks almost kind of-- well, not really the same. 331 00:16:07,740 --> 00:16:10,819 But it's written in a very similar language called C++. 332 00:16:10,819 --> 00:16:13,860 Now, here too, you might not recognize some of the symbols on the screen. 333 00:16:13,860 --> 00:16:16,800 But you probably do recognize hello world, this time 334 00:16:16,800 --> 00:16:18,600 without the backslash n. 335 00:16:18,600 --> 00:16:22,980 And even though we have a different word up here, I/O stream and standard, endl 336 00:16:22,980 --> 00:16:26,940 here, odds are it's a pretty good bet that this program too 337 00:16:26,940 --> 00:16:28,110 does print hello world. 338 00:16:28,110 --> 00:16:31,260 And this is already, in simplest form, testament to the fact 339 00:16:31,260 --> 00:16:36,330 that many programming languages do the same things differently. 340 00:16:36,330 --> 00:16:41,670 Indeed, whether you know C or C++ or something like Java or PHP or Python 341 00:16:41,670 --> 00:16:44,100 or Ruby, or any number of other languages, odds are, 342 00:16:44,100 --> 00:16:47,700 at the end of the day, you can actually solve the same problems using any 343 00:16:47,700 --> 00:16:50,850 number of different languages, much like you, as a human, 344 00:16:50,850 --> 00:16:55,080 can express yourself verbally in any number of spoken languages. 345 00:16:55,080 --> 00:16:57,630 But it might just be easier to communicate 346 00:16:57,630 --> 00:16:59,880 with other humans in one language. 347 00:16:59,880 --> 00:17:02,220 It might just be easier and less time consuming 348 00:17:02,220 --> 00:17:05,577 to solve problems using one programming language over another. 349 00:17:05,577 --> 00:17:08,160 And this indeed, in part at least, explains why there are just 350 00:17:08,160 --> 00:17:09,450 so many programming languages. 351 00:17:09,450 --> 00:17:10,932 We've seen just two so far. 352 00:17:10,932 --> 00:17:12,390 But many different languages exist. 353 00:17:12,390 --> 00:17:14,973 Because as more and more time passes, and more and more humans 354 00:17:14,973 --> 00:17:18,150 use these languages, do they realize, wow, I could do this better. 355 00:17:18,150 --> 00:17:20,770 Or gee, I wish I had this feature instead or wow, 356 00:17:20,770 --> 00:17:24,210 I wish I could type fewer keys on the keyboard in order just 357 00:17:24,210 --> 00:17:26,520 to have my computer say hello world. 358 00:17:26,520 --> 00:17:29,550 And so you'll find that different languages do things differently 359 00:17:29,550 --> 00:17:31,710 even if the end result is the same. 360 00:17:31,710 --> 00:17:35,580 For instance, here is a language called Python. 361 00:17:35,580 --> 00:17:39,030 And thank God-- this is the simplest example of the ones 362 00:17:39,030 --> 00:17:42,000 we've seen thus far-- it really just says what it means. 363 00:17:42,000 --> 00:17:45,510 No hashtags up top, no curly braces, apparently. 364 00:17:45,510 --> 00:17:47,790 Just print hello world. 365 00:17:47,790 --> 00:17:51,270 And that's with this program in Python does. 366 00:17:51,270 --> 00:17:53,820 Now Python, it's worth noting, is a different type 367 00:17:53,820 --> 00:17:57,390 of language in most implementations. 368 00:17:57,390 --> 00:18:00,750 That is to say, you typically don't write Python source code 369 00:18:00,750 --> 00:18:04,410 and then manually convert it to machine code, zeros and ones. 370 00:18:04,410 --> 00:18:08,490 Rather, there is a special program that you use that's not called a compiler, 371 00:18:08,490 --> 00:18:10,200 but called an interpreter. 372 00:18:10,200 --> 00:18:13,110 Because what's also the case, with some languages, 373 00:18:13,110 --> 00:18:15,630 is that rather than convert them directly to zeros and ones, 374 00:18:15,630 --> 00:18:20,000 that your CPU, your computer's brain understands directly, 375 00:18:20,000 --> 00:18:23,370 you instead convert them to some intermediate language, generally known 376 00:18:23,370 --> 00:18:24,360 as bytecode. 377 00:18:24,360 --> 00:18:27,280 Java is the same way, as are some other languages. 378 00:18:27,280 --> 00:18:29,490 And so with Python, before running this, I 379 00:18:29,490 --> 00:18:34,290 might actually compile it or convert it to this much more 380 00:18:34,290 --> 00:18:35,670 cryptic-looking format. 381 00:18:35,670 --> 00:18:38,550 This is not code that I, myself, would particularly enjoy writing. 382 00:18:38,550 --> 00:18:42,330 But this is what's outputted when you write Python code. 383 00:18:42,330 --> 00:18:44,790 And it's outputted as something called bytecode. 384 00:18:44,790 --> 00:18:47,810 So this is just an intermediate format that still is somewhat readable. 385 00:18:47,810 --> 00:18:50,380 It's at least alphabetical characters and not zeros and ones. 386 00:18:50,380 --> 00:18:52,860 So as a human I kind of sort of can read it. 387 00:18:52,860 --> 00:18:55,180 But my computer can absolutely read this. 388 00:18:55,180 --> 00:18:58,830 Specifically, a program called an Interpreter on my computer, 389 00:18:58,830 --> 00:19:01,860 that, I could download to my Mac or PC or some other device 390 00:19:01,860 --> 00:19:04,660 can understand these lines one at a time. 391 00:19:04,660 --> 00:19:06,810 And so generally, a language like Python might 392 00:19:06,810 --> 00:19:10,800 again, be compiled to an intermediate language like this here, this bytecode. 393 00:19:10,800 --> 00:19:14,760 And then it's this code, ultimately, that's read by the machine. 394 00:19:14,760 --> 00:19:17,670 But the takeaway for us is really, quite simply, 395 00:19:17,670 --> 00:19:20,340 that there are different ways of doing the same thing 396 00:19:20,340 --> 00:19:21,750 in any number of languages. 397 00:19:21,750 --> 00:19:25,210 And even among those languages, do they get used in different ways? 398 00:19:25,210 --> 00:19:29,040 Sometimes you have to compile your code and then run the resulting machine 399 00:19:29,040 --> 00:19:31,410 code, the zeros and ones, by double clicking an icon 400 00:19:31,410 --> 00:19:32,940 or typing some command. 401 00:19:32,940 --> 00:19:36,420 Or might you be able to write your code and not explicitly compile 402 00:19:36,420 --> 00:19:38,190 it, just instead interpret it. 403 00:19:38,190 --> 00:19:40,320 The steps might feel or be a little different. 404 00:19:40,320 --> 00:19:44,850 But at the end of the day, most users experience the software 405 00:19:44,850 --> 00:19:47,400 in a familiar way, by double-clicking an icon 406 00:19:47,400 --> 00:19:49,290 by running in the name of a command. 407 00:19:49,290 --> 00:19:52,110 And for all intents and purposes, your users or your customers 408 00:19:52,110 --> 00:19:55,540 don't need to know or care what language something is written in, 409 00:19:55,540 --> 00:20:00,930 so long as it is created for your particular type of computer 410 00:20:00,930 --> 00:20:03,257 or your particular operating system. 411 00:20:03,257 --> 00:20:06,090 This is why, if you have a Mac, for instance, and a friend has a PC, 412 00:20:06,090 --> 00:20:10,680 you can't necessarily just share software and run the same programs 413 00:20:10,680 --> 00:20:11,816 on multiple computers. 414 00:20:11,816 --> 00:20:14,190 You might each have to buy or download different versions 415 00:20:14,190 --> 00:20:17,370 of the software, one of which is for Mac OS, one of which is for Windows. 416 00:20:17,370 --> 00:20:21,100 And even though those programs might be written in the same language, 417 00:20:21,100 --> 00:20:25,770 they generally have been compiled for or packaged for different computers, CPUs, 418 00:20:25,770 --> 00:20:28,170 or really, different operating systems. 419 00:20:28,170 --> 00:20:31,590 But this is just a decision that the software author, the software 420 00:20:31,590 --> 00:20:34,290 developer, or software engineer, so to speak, 421 00:20:34,290 --> 00:20:38,250 simply has to make on your behalf before shipping his or her software to you. 422 00:20:38,250 --> 00:20:39,540 What about other languages? 423 00:20:39,540 --> 00:20:41,040 This one here is Java. 424 00:20:41,040 --> 00:20:42,630 It too has some syntax of its own. 425 00:20:42,630 --> 00:20:45,690 But at the end of the day, it's going to do the same thing, 426 00:20:45,690 --> 00:20:48,690 print out the screen just hello world. 427 00:20:48,690 --> 00:20:50,820 This example here is another language called 428 00:20:50,820 --> 00:20:55,140 Ruby, which is commonly used as an alternative to some of these languages 429 00:20:55,140 --> 00:20:55,770 here as well. 430 00:20:55,770 --> 00:20:59,100 And it is even more simple syntactically, 431 00:20:59,100 --> 00:21:01,880 in the particular example, in that it's going to put or print 432 00:21:01,880 --> 00:21:04,790 on the screen, hello world as well. 433 00:21:04,790 --> 00:21:07,130 This one here is written in a language called LISP. 434 00:21:07,130 --> 00:21:09,440 The salient difference here being these parentheses 435 00:21:09,440 --> 00:21:12,354 on the outside, which are just hinting at a syntactic feature 436 00:21:12,354 --> 00:21:13,520 of this particular language. 437 00:21:13,520 --> 00:21:16,550 But this is quite simply how you might print hello world. 438 00:21:16,550 --> 00:21:18,810 And then in another language altogether, JavaScript 439 00:21:18,810 --> 00:21:23,720 is this how you might print hello world to the screen or browser window 440 00:21:23,720 --> 00:21:24,750 as well? 441 00:21:24,750 --> 00:21:28,640 Now, we've certainly only just scratched the surface of these several languages. 442 00:21:28,640 --> 00:21:30,830 And surely these languages can do much more. 443 00:21:30,830 --> 00:21:33,410 And odds are, it's going to take many more lines of code. 444 00:21:33,410 --> 00:21:36,830 But throughout each of these language are some commonalities, 445 00:21:36,830 --> 00:21:40,520 support for things like functions and loops 446 00:21:40,520 --> 00:21:43,310 and conditions and Boolean expressions, and maybe 447 00:21:43,310 --> 00:21:46,280 things like events and threads and variables and more. 448 00:21:46,280 --> 00:21:50,030 And so rather than get too much into the weeds of very specific languages, 449 00:21:50,030 --> 00:21:52,370 let's focus here on the ideas, and let's focus 450 00:21:52,370 --> 00:21:57,020 on these ideas as graphically and as pleasantly 451 00:21:57,020 --> 00:22:02,000 as we can by revisiting that first programming environment called Scratch. 452 00:22:02,000 --> 00:22:05,180 In particular, you'll recall that Scratch, just a moment ago, 453 00:22:05,180 --> 00:22:08,570 was raining trash down on my screen in synchronization 454 00:22:08,570 --> 00:22:11,810 with the old Sesame Street song that you might remember. 455 00:22:11,810 --> 00:22:13,850 But how was that program working? 456 00:22:13,850 --> 00:22:16,340 Well, consider how we might have gone about implementing 457 00:22:16,340 --> 00:22:18,380 some of these basic ideas. 458 00:22:18,380 --> 00:22:20,724 There was trash falling from the screen. 459 00:22:20,724 --> 00:22:22,640 But what does it mean to fall from the screen? 460 00:22:22,640 --> 00:22:26,180 Well, a screen, recall, is just a grid of dots, a grid of pixels, 461 00:22:26,180 --> 00:22:29,540 a bunch of pixels left-right, a bunch of pixels top-down. 462 00:22:29,540 --> 00:22:33,410 And so to move on the screen or to animate something on the screen really 463 00:22:33,410 --> 00:22:37,220 means just to take an image, whether it's a .png or .gif or .jpg or some 464 00:22:37,220 --> 00:22:40,610 other format and just move it slightly, slightly. 465 00:22:40,610 --> 00:22:43,470 Maybe one pixel downward at a time. 466 00:22:43,470 --> 00:22:48,080 And if you move that image downward one pixel at a time quickly enough, 467 00:22:48,080 --> 00:22:50,435 it doesn't look like some very jagged movement. 468 00:22:50,435 --> 00:22:54,290 It, to the human eyes, actually looks like a very clear movement. 469 00:22:54,290 --> 00:22:56,390 And so indeed what I was probably doing in order 470 00:22:56,390 --> 00:23:00,680 to make trash fall from the sky here is it started off screen. 471 00:23:00,680 --> 00:23:04,100 And then in some kind of loop, moved some number of pixels 472 00:23:04,100 --> 00:23:05,900 every second or every split second. 473 00:23:05,900 --> 00:23:07,580 And the result is some animation. 474 00:23:07,580 --> 00:23:10,400 Well, why does the trash, like the shoe and the piece of trash, 475 00:23:10,400 --> 00:23:12,920 actually stop at the bottom of the screen? 476 00:23:12,920 --> 00:23:16,700 Well, odds are, I could solve that problem with some kind of condition, 477 00:23:16,700 --> 00:23:18,680 some kind of logic or Boolean expression where 478 00:23:18,680 --> 00:23:23,930 I ask the computer if you're touching the bottom of the screen, sneaker, 479 00:23:23,930 --> 00:23:25,550 then stop moving. 480 00:23:25,550 --> 00:23:29,570 Or conversely, only if you're not touching the bottom of the screen, 481 00:23:29,570 --> 00:23:31,400 should you be moving top to bottom. 482 00:23:31,400 --> 00:23:33,740 So you can effectively stop the animation 483 00:23:33,740 --> 00:23:37,250 by just using some additional logic, and asking a question, 484 00:23:37,250 --> 00:23:39,900 are you at the bottom of the screen, yes or no? 485 00:23:39,900 --> 00:23:41,450 True or false? 486 00:23:41,450 --> 00:23:45,020 Meanwhile, every time I click and drag the piece of trash 487 00:23:45,020 --> 00:23:47,600 into the trashcan, what was happening while Oscar 488 00:23:47,600 --> 00:23:50,970 was emerging from his trash can, which was another form of animation 489 00:23:50,970 --> 00:23:51,650 altogether. 490 00:23:51,650 --> 00:23:53,720 But he was also shouting out, in a little cartoon 491 00:23:53,720 --> 00:23:57,680 bubble, the number of pieces of trash that I'd already deposited in his can, 492 00:23:57,680 --> 00:24:00,020 starting at one, then two, then three. 493 00:24:00,020 --> 00:24:02,120 Well, he would appear to be using something 494 00:24:02,120 --> 00:24:06,890 you might recall from algebra, being a variable like x or y or z. 495 00:24:06,890 --> 00:24:12,290 And this variable was probably initialized, or set initially to 0, 496 00:24:12,290 --> 00:24:14,090 because we'd put no pieces of trash. 497 00:24:14,090 --> 00:24:17,550 And every time Oscar received a new piece of trash, 498 00:24:17,550 --> 00:24:21,600 he probably incremented, or added 1, to that variable. 499 00:24:21,600 --> 00:24:25,296 So 0 becomes 1, which then becomes 2 or 3. 500 00:24:25,296 --> 00:24:26,920 Now, how did I increment that variable? 501 00:24:26,920 --> 00:24:29,730 Odds are, there is some kind of condition, 502 00:24:29,730 --> 00:24:34,100 saying if piece of trash added to trash can, then 503 00:24:34,100 --> 00:24:37,580 increase the variable's value by 1. 504 00:24:37,580 --> 00:24:41,550 If it's called x make x 1, then 2, than 3. 505 00:24:41,550 --> 00:24:43,272 So again, a basic building block. 506 00:24:43,272 --> 00:24:46,480 Now, there is more and more trash that would eventually fall from the screen. 507 00:24:46,480 --> 00:24:48,813 And my god, there's that song that I still can't get out 508 00:24:48,813 --> 00:24:50,600 of my head, 10 years later. 509 00:24:50,600 --> 00:24:54,500 But that, too, was playing on some kind of loop or some kind of synchronization 510 00:24:54,500 --> 00:24:55,790 with the game at hand. 511 00:24:55,790 --> 00:24:58,826 So even if, at first glance, this game seems pretty daunting. 512 00:24:58,826 --> 00:25:00,950 And you might think, that must have taken you like, 513 00:25:00,950 --> 00:25:02,510 what, David, eight hours? 514 00:25:02,510 --> 00:25:03,500 Well, that is true. 515 00:25:03,500 --> 00:25:04,970 It did take me at least that long. 516 00:25:04,970 --> 00:25:08,900 And I swear, by far the most challenging aspect of this game 517 00:25:08,900 --> 00:25:13,290 wasn't getting the logic right, but was getting that song in of and henceforth, 518 00:25:13,290 --> 00:25:14,880 never out of my head. 519 00:25:14,880 --> 00:25:20,000 But the key takeaway is, is that all of this seeming complexity, 520 00:25:20,000 --> 00:25:22,340 if you kind of zoom in and focus conceptually 521 00:25:22,340 --> 00:25:25,430 on just individual aspects of this game or this computer program, 522 00:25:25,430 --> 00:25:31,010 it can be reduced to just conditions and loops and variables 523 00:25:31,010 --> 00:25:32,412 and some basic building blocks. 524 00:25:32,412 --> 00:25:35,120 And I daresay, if you think about the software you, yourself, use 525 00:25:35,120 --> 00:25:39,200 every day on your phone, on your laptop or your desktop, odds are, 526 00:25:39,200 --> 00:25:42,380 even if you might have no idea how a browser is implemented 527 00:25:42,380 --> 00:25:45,650 or no idea how Excel or Word or Keynote or Numbers 528 00:25:45,650 --> 00:25:48,110 or any number of other programs are written, 529 00:25:48,110 --> 00:25:53,210 if you really focus on just small pieces of that software, individual features, 530 00:25:53,210 --> 00:25:59,200 could you probably start to glean exactly how the software developers who 531 00:25:59,200 --> 00:26:02,929 made the software actually implemented those features? 532 00:26:02,929 --> 00:26:05,470 So let's now break down Scratch into some of its fundamentals 533 00:26:05,470 --> 00:26:08,830 and start applying some of these very ideas. 534 00:26:08,830 --> 00:26:12,820 Here is perhaps the simplest of programs that you might 535 00:26:12,820 --> 00:26:15,130 implement with Scratch as a language. 536 00:26:15,130 --> 00:26:19,330 Surprise, surprise, this is how, in Scratch, you would say, hello world. 537 00:26:19,330 --> 00:26:23,380 Now, in the world of Scratch, you have a graphical environment 538 00:26:23,380 --> 00:26:26,851 where there is, as we'll soon see, a cat that actually performs all the action. 539 00:26:26,851 --> 00:26:30,100 So it's much like I, the human who was performing these actions with the phone 540 00:26:30,100 --> 00:26:33,070 book just a bit ago, in the world of Scratch, by default, 541 00:26:33,070 --> 00:26:38,115 is a cat going to perform any of the commands that you provide in software. 542 00:26:38,115 --> 00:26:39,740 We can change the cat to anything else. 543 00:26:39,740 --> 00:26:43,250 Indeed, I turned him into Oscar in that example. 544 00:26:43,250 --> 00:26:48,190 But this is what the commands themselves are going to look like. 545 00:26:48,190 --> 00:26:51,880 And Scratch, as we'll see, has a whole bunch of fundamentals. 546 00:26:51,880 --> 00:26:55,834 For instance, Scratch is going to have functions or actions or verbs that 547 00:26:55,834 --> 00:26:57,250 look a little something like this. 548 00:26:57,250 --> 00:27:00,250 This is a puzzle piece, purple in fact, that's 549 00:27:00,250 --> 00:27:03,620 going to specify that Scratch should say hello world. 550 00:27:03,620 --> 00:27:06,340 Here's another puzzle piece that, as you might guess, 551 00:27:06,340 --> 00:27:11,440 is going to tell Scratch to say hello world forever, again and again 552 00:27:11,440 --> 00:27:13,240 and again, in some kind of cycle. 553 00:27:13,240 --> 00:27:15,250 Meanwhile in Scratch, this is how you're going 554 00:27:15,250 --> 00:27:20,110 to repeat something a fixed or finite number of times, 50 in this case. 555 00:27:20,110 --> 00:27:22,540 This in Scratch, though a much bigger block, 556 00:27:22,540 --> 00:27:25,780 is how we're going to specify things conditionally. 557 00:27:25,780 --> 00:27:28,570 If x is less than y, then do the following. 558 00:27:28,570 --> 00:27:32,120 Else, if x is greater than y, do the following instead. 559 00:27:32,120 --> 00:27:38,660 Else, third fork in the road, do this, some other thing, altogether. 560 00:27:38,660 --> 00:27:40,750 And so indeed, you can really see in this example 561 00:27:40,750 --> 00:27:45,700 that Scratch, being graphical in nature, actually has you programming. 562 00:27:45,700 --> 00:27:48,250 Not by typing words alone on the keyboard 563 00:27:48,250 --> 00:27:52,450 and numbering your lines, as I did earlier with the phone book algorithm. 564 00:27:52,450 --> 00:27:58,120 But rather, putting together puzzle pieces whose shape kind of 565 00:27:58,120 --> 00:27:59,470 implies what they do. 566 00:27:59,470 --> 00:28:02,160 The fact that this if block kind of looks like this. 567 00:28:02,160 --> 00:28:04,600 And inside of that block you can put other blocks, 568 00:28:04,600 --> 00:28:08,350 apparently, implies that you should only say that x is less than y 569 00:28:08,350 --> 00:28:11,380 if it's inside of this if else block. 570 00:28:11,380 --> 00:28:14,290 And now, notice we have apparently crammed another if else block 571 00:28:14,290 --> 00:28:18,010 inside of this to effectively create a threw-way fork in the road. 572 00:28:18,010 --> 00:28:21,190 And in green here, do we see some Boolean expressions? 573 00:28:21,190 --> 00:28:25,560 Asking the question is x less than y or greater than y, in these two lines 574 00:28:25,560 --> 00:28:26,060 here. 575 00:28:26,060 --> 00:28:28,960 And then in orange we have variables, x and y themselves, 576 00:28:28,960 --> 00:28:30,790 which are probably just numbers. 577 00:28:30,790 --> 00:28:34,570 So how do we go about assembling all of these building blocks 578 00:28:34,570 --> 00:28:37,436 into actual programs written in this language called Scratch? 579 00:28:37,436 --> 00:28:39,810 Well, let's go ahead and run the Scratch software itself. 580 00:28:39,810 --> 00:28:42,035 Scratch is not only a programming language. 581 00:28:42,035 --> 00:28:43,785 It's also a whole programming environment. 582 00:28:43,785 --> 00:28:46,180 It's a piece of software unto itself that's 583 00:28:46,180 --> 00:28:50,440 going to allow us, by dragging and dropping these puzzle pieces, 584 00:28:50,440 --> 00:28:51,640 to program the computer. 585 00:28:51,640 --> 00:28:54,280 Well, let's take a look at the User Interface, or UI. 586 00:28:54,280 --> 00:28:56,860 At the top left here is Scratch himself. 587 00:28:56,860 --> 00:29:00,490 He lives in this two-dimensional world that has a height and has a width 588 00:29:00,490 --> 00:29:02,950 and currently, by default, has just this blank backdrop. 589 00:29:02,950 --> 00:29:05,650 And he can move up, down, left, right, and do many more things 590 00:29:05,650 --> 00:29:07,060 in that environment as well. 591 00:29:07,060 --> 00:29:08,710 What kinds of things can he do? 592 00:29:08,710 --> 00:29:10,780 Well, in the middle of this user interface 593 00:29:10,780 --> 00:29:14,590 do you see a whole bunch of palettes or categories, these being the scripts? 594 00:29:14,590 --> 00:29:17,680 And these blue blocks here all fall under the header of motion. 595 00:29:17,680 --> 00:29:19,720 So these are all puzzle pieces or blocks that 596 00:29:19,720 --> 00:29:21,641 somehow relate to Scratch's motion. 597 00:29:21,641 --> 00:29:24,640 Meanwhile, if we click through Costumes, we could change the aesthetics. 598 00:29:24,640 --> 00:29:27,790 And in fact, we could turn Scratch into a dog or to a grouch. 599 00:29:27,790 --> 00:29:32,200 And under the sounds tab, could we actually explore sounds and multimedia 600 00:29:32,200 --> 00:29:34,030 that we can integrate into Scratch? 601 00:29:34,030 --> 00:29:38,800 But the blank slate with which we begin is this big area over here 602 00:29:38,800 --> 00:29:42,550 on the right, to which I can drag and drop these puzzle pieces 603 00:29:42,550 --> 00:29:47,950 and actually interconnect them in order to instruct Scratch to do things. 604 00:29:47,950 --> 00:29:49,450 For instance, let's try. 605 00:29:49,450 --> 00:29:51,580 Now, I just know, from having used Scratch before, 606 00:29:51,580 --> 00:29:52,890 where some of these blocks are. 607 00:29:52,890 --> 00:29:55,600 And the first one I'm going to grab is under Events. 608 00:29:55,600 --> 00:29:58,870 And I'm going to click and drag and grab this one here, which 609 00:29:58,870 --> 00:30:01,009 is titled when green flag clicked. 610 00:30:01,009 --> 00:30:02,800 Because if you didn't notice before, notice 611 00:30:02,800 --> 00:30:05,980 now that above Scratch's two-dimensional world here 612 00:30:05,980 --> 00:30:08,950 is not only this blank background, but also this green flag 613 00:30:08,950 --> 00:30:12,850 and green, signifying go, and this red stop sign, signifying stop. 614 00:30:12,850 --> 00:30:16,600 And it's by clicking either of those buttons that I can start or stop. 615 00:30:16,600 --> 00:30:19,300 Respectively, any program here that I write. 616 00:30:19,300 --> 00:30:21,060 Very similar in spirit to double-clicking 617 00:30:21,060 --> 00:30:24,070 an icon on your desktop, or typing a command 618 00:30:24,070 --> 00:30:27,010 in a prompt on a typical computer. 619 00:30:27,010 --> 00:30:30,310 So meanwhile, I have now this when green flag clicked block. 620 00:30:30,310 --> 00:30:32,770 And I want Scratch to say something. 621 00:30:32,770 --> 00:30:36,130 Well, I know from having used Scratched before that the Say block happens 622 00:30:36,130 --> 00:30:39,710 to be under Looks, where a whole bunch of puzzle pieces are as well. 623 00:30:39,710 --> 00:30:42,850 And notice what I can do now is click on say hello, 624 00:30:42,850 --> 00:30:44,830 where hello is just the default word. 625 00:30:44,830 --> 00:30:49,240 And then notice here, if I drag, notice how it turns white and kind of glows 626 00:30:49,240 --> 00:30:52,060 when I move the block close enough, as though they're magnetized? 627 00:30:52,060 --> 00:30:55,780 Well, that's because these two blocks want to logically snap together. 628 00:30:55,780 --> 00:31:00,459 So as soon as I release my mouse button, will they lock together as such? 629 00:31:00,459 --> 00:31:02,500 And now I can double-click on the text box there, 630 00:31:02,500 --> 00:31:06,810 and type hello comma world, and actually type and any number of words 631 00:31:06,810 --> 00:31:08,640 that I might want Scratch to say. 632 00:31:08,640 --> 00:31:13,810 Well, let's zoom out, move my cursor over to the green flag and click. 633 00:31:13,810 --> 00:31:16,710 And voila, the first of my programs. 634 00:31:16,710 --> 00:31:18,390 It's doing exactly what I said. 635 00:31:18,390 --> 00:31:22,359 And if you notice, it's not stopping to say hello world anymore, 636 00:31:22,359 --> 00:31:24,150 because I never actually had a command that 637 00:31:24,150 --> 00:31:26,760 said hey, Scratch, stop saying hello. 638 00:31:26,760 --> 00:31:29,820 And so I'm just going to manually stop this program for now, 639 00:31:29,820 --> 00:31:31,825 with the red stop sign up there. 640 00:31:31,825 --> 00:31:33,450 All right, so that's all fine and good. 641 00:31:33,450 --> 00:31:35,820 But it's not all that realistic. 642 00:31:35,820 --> 00:31:38,490 Cats do not have speech bubbles coming out of their mouths. 643 00:31:38,490 --> 00:31:42,840 So let's make it a little more realistic by moving up here to my blocks, 644 00:31:42,840 --> 00:31:45,112 clicking and dragging and pulling away the Say block. 645 00:31:45,112 --> 00:31:47,070 And I can just let it go anywhere in the middle 646 00:31:47,070 --> 00:31:49,050 and it will just disappear or be deleted. 647 00:31:49,050 --> 00:31:53,040 And now this time let me go up to Sound. 648 00:31:53,040 --> 00:31:54,420 And oh, this is promising. 649 00:31:54,420 --> 00:31:57,064 Play sound meow is the purple block here. 650 00:31:57,064 --> 00:31:58,230 Let me go ahead and do this. 651 00:31:58,230 --> 00:32:00,300 And notice it too has a very similar shape, 652 00:32:00,300 --> 00:32:01,740 even though it's a little longer. 653 00:32:01,740 --> 00:32:04,724 And it wants to interconnect as soon as I let go. 654 00:32:04,724 --> 00:32:07,140 Let me go ahead and zoom out and click now the green flag. 655 00:32:07,140 --> 00:32:09,120 [MEOW] 656 00:32:09,120 --> 00:32:09,620 657 00:32:09,620 --> 00:32:10,612 Aw. 658 00:32:10,612 --> 00:32:11,610 [MEOW] 659 00:32:11,610 --> 00:32:13,112 Aw. 660 00:32:13,112 --> 00:32:14,540 [MEOW] 661 00:32:14,540 --> 00:32:15,900 Aw. 662 00:32:15,900 --> 00:32:18,010 So Scratch has just meowed three separate times 663 00:32:18,010 --> 00:32:22,510 because I ran the program three times by clicking on the green flag three times. 664 00:32:22,510 --> 00:32:23,830 Now, that's a little tedious. 665 00:32:23,830 --> 00:32:26,020 And it's also not very lifelike if every time I 666 00:32:26,020 --> 00:32:29,470 want to hear Scratch I have to breathe new life into him by clicking 667 00:32:29,470 --> 00:32:30,790 the green flag. 668 00:32:30,790 --> 00:32:33,160 Wouldn't this be an opportunity to leverage one 669 00:32:33,160 --> 00:32:37,570 of those principles we looked at already, that of a loop or a cycle, 670 00:32:37,570 --> 00:32:39,880 if I want Scratch to do something again and again? 671 00:32:39,880 --> 00:32:43,540 So for instance, let me go ahead and poke around under the control box, 672 00:32:43,540 --> 00:32:44,330 perhaps. 673 00:32:44,330 --> 00:32:46,120 And oh, there's that repeat block. 674 00:32:46,120 --> 00:32:49,130 It defaults to 10, but we can change that to anything I want. 675 00:32:49,130 --> 00:32:53,950 And if I click and drag here, now, this isn't quite right logically. 676 00:32:53,950 --> 00:32:56,560 Because I don't want to play the sound meow 677 00:32:56,560 --> 00:32:59,410 when the green flag is clicked and then repeat something 10 times. 678 00:32:59,410 --> 00:33:00,118 So you know what? 679 00:33:00,118 --> 00:33:02,950 I'm going to just leave this in no-man's land for just a moment. 680 00:33:02,950 --> 00:33:06,970 I'm going to click and drag this purple block away so it becomes detached. 681 00:33:06,970 --> 00:33:09,910 And now, notice, you might think that it definitely 682 00:33:09,910 --> 00:33:12,580 is not going to fit inside this repeat block that's just not 683 00:33:12,580 --> 00:33:13,730 too tall of a space. 684 00:33:13,730 --> 00:33:16,000 But notice that the whiteness is, in fact, 685 00:33:16,000 --> 00:33:18,250 illuminated, kind of saying yes, this is OK. 686 00:33:18,250 --> 00:33:20,290 And the shapes do kind of match. 687 00:33:20,290 --> 00:33:22,510 And so what's nice about Scratch is that so long 688 00:33:22,510 --> 00:33:26,110 as the shapes are in accordance, can you let go? 689 00:33:26,110 --> 00:33:28,970 And the containing block will grow to fill that particular shape. 690 00:33:28,970 --> 00:33:31,660 And even though it looks like we're now completely out of room 691 00:33:31,660 --> 00:33:33,400 within that Repeat block, we can actually 692 00:33:33,400 --> 00:33:37,600 drag and squeeze more and more blocks there, and the block will grow to fill. 693 00:33:37,600 --> 00:33:40,020 So let's just do this three times. 694 00:33:40,020 --> 00:33:44,230 And now let's go ahead and connect this to when the green flag clicked. 695 00:33:44,230 --> 00:33:46,960 Zoom out, click the green flag, and-- 696 00:33:46,960 --> 00:33:48,442 [MEOW] 697 00:33:48,442 --> 00:33:52,400 698 00:33:52,400 --> 00:33:53,780 Huh. 699 00:33:53,780 --> 00:33:57,440 Now, I am pretty sure logically this says when the green flag is clicked, 700 00:33:57,440 --> 00:33:59,420 repeat the following three times. 701 00:33:59,420 --> 00:34:01,190 Play sound, meow. 702 00:34:01,190 --> 00:34:07,280 And yet, unless I'm not hearing things right, I only heard one meow. 703 00:34:07,280 --> 00:34:08,480 So what's wrong? 704 00:34:08,480 --> 00:34:10,010 Is this a bug? 705 00:34:10,010 --> 00:34:11,270 A mistake in Scratch? 706 00:34:11,270 --> 00:34:13,130 Did MIT screw up? 707 00:34:13,130 --> 00:34:15,949 Or is this a bug in my code somehow? 708 00:34:15,949 --> 00:34:19,270 Did David screw up? 709 00:34:19,270 --> 00:34:21,810 Well, let's consider the options. 710 00:34:21,810 --> 00:34:26,719 Let me go back to that sound category, and see if there's maybe 711 00:34:26,719 --> 00:34:29,179 a different block I should be using. 712 00:34:29,179 --> 00:34:31,370 Now, I'm only just now reasoning through this. 713 00:34:31,370 --> 00:34:31,870 Right? 714 00:34:31,870 --> 00:34:34,670 Because I've written a program that I think should do one thing. 715 00:34:34,670 --> 00:34:37,620 I have realized it did not do what I intended. 716 00:34:37,620 --> 00:34:38,496 So is it my fault? 717 00:34:38,496 --> 00:34:39,620 Is it the software's fault? 718 00:34:39,620 --> 00:34:43,870 And maybe am I misunderstanding the functionality of some of these blocks? 719 00:34:43,870 --> 00:34:46,940 Now, what do you notice here? 720 00:34:46,940 --> 00:34:50,170 Scratch supports drumming, apparently, and other notes. 721 00:34:50,170 --> 00:34:53,239 But up above, it can play sound meow. 722 00:34:53,239 --> 00:34:59,420 Or more precisely, it can play sound meow until done. 723 00:34:59,420 --> 00:35:01,190 What happens if I use that one instead? 724 00:35:01,190 --> 00:35:01,910 Let me try. 725 00:35:01,910 --> 00:35:06,290 Let me go ahead and drag this one away to effectively delete it. 726 00:35:06,290 --> 00:35:10,572 And then drag this one in its place so it too still fits. 727 00:35:10,572 --> 00:35:12,530 Now, let me go ahead and click that green flag. 728 00:35:12,530 --> 00:35:15,860 [THREE MEOWS] 729 00:35:15,860 --> 00:35:16,700 Interesting. 730 00:35:16,700 --> 00:35:18,470 That time I did hear it all three times. 731 00:35:18,470 --> 00:35:19,310 Let's just be sure. 732 00:35:19,310 --> 00:35:22,410 [THREE MEOWS] 733 00:35:22,410 --> 00:35:23,420 OK. 734 00:35:23,420 --> 00:35:25,850 I definitely heard it all three times that time. 735 00:35:25,850 --> 00:35:26,870 But why? 736 00:35:26,870 --> 00:35:30,350 Well, with the previous version, which I'll restore here 737 00:35:30,350 --> 00:35:35,630 by going back to the way it is, notice that the program was actually 738 00:35:35,630 --> 00:35:38,090 performing correctly. 739 00:35:38,090 --> 00:35:40,610 Correctly, so far as the definition of these blocks go. 740 00:35:40,610 --> 00:35:44,510 Just incorrectly, with respect to my own expectations. 741 00:35:44,510 --> 00:35:46,500 Computers, recall, are really fast. 742 00:35:46,500 --> 00:35:47,000 Right? 743 00:35:47,000 --> 00:35:50,310 This Mac here might be a gigahertz or two gigahertz fast, 744 00:35:50,310 --> 00:35:53,630 which means it can do one or two billion things per second. 745 00:35:53,630 --> 00:35:54,590 And that's a lot. 746 00:35:54,590 --> 00:35:58,440 I mean, I am, by far, the limiting factor as the human in this equation. 747 00:35:58,440 --> 00:36:01,400 So maybe, just maybe, Scratch was literally 748 00:36:01,400 --> 00:36:05,180 doing what I told it to do which was when the green flag is clicked 749 00:36:05,180 --> 00:36:06,950 repeat the following three times 750 00:36:06,950 --> 00:36:09,740 But Scratch, being a computer program, is just so fast. 751 00:36:09,740 --> 00:36:13,010 It played the song or the sound three times. 752 00:36:13,010 --> 00:36:16,250 But it played it so fast within this Repeat block 753 00:36:16,250 --> 00:36:19,940 that all three of those meows were effectively overlapping. 754 00:36:19,940 --> 00:36:22,730 So we only heard one of them because all three 755 00:36:22,730 --> 00:36:25,070 were being played pretty much at the same time, 756 00:36:25,070 --> 00:36:27,470 because that loop was going around so quickly. 757 00:36:27,470 --> 00:36:32,570 But by contrast, with this other puzzle piece, play sound meow until done, 758 00:36:32,570 --> 00:36:36,200 now I'm compelling the program to just give me 759 00:36:36,200 --> 00:36:39,050 a moment to listen to the entirety of that sound 760 00:36:39,050 --> 00:36:42,650 before you proceed to the next iteration, or the next cycle. 761 00:36:42,650 --> 00:36:45,440 And then one more pause until the next cycle, 762 00:36:45,440 --> 00:36:49,820 so that I can hear it three and exactly three times. 763 00:36:49,820 --> 00:36:53,100 So such a simple program and such a simple example. 764 00:36:53,100 --> 00:36:55,610 And odds are, whenever you're writing code 765 00:36:55,610 --> 00:36:58,820 and it doesn't behave as you intend and you look at it and you think, 766 00:36:58,820 --> 00:37:00,693 no, that is right. 767 00:37:00,693 --> 00:37:03,570 Eh, that's not necessarily the case. 768 00:37:03,570 --> 00:37:06,680 And indeed, bugs, or mistakes in one's code, 769 00:37:06,680 --> 00:37:10,880 are going to be perhaps one of the most common and one 770 00:37:10,880 --> 00:37:15,816 of the most frustrating experiences one has when first learning to program. 771 00:37:15,816 --> 00:37:18,440 But these are the kinds of things that, with practice, go away. 772 00:37:18,440 --> 00:37:21,920 And so like I just did, you reach instinctively, here on out, 773 00:37:21,920 --> 00:37:25,760 for the right block, as opposed to the incorrect one. 774 00:37:25,760 --> 00:37:28,830 Now let's see what else we can do here when it comes to sound. 775 00:37:28,830 --> 00:37:32,970 What about not just playing a sound, but adding a bit of, 776 00:37:32,970 --> 00:37:34,700 shall we say, animation here? 777 00:37:34,700 --> 00:37:37,190 Well how might it go about making this cat moo? 778 00:37:37,190 --> 00:37:40,672 Well, let me go ahead under Control and do something forever. 779 00:37:40,672 --> 00:37:42,380 Because I just want this cat, ultimately, 780 00:37:42,380 --> 00:37:44,887 to move back and forth, back and forth forever. 781 00:37:44,887 --> 00:37:46,220 That of course, involves motion. 782 00:37:46,220 --> 00:37:47,434 So let me go to motion. 783 00:37:47,434 --> 00:37:49,100 And all right, I like the sound of this. 784 00:37:49,100 --> 00:37:51,200 Move 10 steps. 785 00:37:51,200 --> 00:37:55,280 And 10 steps is probably going to be 10 dots or 10 pixels on the screen. 786 00:37:55,280 --> 00:37:57,420 Well, then what do I want him to do? 787 00:37:57,420 --> 00:38:01,740 Well, let's see what happens first if I click the green flag. 788 00:38:01,740 --> 00:38:02,660 OK. 789 00:38:02,660 --> 00:38:04,490 So not quite what I intended. 790 00:38:04,490 --> 00:38:06,650 Because he's not really moving anymore. 791 00:38:06,650 --> 00:38:11,720 And this is actually a feature, being designed for aspiring programmers 792 00:38:11,720 --> 00:38:13,400 and not to mention, children. 793 00:38:13,400 --> 00:38:17,240 Scratch realized, or rather, MIT realized, that in designing Scratch, 794 00:38:17,240 --> 00:38:20,030 probably shouldn't let the cat go 100% off the screen. 795 00:38:20,030 --> 00:38:23,530 So we can just click and drag him back into view here if we want. 796 00:38:23,530 --> 00:38:25,740 But of course, program's still running. 797 00:38:25,740 --> 00:38:28,370 So he's just going to run away from us anyway. 798 00:38:28,370 --> 00:38:29,460 So how do we fix this? 799 00:38:29,460 --> 00:38:32,210 How do we make him go back and forth and back and forth without me 800 00:38:32,210 --> 00:38:33,570 having to manually intervene? 801 00:38:33,570 --> 00:38:35,900 Well, what about some kind of condition? 802 00:38:35,900 --> 00:38:39,260 Let me poke around the Control blocks. 803 00:38:39,260 --> 00:38:42,200 And let me actually grab one of these conditions. 804 00:38:42,200 --> 00:38:46,970 And instead of moving 10 steps forever again and again, 805 00:38:46,970 --> 00:38:50,630 after making 10 steps let me ask a question. 806 00:38:50,630 --> 00:38:52,220 Am I touching the edge? 807 00:38:52,220 --> 00:38:54,350 Because if so I don't want to keep going. 808 00:38:54,350 --> 00:38:58,100 So to ask that question, let me go under sensing here. 809 00:38:58,100 --> 00:38:59,510 And indeed, let's see. 810 00:38:59,510 --> 00:39:02,210 This one here, Touching, sounds about right. 811 00:39:02,210 --> 00:39:04,100 But I don't want this to have anything to do 812 00:39:04,100 --> 00:39:07,280 with the mouse pointer or the cursor, but rather, with the edge. 813 00:39:07,280 --> 00:39:11,440 So by this drop-down, let me change this Boolean expression to Touching Edge. 814 00:39:11,440 --> 00:39:12,650 Drag and drop this over here. 815 00:39:12,650 --> 00:39:16,610 And this certainly doesn't seem to fit size-wise, but shape-wise, it does. 816 00:39:16,610 --> 00:39:20,750 So if I let go, the block, as expected, grows to fill that particular Boolean 817 00:39:20,750 --> 00:39:21,500 expression. 818 00:39:21,500 --> 00:39:23,390 And now, what do I want to do? 819 00:39:23,390 --> 00:39:26,660 Well, now, maybe if I'm touching the edge, 820 00:39:26,660 --> 00:39:28,710 I should turn some number of degrees. 821 00:39:28,710 --> 00:39:29,960 15 doesn't feel quite right. 822 00:39:29,960 --> 00:39:31,430 I want to turn all the way around. 823 00:39:31,430 --> 00:39:35,810 And I know that to be 180 out of 360 total possible degrees. 824 00:39:35,810 --> 00:39:39,800 And now let's see what happens when I click the green flag. 825 00:39:39,800 --> 00:39:40,850 OK. 826 00:39:40,850 --> 00:39:41,545 So better. 827 00:39:41,545 --> 00:39:43,290 He's not just running off the screen. 828 00:39:43,290 --> 00:39:45,890 And now, I don't have to click and drag him back into view. 829 00:39:45,890 --> 00:39:51,227 But of course, turning 180 degrees isn't quite the visual I want. 830 00:39:51,227 --> 00:39:53,810 We don't really intend for the cat to be flipping upside down. 831 00:39:53,810 --> 00:39:55,890 So maybe there's a better way. 832 00:39:55,890 --> 00:40:00,177 This, definitely a bug aesthetically, but perhaps not functionally. 833 00:40:00,177 --> 00:40:01,760 But there's still an opportunity here. 834 00:40:01,760 --> 00:40:03,600 Let's leave that bug alone. 835 00:40:03,600 --> 00:40:06,360 Let's pause the program with the red stop sign here. 836 00:40:06,360 --> 00:40:08,330 Let me go into sounds, just for fun. 837 00:40:08,330 --> 00:40:11,180 It's hard to justify this academically here. 838 00:40:11,180 --> 00:40:13,770 But let me go into this sound bar, where you can hear-- 839 00:40:13,770 --> 00:40:14,270 [MEOW] 840 00:40:14,270 --> 00:40:18,080 --not just the default meow, But you can also click on the microphone. 841 00:40:18,080 --> 00:40:22,460 And let me go ahead and give my best example of cat 842 00:40:22,460 --> 00:40:25,740 running into the side of a screen. 843 00:40:25,740 --> 00:40:27,480 Ouch! 844 00:40:27,480 --> 00:40:28,470 And stop that. 845 00:40:28,470 --> 00:40:31,050 You can now see a waveform, or a graphical depiction 846 00:40:31,050 --> 00:40:33,090 of what my voice apparently sounds like. 847 00:40:33,090 --> 00:40:38,250 Let me go ahead and click and Delete the moments of silence beforehand and also 848 00:40:38,250 --> 00:40:39,330 a little after. 849 00:40:39,330 --> 00:40:42,179 And interestingly, it seems like I've really mustered some energy 850 00:40:42,179 --> 00:40:42,970 and then said ouch. 851 00:40:42,970 --> 00:40:45,400 But we'll leave the rest of the wave together. 852 00:40:45,400 --> 00:40:47,640 I'm going to go ahead and name this recording ouch. 853 00:40:47,640 --> 00:40:52,170 And now notice if I go back to Scripts, and I go to Sound, 854 00:40:52,170 --> 00:40:55,050 now ouch is available from the drop-down as one of my Sounds. 855 00:40:55,050 --> 00:40:59,010 And let me go ahead and put that not outside the condition, but inside. 856 00:40:59,010 --> 00:41:01,350 So that now, if I'm touching the edge, not only 857 00:41:01,350 --> 00:41:06,090 do I want to wrap around 180 degrees, I also want to play this sound. 858 00:41:06,090 --> 00:41:09,240 Let's see what my newest program now sounds like. 859 00:41:09,240 --> 00:41:10,510 Ouch! 860 00:41:10,510 --> 00:41:11,070 Ouch! 861 00:41:11,070 --> 00:41:11,810 OK. 862 00:41:11,810 --> 00:41:12,364 Ouch! 863 00:41:12,364 --> 00:41:13,530 OK, maybe not very cat-like. 864 00:41:13,530 --> 00:41:15,020 [OUCHING CONTINUES] 865 00:41:15,020 --> 00:41:18,810 A bit more like human hitting the edge of a screen, 866 00:41:18,810 --> 00:41:23,460 but at least correct, that 180-degree detail aside. 867 00:41:23,460 --> 00:41:26,460 So notice what's guided my building of this program. 868 00:41:26,460 --> 00:41:29,220 I didn't set out and drag all the possible puzzle pieces at once. 869 00:41:29,220 --> 00:41:31,320 I didn't record the sound in advance all at once. 870 00:41:31,320 --> 00:41:34,549 I instead took the proverbial baby steps, very small, 871 00:41:34,549 --> 00:41:36,840 incremental steps, starting with something very simple, 872 00:41:36,840 --> 00:41:38,970 just a forever loop, and just have the cat move 873 00:41:38,970 --> 00:41:40,604 all the way to the side of the screen. 874 00:41:40,604 --> 00:41:43,020 Then did I add to that the feature where he would actually 875 00:41:43,020 --> 00:41:46,500 wrap around conditionally, in the form of that If block. 876 00:41:46,500 --> 00:41:50,370 And then did I go in and add the third feature, which was this 877 00:41:50,370 --> 00:41:53,850 a silly human ouch-like sound. 878 00:41:53,850 --> 00:41:57,085 But the key takeaway there is that it's much easier, 879 00:41:57,085 --> 00:42:01,200 I'd argue, to write complex programs if you start off by breaking them down 880 00:42:01,200 --> 00:42:05,520 into those component parts and consider individual milestones for yourself, 881 00:42:05,520 --> 00:42:08,580 so how you might set out implementing just one feature at a time, 882 00:42:08,580 --> 00:42:09,780 as opposed to everything. 883 00:42:09,780 --> 00:42:12,738 And indeed, if you consider real-world software that use on your phones 884 00:42:12,738 --> 00:42:16,020 or your computers, certainly did Microsoft not set out to build, 885 00:42:16,020 --> 00:42:19,230 in one day, an entire word processing program 886 00:42:19,230 --> 00:42:22,320 called Word or an entire spreadsheet program called Excel. 887 00:42:22,320 --> 00:42:24,630 Odds are, their software developers back in the day, 888 00:42:24,630 --> 00:42:29,799 the very first version of the software, did they write just one small feature? 889 00:42:29,799 --> 00:42:31,590 Maybe you double-click the icon and it just 890 00:42:31,590 --> 00:42:34,092 opens a big rectangular window that does nothing, 891 00:42:34,092 --> 00:42:36,300 but at least they had the beginnings of the software. 892 00:42:36,300 --> 00:42:39,840 Then maybe they added support for just a column, maybe two columns, 893 00:42:39,840 --> 00:42:42,410 maybe any number of columns in any number of rows. 894 00:42:42,410 --> 00:42:45,150 And so there too, might Microsoft, among other companies, 895 00:42:45,150 --> 00:42:48,420 have set milestones for themselves such that the end result is 896 00:42:48,420 --> 00:42:50,560 impressive and amazingly complex. 897 00:42:50,560 --> 00:42:55,110 Maybe even millions of lines of code in C or C++ or Java, 898 00:42:55,110 --> 00:42:56,460 or some other language. 899 00:42:56,460 --> 00:42:59,637 But they didn't start out by trying to tackle that all at once. 900 00:42:59,637 --> 00:43:01,470 Just like I, when starting out this program, 901 00:43:01,470 --> 00:43:05,170 did not set out to implement it all at once. 902 00:43:05,170 --> 00:43:07,740 Now, with that said, let's open a couple of examples 903 00:43:07,740 --> 00:43:11,790 that have already been written and see what they do themselves. 904 00:43:11,790 --> 00:43:14,220 This, then, is Pet the Cat, a program I wrote 905 00:43:14,220 --> 00:43:16,830 in advance that still stars Scratch and already has 906 00:43:16,830 --> 00:43:19,290 these puzzle pieces assembled. 907 00:43:19,290 --> 00:43:20,340 So what does this do? 908 00:43:20,340 --> 00:43:22,090 Well, lets go about reading code, which is 909 00:43:22,090 --> 00:43:23,941 another side of software development. 910 00:43:23,941 --> 00:43:26,190 Most software programs, certainly the largest of them, 911 00:43:26,190 --> 00:43:28,890 are not written by single humans, but rather 912 00:43:28,890 --> 00:43:31,042 by teams of humans who are collaborating. 913 00:43:31,042 --> 00:43:33,750 Indeed, even though you might have the mindset or the expectation 914 00:43:33,750 --> 00:43:37,050 that programming is largely a solitary exercise done late 915 00:43:37,050 --> 00:43:41,850 at night with lots of caffeine and darkness and a flickering computer 916 00:43:41,850 --> 00:43:46,200 screen, the reality is it's an incredibly collaborative profession. 917 00:43:46,200 --> 00:43:51,930 It's an incredibly collaborative hobby, for some, whereby you work either 918 00:43:51,930 --> 00:43:54,657 alongside a whole team of individuals or remotely 919 00:43:54,657 --> 00:43:57,240 with a whole team of individuals collaborating at whiteboards, 920 00:43:57,240 --> 00:44:00,900 collaborating virtually, and ultimately reading each other's code. 921 00:44:00,900 --> 00:44:03,120 Not only to understand what someone else has written, 922 00:44:03,120 --> 00:44:05,910 but to enhance what he or she has done by building 923 00:44:05,910 --> 00:44:09,577 atop their own lives of code or in this case their own puzzle pieces. 924 00:44:09,577 --> 00:44:10,660 So let's try exactly that. 925 00:44:10,660 --> 00:44:13,312 And let's read this code that I've already written. 926 00:44:13,312 --> 00:44:14,520 When the green klag flicked-- 927 00:44:14,520 --> 00:44:15,780 [LAUGHS] 928 00:44:15,780 --> 00:44:19,050 When green flag clicked, forever do the following. 929 00:44:19,050 --> 00:44:22,500 If touching the mouse pointer, then play sound meow, 930 00:44:22,500 --> 00:44:27,880 and then wait for two seconds if touching mouse pointer, then play 931 00:44:27,880 --> 00:44:29,870 sound meow, then wait for two seconds. 932 00:44:29,870 --> 00:44:31,790 So what's this program going to do? 933 00:44:31,790 --> 00:44:34,050 Well, its title kind of gives it away. 934 00:44:34,050 --> 00:44:38,442 But if I click the green flag, nothing seems to be happening. 935 00:44:38,442 --> 00:44:40,400 But notice that all these puzzle pieces are now 936 00:44:40,400 --> 00:44:44,480 highlighted in yellow, to indicate that the program is indeed running. 937 00:44:44,480 --> 00:44:47,240 But nothing's happening until-- 938 00:44:47,240 --> 00:44:50,661 let me move my mouse pointer over the cat. 939 00:44:50,661 --> 00:44:51,623 [MEOW] 940 00:44:51,623 --> 00:44:53,070 Ah. 941 00:44:53,070 --> 00:44:55,310 Let's try that again. 942 00:44:55,310 --> 00:44:56,180 Interesting. 943 00:44:56,180 --> 00:44:59,230 So this time, rather than meowing forever, 944 00:44:59,230 --> 00:45:02,780 Scratch is only meowing when my mouse pointer is touching him, just 945 00:45:02,780 --> 00:45:03,401 like this. 946 00:45:03,401 --> 00:45:05,756 [TWO MEOWS] 947 00:45:05,756 --> 00:45:09,360 So this is kind of like the digital equivalent of petting the cat. 948 00:45:09,360 --> 00:45:11,060 Well, what about the opposite? 949 00:45:11,060 --> 00:45:15,740 What might it be like to write a program where you don't want to pet the cat? 950 00:45:15,740 --> 00:45:21,420 Well, for that example let's open Don't Pet the Cat, which now looks like this. 951 00:45:21,420 --> 00:45:23,480 So this program's a little more complicated 952 00:45:23,480 --> 00:45:25,970 in that it has not just an If block, which asks one 953 00:45:25,970 --> 00:45:29,300 question, but an If Else block, which asks a question 954 00:45:29,300 --> 00:45:32,900 and then behaves one way if it's true and another way if it's false. 955 00:45:32,900 --> 00:45:35,660 In this case, we forever if touching the mouse pointer, 956 00:45:35,660 --> 00:45:38,600 then play sound lion five-- 957 00:45:38,600 --> 00:45:40,730 so like the fifth of our lion sounds-- 958 00:45:40,730 --> 00:45:41,420 until done. 959 00:45:41,420 --> 00:45:45,620 Otherwise play sound meow, and then wait for two seconds 960 00:45:45,620 --> 00:45:48,050 to give the human a chance to sort of orient 961 00:45:48,050 --> 00:45:50,750 himself or herself and pet the cat again. 962 00:45:50,750 --> 00:45:52,280 So let's see what happens here. 963 00:45:52,280 --> 00:45:57,205 But consider that I've induced, this time, an infinite loop forever. 964 00:45:57,205 --> 00:46:00,276 [MEOWING] 965 00:46:00,276 --> 00:46:02,500 966 00:46:02,500 --> 00:46:03,250 Every two seconds. 967 00:46:03,250 --> 00:46:06,270 968 00:46:06,270 --> 00:46:08,200 What about not touching the cat? 969 00:46:08,200 --> 00:46:10,630 What was the imperative there? 970 00:46:10,630 --> 00:46:16,470 Let's try moving the cursor closer, closer. 971 00:46:16,470 --> 00:46:17,930 Closer. 972 00:46:17,930 --> 00:46:19,830 [LION ROARS] 973 00:46:19,830 --> 00:46:22,050 That is why you don't want to pet the cat. 974 00:46:22,050 --> 00:46:24,660 So in that case, did the lion sound only play 975 00:46:24,660 --> 00:46:28,020 when the cat was actually touched with the mouse pointer? 976 00:46:28,020 --> 00:46:29,280 Well, what about variables? 977 00:46:29,280 --> 00:46:31,350 What about programs in which you actually 978 00:46:31,350 --> 00:46:34,920 want to count something, as in the case of the sheep? 979 00:46:34,920 --> 00:46:38,760 Of course, in the human world it's often we humans who are doing the counting. 980 00:46:38,760 --> 00:46:42,480 But let me propose that it's sheep who deserve a chance to count themselves 981 00:46:42,480 --> 00:46:43,050 sometimes. 982 00:46:43,050 --> 00:46:47,160 And so here we have counting sheep. 983 00:46:47,160 --> 00:46:50,730 And indeed, this is literally a sheep counting. 984 00:46:50,730 --> 00:46:52,140 And how is he doing that? 985 00:46:52,140 --> 00:46:54,970 Well, over here, since I've already clicked the green flag, 986 00:46:54,970 --> 00:46:57,180 do you see highlighted the program that he's running? 987 00:46:57,180 --> 00:47:00,030 When green flag clicked, he said counter to zero. 988 00:47:00,030 --> 00:47:02,160 So this orange puzzle piece is like a custom piece 989 00:47:02,160 --> 00:47:04,950 that I made in advance via the Data Palette. 990 00:47:04,950 --> 00:47:09,450 And it allows me to create a variable called anything I want, x or y or z, 991 00:47:09,450 --> 00:47:12,270 or frankly, more descriptively in English, counter. 992 00:47:12,270 --> 00:47:15,030 Because what it is, I want a variable-- 993 00:47:15,030 --> 00:47:16,590 something that stores a value-- 994 00:47:16,590 --> 00:47:17,855 that does counting. 995 00:47:17,855 --> 00:47:20,730 I'm going to call it counter instead of the more generic x or y or z. 996 00:47:20,730 --> 00:47:22,688 And then I'm forever going to do the following. 997 00:47:22,688 --> 00:47:25,230 I'm going to say not hello world or some other phrase, 998 00:47:25,230 --> 00:47:27,570 but rather, the value of the counter. 999 00:47:27,570 --> 00:47:31,410 So I seem to have dragged and dropped the variable's puzzle piece right 1000 00:47:31,410 --> 00:47:33,480 on top of the Say block for one second. 1001 00:47:33,480 --> 00:47:35,176 Then I'm going to wait for a second. 1002 00:47:35,176 --> 00:47:37,050 Then I'm going to increment the counter by 1, 1003 00:47:37,050 --> 00:47:40,680 so change it by 1, by adding 1 to its value, 1004 00:47:40,680 --> 00:47:43,060 and then just keep doing this forever. 1005 00:47:43,060 --> 00:47:47,850 And so the sheep is now going to count up and up and up 1006 00:47:47,850 --> 00:47:50,940 and up and up, seemingly forever. 1007 00:47:50,940 --> 00:47:55,710 If that gets a little boring, I suppose we could always remove the weight block 1008 00:47:55,710 --> 00:47:59,620 and just have the sheep count again and again and again and again. 1009 00:47:59,620 --> 00:48:01,800 And so now there's no blinking effect. 1010 00:48:01,800 --> 00:48:03,790 Because the speech bubble isn't going away, 1011 00:48:03,790 --> 00:48:06,570 but the number's indeed counting a little faster. 1012 00:48:06,570 --> 00:48:09,630 Because we're saying it for one second at a time. 1013 00:48:09,630 --> 00:48:12,780 But it's one thing to use puzzle pieces that MIT 1014 00:48:12,780 --> 00:48:15,990 has created for us, these conditions, these loops, these variables. 1015 00:48:15,990 --> 00:48:18,930 What if my programs start to get sophisticated enough 1016 00:48:18,930 --> 00:48:22,170 and my ideas start to get grand enough that I'd really 1017 00:48:22,170 --> 00:48:24,720 like to start creating my own puzzle pieces, 1018 00:48:24,720 --> 00:48:28,760 puzzle pieces that maybe MIT didn't envision programmers needing? 1019 00:48:28,760 --> 00:48:32,790 Well, turns out in most programming languages you can do exactly this. 1020 00:48:32,790 --> 00:48:36,720 You can create your own custom functions or procedures 1021 00:48:36,720 --> 00:48:41,540 by assembling new functionality out of other existing puzzle pieces. 1022 00:48:41,540 --> 00:48:45,510 And so in this way, can we use existing puzzle pieces, kind of wrap them up 1023 00:48:45,510 --> 00:48:49,590 with a new name, with a new shape, and actually then give that shape a name 1024 00:48:49,590 --> 00:48:52,170 so that henceforth, I don't have to worry about using 1025 00:48:52,170 --> 00:48:53,940 all of those individual puzzle pieces. 1026 00:48:53,940 --> 00:48:57,750 I can use just one newly-named one to achieve some goal. 1027 00:48:57,750 --> 00:49:01,140 Let's consider the following example, cough 0. 1028 00:49:01,140 --> 00:49:04,110 This is an example, per the puzzle pieces up here, 1029 00:49:04,110 --> 00:49:06,300 that simply instruct the cat to cough three 1030 00:49:06,300 --> 00:49:08,130 times, waiting a second in between. 1031 00:49:08,130 --> 00:49:09,980 Say cough for a second, then wait. 1032 00:49:09,980 --> 00:49:11,616 Say cough for a second, then wait. 1033 00:49:11,616 --> 00:49:12,990 Say cough for a second then wait. 1034 00:49:12,990 --> 00:49:15,615 Of course, if I click green flag on here, you're going to see-- 1035 00:49:15,615 --> 00:49:16,740 as you might expect-- 1036 00:49:16,740 --> 00:49:20,620 the cat is unfortunately coughing not once, not twice, 1037 00:49:20,620 --> 00:49:22,620 but three times in total. 1038 00:49:22,620 --> 00:49:25,500 This is clearly an opportunity for better design. 1039 00:49:25,500 --> 00:49:32,850 And you can see the surface of an opportunity for better programming. 1040 00:49:32,850 --> 00:49:34,650 This is not a good design. 1041 00:49:34,650 --> 00:49:38,400 It's a correct design in that it will say cough three times 1042 00:49:38,400 --> 00:49:39,730 and wait a second in between. 1043 00:49:39,730 --> 00:49:42,146 But it's not a very good design because it kind of sort of 1044 00:49:42,146 --> 00:49:44,880 looks like I copied and pasted these puzzle pieces, much 1045 00:49:44,880 --> 00:49:47,580 like you might do with your own processing program or email 1046 00:49:47,580 --> 00:49:48,690 client or the like. 1047 00:49:48,690 --> 00:49:52,122 I've just taken a couple of puzzle pieces and said, copy, paste, paste. 1048 00:49:52,122 --> 00:49:53,830 And maybe I'd do it even more if I wanted 1049 00:49:53,830 --> 00:49:56,130 Scratch to cough more than three times. 1050 00:49:56,130 --> 00:49:58,200 But we can do better than that with programming. 1051 00:49:58,200 --> 00:50:00,240 We can use loops instead. 1052 00:50:00,240 --> 00:50:04,350 So in cough one do we have an alternative example, 1053 00:50:04,350 --> 00:50:06,600 wherein the cat now is going to cough three times, 1054 00:50:06,600 --> 00:50:10,480 but by way of a repeat block, a loop. 1055 00:50:10,480 --> 00:50:12,390 Now, the code is functionally the same. 1056 00:50:12,390 --> 00:50:15,350 But this would be arguably better designed. 1057 00:50:15,350 --> 00:50:18,600 Because now if I want to change what the cat is saying, or when he's coughing, 1058 00:50:18,600 --> 00:50:20,190 maybe I want to spell it differently. 1059 00:50:20,190 --> 00:50:23,410 Or I want him to wait some number of seconds that aren't just one. 1060 00:50:23,410 --> 00:50:25,980 Well, I can just make a change in one place 1061 00:50:25,980 --> 00:50:28,620 rather than in like, six different puzzle pieces. 1062 00:50:28,620 --> 00:50:32,100 I can focus on just the one instance here. 1063 00:50:32,100 --> 00:50:36,570 But suppose that it's coughing that is the puzzle piece that I 1064 00:50:36,570 --> 00:50:39,780 want to create and use here on out, so I don't 1065 00:50:39,780 --> 00:50:41,760 have to remember that that is how you make 1066 00:50:41,760 --> 00:50:44,190 a sprite, a character on the screen, cough. 1067 00:50:44,190 --> 00:50:46,290 Because in addition to having one cat like this, 1068 00:50:46,290 --> 00:50:49,134 we can actually have multiple cats, or a cat and a dog or a cat 1069 00:50:49,134 --> 00:50:51,550 and a dog and a grouch, or any number of other characters. 1070 00:50:51,550 --> 00:50:54,390 So this is to say, it would be nice, once I figure out 1071 00:50:54,390 --> 00:50:57,120 how to do something in a programming language like Scratch, 1072 00:50:57,120 --> 00:51:01,080 I'd really like to save that functionality in a custom function, 1073 00:51:01,080 --> 00:51:03,960 in a puzzle piece that I have made so I can use it elsewhere. 1074 00:51:03,960 --> 00:51:06,720 Not just for this sprite or cat, but for others. 1075 00:51:06,720 --> 00:51:13,410 So in cough two do we now have an example that defines 1076 00:51:13,410 --> 00:51:15,390 a new puzzle piece called cough? 1077 00:51:15,390 --> 00:51:16,860 It's purple in nature. 1078 00:51:16,860 --> 00:51:19,184 I grabbed it from the More Blocks Palette. 1079 00:51:19,184 --> 00:51:21,600 And you'll notice that I defined, with this special puzzle 1080 00:51:21,600 --> 00:51:25,080 piece, a new piece called cough. 1081 00:51:25,080 --> 00:51:27,990 Beneath that block is a number of statements. 1082 00:51:27,990 --> 00:51:32,010 Say cough for one second, wait for one second, and that's it. 1083 00:51:32,010 --> 00:51:34,690 But now, above this is my new program. 1084 00:51:34,690 --> 00:51:36,690 And this is where things get really interesting. 1085 00:51:36,690 --> 00:51:39,360 Because now I can drag and drop when green flag clicked. 1086 00:51:39,360 --> 00:51:42,810 I can still grab a Repeat block and do something three times. 1087 00:51:42,810 --> 00:51:44,610 But what do I want to do three times? 1088 00:51:44,610 --> 00:51:47,970 This time I just very simply want to cough. 1089 00:51:47,970 --> 00:51:51,750 And so now, thanks to my Custom puzzle piece being defined here, 1090 00:51:51,750 --> 00:51:52,950 I now have access-- 1091 00:51:52,950 --> 00:51:57,570 under More Blocks-- to a custom puzzle piece called cough that not only says 1092 00:51:57,570 --> 00:51:58,600 what it means-- 1093 00:51:58,600 --> 00:52:00,570 which is nice and descriptive and easy to use-- 1094 00:52:00,570 --> 00:52:03,840 it also hides or, so to speak, abstracts away 1095 00:52:03,840 --> 00:52:08,370 all of the underlying implementation details or the complexity, relatively 1096 00:52:08,370 --> 00:52:09,930 speaking, of what it means to cough. 1097 00:52:09,930 --> 00:52:12,600 So that all I or a friend who is using this puzzle piece 1098 00:52:12,600 --> 00:52:15,840 has to worry about here on out is that the puzzle piece is called cough. 1099 00:52:15,840 --> 00:52:19,380 Does not matter how it's actually implemented. 1100 00:52:19,380 --> 00:52:21,480 And it turns out that in programming languages, 1101 00:52:21,480 --> 00:52:26,220 just like Scratch, you can make one additional improvement on this. 1102 00:52:26,220 --> 00:52:30,380 Rather than have to rely on your own repeat block, 1103 00:52:30,380 --> 00:52:32,130 notice what else you can do. 1104 00:52:32,130 --> 00:52:35,940 In this case, I've refined my implementation of this custom puzzle 1105 00:52:35,940 --> 00:52:39,600 piece, cough, to take what we'll call and what a programmer would call 1106 00:52:39,600 --> 00:52:42,900 an argument or a parameter, some number of inputs 1107 00:52:42,900 --> 00:52:45,270 that influence the behavior of the puzzle piece. 1108 00:52:45,270 --> 00:52:48,900 Now, we've seen arguments or inputs all over the place thus far. 1109 00:52:48,900 --> 00:52:50,670 Move some number of steps. 1110 00:52:50,670 --> 00:52:52,320 That's an argument or a parameter. 1111 00:52:52,320 --> 00:52:53,326 Say something. 1112 00:52:53,326 --> 00:52:55,200 That's an argument or a parameter, because it 1113 00:52:55,200 --> 00:53:00,070 influences the behavior of the Moo block or the Say block, respectively. 1114 00:53:00,070 --> 00:53:01,180 So how do I do that? 1115 00:53:01,180 --> 00:53:03,480 How do I make a cough puzzle piece that doesn't just 1116 00:53:03,480 --> 00:53:07,320 cough once, but coughs 2 times, 3 times, 10 times, 1117 00:53:07,320 --> 00:53:10,740 however many times the user of that puzzle piece wants? 1118 00:53:10,740 --> 00:53:13,060 Well, would use the puzzle piece like this. 1119 00:53:13,060 --> 00:53:16,260 And notice there's now a little white box where I can type a number. 1120 00:53:16,260 --> 00:53:20,070 But it turns out you can parameterize your own custom functions 1121 00:53:20,070 --> 00:53:22,830 by using a special puzzle piece like this, that has not just 1122 00:53:22,830 --> 00:53:25,950 the name of your custom function, but also 1123 00:53:25,950 --> 00:53:28,200 a placeholder for a variable, really. 1124 00:53:28,200 --> 00:53:33,720 A variable being another way of thinking about a parameter or argument. 1125 00:53:33,720 --> 00:53:36,870 And so what I've done with n-- and I'm just calling it n for number, 1126 00:53:36,870 --> 00:53:40,620 but I could have called it anything I want, x, y, or z or something else. 1127 00:53:40,620 --> 00:53:45,150 I can now repeat in the implementation of cough that many times. 1128 00:53:45,150 --> 00:53:46,980 I don't have to hard code 3 anymore. 1129 00:53:46,980 --> 00:53:48,540 I don't have to hard code any number. 1130 00:53:48,540 --> 00:53:51,660 I can drag and drop a copy of n here. 1131 00:53:51,660 --> 00:53:56,580 So that whatever number the user of my puzzle piece types in, 1132 00:53:56,580 --> 00:53:58,800 that's what will be used for the Repeat block. 1133 00:53:58,800 --> 00:54:01,170 And that's how many times this puzzle piece 1134 00:54:01,170 --> 00:54:05,130 will say cough and wait one second. 1135 00:54:05,130 --> 00:54:08,970 And so this now is just a small example of what it's really 1136 00:54:08,970 --> 00:54:11,190 like to program and solve problems. 1137 00:54:11,190 --> 00:54:13,320 The problem, to be fair, is relatively small here, 1138 00:54:13,320 --> 00:54:16,890 in that we just want the cat to cough visually on the screen. 1139 00:54:16,890 --> 00:54:19,470 But the opportunities that problem affords really 1140 00:54:19,470 --> 00:54:21,260 are captured in these several examples. 1141 00:54:21,260 --> 00:54:23,490 With these examples, do you see me starting out 1142 00:54:23,490 --> 00:54:26,154 in the simplest, most naive and correct way possible? 1143 00:54:26,154 --> 00:54:28,320 But it wasn't very well designed, because I was just 1144 00:54:28,320 --> 00:54:31,442 kind of duplicating the Say block and the Wait block 1145 00:54:31,442 --> 00:54:33,150 and then the Say block and the Wait block 1146 00:54:33,150 --> 00:54:34,200 and the Say block and the Wait block. 1147 00:54:34,200 --> 00:54:35,910 It's just, it already sounds tedious. 1148 00:54:35,910 --> 00:54:37,565 And indeed, it's poor form. 1149 00:54:37,565 --> 00:54:39,690 But then I factored that out with the repeat block. 1150 00:54:39,690 --> 00:54:43,410 And then I introduced a custom puzzle piece whose second version 1151 00:54:43,410 --> 00:54:45,660 also allowed me to parameterize it. 1152 00:54:45,660 --> 00:54:50,310 And so the fun in programming, and the opportunities 1153 00:54:50,310 --> 00:54:55,140 to become a better programmer are illuminated with examples like this. 1154 00:54:55,140 --> 00:54:58,290 To be good at programming is to notice opportunities like this, 1155 00:54:58,290 --> 00:55:00,360 to actually take opportunities like this, 1156 00:55:00,360 --> 00:55:05,880 to factor certain common code out, to abstract it away or bundle it inside 1157 00:55:05,880 --> 00:55:09,220 of custom puzzle pieces or black boxes, so to speak, 1158 00:55:09,220 --> 00:55:13,020 is what's evidence, generally, of not just correct code, 1159 00:55:13,020 --> 00:55:16,800 but good design and well-designed code. 1160 00:55:16,800 --> 00:55:19,749 Now, these are just a few of the features you might see in a language. 1161 00:55:19,749 --> 00:55:21,290 There are certainly a few others too. 1162 00:55:21,290 --> 00:55:24,810 Let me go ahead and open up an example here called Thread. 1163 00:55:24,810 --> 00:55:29,040 And you'll see, as promised, Scratch's support for multiple sprites, 1164 00:55:29,040 --> 00:55:30,364 multiple characters. 1165 00:55:30,364 --> 00:55:31,530 And this is the funny thing. 1166 00:55:31,530 --> 00:55:36,150 Because thus far, almost all of our programs or indeed, 1167 00:55:36,150 --> 00:55:40,140 all of our programs, have had just one cat or one sprite, and therefore, 1168 00:55:40,140 --> 00:55:42,330 really one thread, as we'll call it. 1169 00:55:42,330 --> 00:55:44,490 They're only doing one thing at a time. 1170 00:55:44,490 --> 00:55:47,340 With this example, per the cat and the bird, 1171 00:55:47,340 --> 00:55:49,320 this example will actually have two things 1172 00:55:49,320 --> 00:55:51,160 happening at once simultaneously. 1173 00:55:51,160 --> 00:55:54,340 And there's some kind of interrelation between them. 1174 00:55:54,340 --> 00:55:57,450 Notice that the cat is kind of stealthily, 1175 00:55:57,450 --> 00:56:00,960 and very predictably, following the bird. 1176 00:56:00,960 --> 00:56:02,130 This is not random. 1177 00:56:02,130 --> 00:56:05,040 But oh, no, please, getting-- 1178 00:56:05,040 --> 00:56:06,430 [LIONS ROARS] 1179 00:56:06,430 --> 00:56:07,480 1180 00:56:07,480 --> 00:56:09,610 Not exactly what we were hoping for there. 1181 00:56:09,610 --> 00:56:14,110 So there was clearly some kind of interaction or dependency there. 1182 00:56:14,110 --> 00:56:15,500 So what was going on? 1183 00:56:15,500 --> 00:56:19,000 Well, notice that the bird is highlighted in the bottom left, 1184 00:56:19,000 --> 00:56:21,020 as has been our cat previously. 1185 00:56:21,020 --> 00:56:25,090 And so this, at top right, is the program driving the bird's behavior. 1186 00:56:25,090 --> 00:56:28,830 When the green flag was clicked it went to negative 150 and positive 150. 1187 00:56:28,830 --> 00:56:33,730 It turns out that blank world in which Scratch lives can 1188 00:56:33,730 --> 00:56:36,790 be addressed with coordinates, x and y. 1189 00:56:36,790 --> 00:56:38,530 So some number of pixels left or right. 1190 00:56:38,530 --> 00:56:40,090 Some number of pixels top and bottom. 1191 00:56:40,090 --> 00:56:43,510 And I just decided arbitrarily to start it at negative 150, 50 1192 00:56:43,510 --> 00:56:44,710 with some trial and error. 1193 00:56:44,710 --> 00:56:46,990 I then had it then point in a 45-degree angle, 1194 00:56:46,990 --> 00:56:49,170 just because it starts off in an interesting way. 1195 00:56:49,170 --> 00:56:52,300 And then I forever told the bird do the following-- 1196 00:56:52,300 --> 00:56:57,070 if not touching the cat, the other sprite, then move three steps. 1197 00:56:57,070 --> 00:56:58,480 And if on edge, bounce. 1198 00:56:58,480 --> 00:57:02,710 Which is a nice one-line version, one single-puzzle-piece version of the if 1199 00:57:02,710 --> 00:57:06,560 construct we did earlier where bounce means turn 180 degrees. 1200 00:57:06,560 --> 00:57:08,770 But I've used a puzzle piece that comes with Scratch 1201 00:57:08,770 --> 00:57:10,670 to achieve the same result. 1202 00:57:10,670 --> 00:57:12,280 So that's it. 1203 00:57:12,280 --> 00:57:15,724 If the bird is not touching the cat, then just move three steps. 1204 00:57:15,724 --> 00:57:17,140 And if you're on the edge, bounce. 1205 00:57:17,140 --> 00:57:18,460 So just keep bouncing around. 1206 00:57:18,460 --> 00:57:19,230 Just keep moving. 1207 00:57:19,230 --> 00:57:23,800 So the bird doesn't put all that much thought into what it's doing. 1208 00:57:23,800 --> 00:57:26,500 The cat, meanwhile, is kind of clever. 1209 00:57:26,500 --> 00:57:30,630 The cat, when the green flag is clicked, goes to negative 160, negative 160. 1210 00:57:30,630 --> 00:57:33,830 So I made sure that they don't start too close to one another. 1211 00:57:33,830 --> 00:57:35,770 I then have them point in a random direction. 1212 00:57:35,770 --> 00:57:39,010 Scratch, like a lot of languages, supports random or pseudo 1213 00:57:39,010 --> 00:57:39,760 random numbers. 1214 00:57:39,760 --> 00:57:44,240 Where just like a human can pick a number, like 50, that's sort of random, 1215 00:57:44,240 --> 00:57:48,300 so can a computer pick a number between 91 and 179. 1216 00:57:48,300 --> 00:57:52,890 And that, you might notice, is between essentially a 90-degree window. 1217 00:57:52,890 --> 00:57:55,480 And just because I wanted the cat to at least start off 1218 00:57:55,480 --> 00:57:57,430 at some range of angles. 1219 00:57:57,430 --> 00:58:00,220 Then I wanted the cat forever to do the following. 1220 00:58:00,220 --> 00:58:04,330 If you're touching the bird, place sound lion 4 this time. 1221 00:58:04,330 --> 00:58:05,467 Then stop this script. 1222 00:58:05,467 --> 00:58:07,300 So I wanted to make sure that the cat didn't 1223 00:58:07,300 --> 00:58:10,210 keep moving if it touched the bird. 1224 00:58:10,210 --> 00:58:13,310 I wanted the game just to stop or the animation to stop. 1225 00:58:13,310 --> 00:58:15,910 And so I explicitly say stop, so that the human doesn't 1226 00:58:15,910 --> 00:58:18,790 have to click the red stop sign. 1227 00:58:18,790 --> 00:58:20,560 But then here's the cleverness. 1228 00:58:20,560 --> 00:58:25,810 Forever point toward the bird and move one step. 1229 00:58:25,810 --> 00:58:28,022 So the cat has this very stealthy advantage 1230 00:58:28,022 --> 00:58:29,980 that no matter where the bird is, and remember, 1231 00:58:29,980 --> 00:58:33,100 the bird is kind of bouncing all every which way, 1232 00:58:33,100 --> 00:58:41,560 bouncing randomly off the walls, ultimately, the cat 1233 00:58:41,560 --> 00:58:45,160 is slowly but surely tracking the bird by always pointing toward it 1234 00:58:45,160 --> 00:58:46,480 and moving one step. 1235 00:58:46,480 --> 00:58:49,480 And so even as the bird is sort of aimlessly flying around, 1236 00:58:49,480 --> 00:58:54,250 the cat is very slowly but very methodically, very algorithmically, 1237 00:58:54,250 --> 00:58:56,530 if you will, pointing itself toward the cat. 1238 00:58:56,530 --> 00:59:00,820 So if we rerun this program, you'll see the cat's indeed 1239 00:59:00,820 --> 00:59:03,280 exercising exactly that logic. 1240 00:59:03,280 --> 00:59:05,130 And the bird's kind of getting away. 1241 00:59:05,130 --> 00:59:07,960 But again, the cat is pivoting to follow him. 1242 00:59:07,960 --> 00:59:10,390 And he keeps going and keeps going and keeps going. 1243 00:59:10,390 --> 00:59:12,250 And we'll again find him right-- 1244 00:59:12,250 --> 00:59:13,300 [LION ROARS] 1245 00:59:13,300 --> 00:59:14,110 There. 1246 00:59:14,110 --> 00:59:17,920 Now, we could give maybe the bird a bit more of an advantage. 1247 00:59:17,920 --> 00:59:19,660 Let me go ahead and click on the bird. 1248 00:59:19,660 --> 00:59:21,730 And how about instead of moving three steps, 1249 00:59:21,730 --> 00:59:24,760 let me have him move six steps, twice as fast? 1250 00:59:24,760 --> 00:59:27,250 Click the green flag. 1251 00:59:27,250 --> 00:59:28,660 Very nice. 1252 00:59:28,660 --> 00:59:31,100 So the cat is still moving at the same rate. 1253 00:59:31,100 --> 00:59:33,700 Unfortunately, it's still moving toward the bird. 1254 00:59:33,700 --> 00:59:36,110 And the bird is not taking that into account. 1255 00:59:36,110 --> 00:59:39,490 We could give the advantage to the cat instead. 1256 00:59:39,490 --> 00:59:42,700 So if I go back to the cat script and instead of moving one step, 1257 00:59:42,700 --> 00:59:46,000 how about 10 steps, and let's see what happens now. 1258 00:59:46,000 --> 00:59:47,360 [ROARS] 1259 00:59:47,360 --> 00:59:49,480 Cat pretty much seeks out the bird. 1260 00:59:49,480 --> 00:59:52,130 A bird-seeking cat. 1261 00:59:52,130 --> 00:59:56,500 How about one more example that speaks to the height 1262 00:59:56,500 --> 00:59:59,560 of the ceiling with an environment like Scratch, just how much 1263 00:59:59,560 --> 01:00:02,230 you can do using some basic fundamentals. 1264 01:00:02,230 --> 01:00:05,890 This time we have a couple of our puppets here to star. 1265 01:00:05,890 --> 01:00:08,500 Notice one is blue, one is orange. 1266 01:00:08,500 --> 01:00:13,630 And one is called playing Marco Polo, it would seem, if familiar. 1267 01:00:13,630 --> 01:00:17,170 This is a game that kids might play whereby if one person says Marco, 1268 01:00:17,170 --> 01:00:18,940 the other kids are supposed to say Polo. 1269 01:00:18,940 --> 01:00:22,360 And then one is supposed to find the other in that particular game. 1270 01:00:22,360 --> 01:00:27,250 But we're just using it as an example of something called Events. 1271 01:00:27,250 --> 01:00:30,550 So it turns out, per the last example, that a computer can effectively 1272 01:00:30,550 --> 01:00:33,970 do multiple things at a time, thanks to multithreading, 1273 01:00:33,970 --> 01:00:37,120 where a thread is an independent thread, so to speak, 1274 01:00:37,120 --> 01:00:40,750 of execution, that is happening in parallel with something 1275 01:00:40,750 --> 01:00:41,650 else on the computer. 1276 01:00:41,650 --> 01:00:45,190 And especially nowadays, now that computers have multiple cores or CPUs, 1277 01:00:45,190 --> 01:00:47,260 they can literally do multiple things at once. 1278 01:00:47,260 --> 01:00:51,220 And even if they can't, computers are so much faster than use humans 1279 01:00:51,220 --> 01:00:55,091 that even if the cat and bird aren't technically moving at the same time, 1280 01:00:55,091 --> 01:00:58,090 even if the cat gets to move a bit and then the bird cat, then the bird, 1281 01:00:58,090 --> 01:00:59,798 the fact that that's happening so quickly 1282 01:00:59,798 --> 01:01:01,930 means my human eyes probably won't even notice. 1283 01:01:01,930 --> 01:01:04,780 So for all intents and purposes, a multithreaded program 1284 01:01:04,780 --> 01:01:08,580 is indeed doing multiple things at once, just like our past example. 1285 01:01:08,580 --> 01:01:12,120 But sometimes those threads might want to inter-communicate, 1286 01:01:12,120 --> 01:01:15,930 not just pointing themselves at each other, but actually sending messages. 1287 01:01:15,930 --> 01:01:17,460 And notice how this can work. 1288 01:01:17,460 --> 01:01:22,110 When green flag is clicked, let's have this puppet forever do the following. 1289 01:01:22,110 --> 01:01:23,780 If the key space-- 1290 01:01:23,780 --> 01:01:25,350 so the space bar is pressed-- 1291 01:01:25,350 --> 01:01:28,770 then say Marco for two seconds, as per this game. 1292 01:01:28,770 --> 01:01:31,200 And then broadcast something called an event. 1293 01:01:31,200 --> 01:01:35,220 An event is like sending a message wirelessly 1294 01:01:35,220 --> 01:01:36,870 that only computers can hear. 1295 01:01:36,870 --> 01:01:39,480 So it's not saying just the word, Marco. 1296 01:01:39,480 --> 01:01:42,490 It's also transmitting a signal called an Event. 1297 01:01:42,490 --> 01:01:48,240 And so long as the other puppet has been configured to listen for that event, 1298 01:01:48,240 --> 01:01:51,450 then it can respond to the first puppet's action. 1299 01:01:51,450 --> 01:01:54,540 So the orange puppet is going to say Marco and then broadcast 1300 01:01:54,540 --> 01:01:55,890 this so-called event. 1301 01:01:55,890 --> 01:01:58,650 The blue puppet, quite simply, is going to do this. 1302 01:01:58,650 --> 01:02:03,100 When I receive Event, say Polo, for two seconds. 1303 01:02:03,100 --> 01:02:06,720 So in other words, this blue Muppet is not 1304 01:02:06,720 --> 01:02:09,530 going to do anything when the green flag is clicked. 1305 01:02:09,530 --> 01:02:11,190 There is no such block there. 1306 01:02:11,190 --> 01:02:16,530 Rather, when I receive Event, that secret wireless signal from some other 1307 01:02:16,530 --> 01:02:18,570 sprite-- in this case, the orange Muppet-- 1308 01:02:18,570 --> 01:02:22,170 the blue Muppet is going to say Polo for two seconds. 1309 01:02:22,170 --> 01:02:26,010 And so notice the dependency we've created between these two guys. 1310 01:02:26,010 --> 01:02:29,770 When I now click on the green flag, nothing appears to happen. 1311 01:02:29,770 --> 01:02:33,570 But the orange Muppet, remember, is listening for my space bar. 1312 01:02:33,570 --> 01:02:37,710 And so as soon as I hit it, he says Marco and the blue guy 1313 01:02:37,710 --> 01:02:40,650 hears it and says Polo. 1314 01:02:40,650 --> 01:02:45,210 But the only thing listening for my key press is the orange puppet. 1315 01:02:45,210 --> 01:02:48,240 The blue puppet, meanwhile, is only responding to the Event 1316 01:02:48,240 --> 01:02:50,340 emitted by the orange puppet. 1317 01:02:50,340 --> 01:02:54,510 Now, this allows us to implement this simple little game with puppets. 1318 01:02:54,510 --> 01:02:58,797 But this idea that one thread can convey a message to another 1319 01:02:58,797 --> 01:03:00,130 is what's ultimately compelling. 1320 01:03:00,130 --> 01:03:03,150 Surely I could use that in more complicated programs 1321 01:03:03,150 --> 01:03:06,750 as a mechanism for having two sprites interact somehow. 1322 01:03:06,750 --> 01:03:09,750 Not to follow each other around on the screen like the cat and the bird, 1323 01:03:09,750 --> 01:03:13,470 but maybe exchange messages of some sort. 1324 01:03:13,470 --> 01:03:16,320 So that something only happens to one sprite 1325 01:03:16,320 --> 01:03:21,630 if something has just happened to another sprite. 1326 01:03:21,630 --> 01:03:22,210 Woo. 1327 01:03:22,210 --> 01:03:23,520 Well, that was Scratch. 1328 01:03:23,520 --> 01:03:27,000 This is just one programming language, and it's graphical at that. 1329 01:03:27,000 --> 01:03:28,920 And indeed, programmers in the real world 1330 01:03:28,920 --> 01:03:32,440 don't typically write software by dragging and dropping puzzle pieces. 1331 01:03:32,440 --> 01:03:34,800 Rather, they write textual lines of code, 1332 01:03:34,800 --> 01:03:39,120 like the C and C++ and Java and Python and Ruby code that we saw earlier. 1333 01:03:39,120 --> 01:03:43,800 But the ideas that they write down and the ideas that they leverage 1334 01:03:43,800 --> 01:03:46,500 are functionally identical to so many of the ideas 1335 01:03:46,500 --> 01:03:48,000 that we've seen here in Scratch. 1336 01:03:48,000 --> 01:03:50,940 What Scratch does for us, for our purposes 1337 01:03:50,940 --> 01:03:54,032 here, is just get rid of things like the hashtag symbol 1338 01:03:54,032 --> 01:03:55,740 and the curly braces and the parentheses, 1339 01:03:55,740 --> 01:03:59,040 and so many other syntactic features that are really just distractions. 1340 01:03:59,040 --> 01:04:01,350 And necessary for the language as vocabulary, 1341 01:04:01,350 --> 01:04:03,910 but not necessary to understand the ideas. 1342 01:04:03,910 --> 01:04:07,620 So if you walk away today with an understanding of what functions are 1343 01:04:07,620 --> 01:04:10,980 and loops and conditions, Boolean expressions, variables, 1344 01:04:10,980 --> 01:04:13,830 and perhaps threads and events, and some of the other features 1345 01:04:13,830 --> 01:04:17,880 we've seen evinced by Scratch, do you have really a fundamental understanding 1346 01:04:17,880 --> 01:04:22,390 of what it tends to be like to program in fairly common languages? 1347 01:04:22,390 --> 01:04:24,640 Indeed, we focused on one type of programming language 1348 01:04:24,640 --> 01:04:26,692 here, imperative or procedural programming. 1349 01:04:26,692 --> 01:04:28,150 And there's other worlds out there. 1350 01:04:28,150 --> 01:04:29,920 There's object-oriented programming. 1351 01:04:29,920 --> 01:04:31,480 There is functional programming. 1352 01:04:31,480 --> 01:04:35,850 But the end of the day, the key takeaway is that in those and these languages, 1353 01:04:35,850 --> 01:04:38,980 are there are generally these principles, these fundamentals, 1354 01:04:38,980 --> 01:04:43,980 these building blocks as embodied by the literal puzzle pieces here, 1355 01:04:43,980 --> 01:04:47,880 with which you can assemble solutions to problems by using 1356 01:04:47,880 --> 01:04:52,470 very small problems solved with these puzzle pieces and build, 1357 01:04:52,470 --> 01:04:56,820 on top of those solutions, even more and more sophisticated solutions. 1358 01:04:56,820 --> 01:05:00,540 Still consider, after all, where we began, looking at Oscar Time. 1359 01:05:00,540 --> 01:05:02,960 That is a game where you have to rack up a high 1360 01:05:02,960 --> 01:05:05,670 as high a score as possible by clicking and dragging and dropping 1361 01:05:05,670 --> 01:05:09,570 trash that's falling from the sky into the trash before the game ends. 1362 01:05:09,570 --> 01:05:11,220 But what does that even mean? 1363 01:05:11,220 --> 01:05:16,140 Again, if you zoom in to the lowest level at the puzzle pieces 1364 01:05:16,140 --> 01:05:18,930 and the building blocks that compose that program, 1365 01:05:18,930 --> 01:05:21,110 there is just a loop that was making the trash fall. 1366 01:05:21,110 --> 01:05:23,970 And there is just a variable keeping track of the score. 1367 01:05:23,970 --> 01:05:26,760 And there was an If condition raising the lid of the trash when 1368 01:05:26,760 --> 01:05:28,020 the cursor got close enough. 1369 01:05:28,020 --> 01:05:31,290 And so all of the complexity of that particular game, at the end of the day, 1370 01:05:31,290 --> 01:05:35,430 can be reduced to these and other basic primitives. 1371 01:05:35,430 --> 01:05:37,350 As to what other languages are out there, 1372 01:05:37,350 --> 01:05:40,380 this is just a slice of the possible list. 1373 01:05:40,380 --> 01:05:43,380 But on the screen here, would you see some of those familiar ones again, 1374 01:05:43,380 --> 01:05:48,960 C and C++, but so many others that are being used currently or have been used 1375 01:05:48,960 --> 01:05:49,710 in the past. 1376 01:05:49,710 --> 01:05:52,260 And the dot, dot, dot suggests that there's so many more. 1377 01:05:52,260 --> 01:05:54,343 In fact, if you'd like to take a look in Wikipedia 1378 01:05:54,343 --> 01:05:57,630 and be completely overwhelmed by the many languages out there, 1379 01:05:57,630 --> 01:06:01,560 you'll be impressed by just how many we humans have created over time. 1380 01:06:01,560 --> 01:06:04,800 But at the end of the day, there tend to be trends in this industry. 1381 01:06:04,800 --> 01:06:07,767 And when you are a programmer or a software developer 1382 01:06:07,767 --> 01:06:10,350 or a software engineer in the real world working for a company 1383 01:06:10,350 --> 01:06:13,260 or really just working for a hobby, will you, as a programmer, 1384 01:06:13,260 --> 01:06:17,250 tend to have just one or a few languages that you tend to reach for? 1385 01:06:17,250 --> 01:06:19,890 So becoming a programmer is not about learning 1386 01:06:19,890 --> 01:06:21,600 that list of programming languages. 1387 01:06:21,600 --> 01:06:24,660 Even I only know a tiny fraction, probably count them 1388 01:06:24,660 --> 01:06:26,610 on one or two hands in total. 1389 01:06:26,610 --> 01:06:28,410 But you tend to want to introduce yourself 1390 01:06:28,410 --> 01:06:30,480 to different types of programming languages. 1391 01:06:30,480 --> 01:06:34,080 So that when something new comes along or some new device comes along 1392 01:06:34,080 --> 01:06:37,950 that you want to program for, you have the basic ideas and principles in mind 1393 01:06:37,950 --> 01:06:40,409 and simply need to pick up a bit of new syntax. 1394 01:06:40,409 --> 01:06:42,450 And as such, it's a little bit easier, I daresay, 1395 01:06:42,450 --> 01:06:45,150 than learning a new spoken or written human language. 1396 01:06:45,150 --> 01:06:48,990 Because these languages tend to be more narrowly defined with fewer keywords. 1397 01:06:48,990 --> 01:06:53,970 But the ideas persist, even as some of those particulars changed. 1398 01:06:53,970 --> 01:06:58,520 To wrap for now, I thought we'd take a look at an oldie but goodie, 1399 01:06:58,520 --> 01:07:01,230 a program written by one of our own former students 1400 01:07:01,230 --> 01:07:03,840 that synthesized music, synthesized loops, 1401 01:07:03,840 --> 01:07:07,290 then synthesized conditions, all to create 1402 01:07:07,290 --> 01:07:11,800 a wonderfully-animated conclusion to this look here, at programming. 1403 01:07:11,800 --> 01:07:41,400 [MUSIC - THE WEATHER GIRLS, "IT'S RAINING MEN"] 1404 01:07:41,400 --> 01:07:42,400 WEATHER GIRL ICON 1: Hi! 1405 01:07:42,400 --> 01:07:43,399 WEATHER GIRL ICON 2: Hi! 1406 01:07:43,399 --> 01:07:44,500 We're your weather girls. 1407 01:07:44,500 --> 01:07:45,666 WEATHER GIRL ICON 3: Uh-huh. 1408 01:07:45,666 --> 01:07:48,100 WEATHER GIRL ICON 2: And have we got news for you! 1409 01:07:48,100 --> 01:07:49,725 WEATHER GIRL ICON 1: You better listen. 1410 01:07:49,725 --> 01:07:52,000 WEATHER GIRL ICON 2: Get ready, all you lonely girls, 1411 01:07:52,000 --> 01:07:54,100 and leave those umbrellas at home. 1412 01:07:54,100 --> 01:07:55,600 WEATHER GIRL ICON 3: All right. 1413 01:07:55,600 --> 01:07:57,700 ALL (SINGING): Humidity's rising. 1414 01:07:57,700 --> 01:07:59,200 WEATHER GIRL ICON 2: Mm, rising. 1415 01:07:59,200 --> 01:08:00,400 ALL (SINGING): Barometer's getting low. 1416 01:08:00,400 --> 01:08:01,600 WEATHER GIRL ICON 2: How low, girl? 1417 01:08:01,600 --> 01:08:02,800 WEATHER GIRL ICON 1: Uh-oh. 1418 01:08:02,800 --> 01:08:04,600 ALL (SINGING): According to all sources-- 1419 01:08:04,600 --> 01:08:06,100 WEATHER GIRL ICON 1: What sources, now? 1420 01:08:06,100 --> 01:08:07,933 ALL (SINGING): The street's the place to go. 1421 01:08:07,933 --> 01:08:09,700 WEATHER GIRL ICON 2: We better hurry up. 1422 01:08:09,700 --> 01:08:15,434 'Cause tonight, for the first time, just about half past 10. 1423 01:08:15,434 --> 01:08:16,600 ALL (SINGING): Half past 10. 1424 01:08:16,600 --> 01:08:20,200 WEATHER GIRL ICON 2: For the first time in history, 1425 01:08:20,200 --> 01:08:22,000 it's going to start raining men. 1426 01:08:22,000 --> 01:08:24,100 WEATHER GIRL ICONS 2 AND 3: Start raining men. 1427 01:08:24,100 --> 01:08:30,400 WEATHER GIRL ICON 2: It's raining men, hallelujah, it's raining men. 1428 01:08:30,400 --> 01:08:32,200 Amen. 1429 01:08:32,200 --> 01:08:34,000 I'm going to go out. 1430 01:08:34,000 --> 01:08:36,100 I'm going to let myself get-- 1431 01:08:36,100 --> 01:08:40,000 ALL: Absolutely soaking wet! 1432 01:08:40,000 --> 01:08:42,700 WEATHER GIRL ICON 2: It's raining men! 1433 01:08:42,700 --> 01:08:44,850 Hallelujah!