1 00:00:00,506 --> 00:00:08,516 [ Silence ] 2 00:00:09,016 --> 00:00:47,506 [ Noise ] 3 00:00:48,006 --> 00:01:25,656 [ Music ] 4 00:01:26,156 --> 00:01:28,736 >> This-- This is CS50. 5 00:01:29,436 --> 00:01:33,566 Welcome back or welcome for the first time 6 00:01:33,666 --> 00:01:35,216 to the end of week zero. 7 00:01:35,216 --> 00:01:38,026 So today's opening act is courtesy of Nicole Bowman, 8 00:01:38,056 --> 00:01:41,326 a student self-described last year is among those less 9 00:01:41,326 --> 00:01:43,806 comfortable when she implemented that visualization 10 00:01:44,066 --> 00:01:46,636 in a programming language called "Scratch" 11 00:01:46,666 --> 00:01:48,676 into which we will dive as a group today. 12 00:01:48,946 --> 00:01:51,286 But recall couple of invitations from Wednesday. 13 00:01:51,286 --> 00:01:53,676 So this year is a representative puzzle 14 00:01:53,676 --> 00:01:55,446 for the first ever CS50 puzzle day 15 00:01:55,446 --> 00:01:57,696 to take place tomorrow at noon. 16 00:01:57,766 --> 00:02:02,466 For those who only glimpse this earlier who happen struggling 17 00:02:02,466 --> 00:02:05,436 with this sort of puzzle, I'll offer the following clue 18 00:02:05,436 --> 00:02:07,666 if you focus on the very top line. 19 00:02:07,666 --> 00:02:13,726 You might think to yourself 1, 2, 3, 4, 20 00:02:14,556 --> 00:02:17,776 we there yet, 5, and so forth. 21 00:02:17,776 --> 00:02:20,266 The other lines are in quite as straightforward 22 00:02:20,266 --> 00:02:22,136 but if you actually fill in those blanks, 23 00:02:22,136 --> 00:02:24,846 you'll come out with some word and that's represented 24 00:02:24,846 --> 00:02:29,396 over the types of puzzles you'll be challenged to solve tomorrow. 25 00:02:29,496 --> 00:02:33,526 So if of interest and you have not RSVP just yet, 26 00:02:33,526 --> 00:02:37,846 do go to cs50.net/register to sign 27 00:02:37,846 --> 00:02:40,836 up for the Facebook sponsored CS50 puzzle day. 28 00:02:40,836 --> 00:02:42,906 It will take place at noon to 3 p.m. 29 00:02:43,126 --> 00:02:45,586 in a building called Northwest Science which is right 30 00:02:45,626 --> 00:02:49,306 across the street, just off the street from here. 31 00:02:49,556 --> 00:02:52,496 You'll be greeted with pizza as well as seven puzzles, 32 00:02:52,496 --> 00:02:55,516 either in printed or electronic form and once you do, 33 00:02:55,516 --> 00:02:59,636 you and your team of friends of 2 or 3 or size 4 will be able 34 00:02:59,636 --> 00:03:00,956 to go often to some corner, 35 00:03:00,956 --> 00:03:04,366 opt into some conference room outside and figure 36 00:03:04,366 --> 00:03:06,526 out the seven-letter clue that will lead you 37 00:03:06,526 --> 00:03:08,086 to some prize on campus. 38 00:03:08,086 --> 00:03:12,006 Among the prizes will be a Wii with the Mario cart bundle, 39 00:03:12,006 --> 00:03:14,826 raffled off to any possible participant not just those 40 00:03:14,826 --> 00:03:18,456 who win some 50 dollar, 25 dollar gift certificates 41 00:03:18,456 --> 00:03:20,326 as well some mice [phonetic] as well 42 00:03:20,326 --> 00:03:22,166 as some other giveaways during that. 43 00:03:22,166 --> 00:03:24,166 And our friends from Facebook will be in attendance 44 00:03:24,366 --> 00:03:28,336 if you would like to see what life is like their real world. 45 00:03:28,336 --> 00:03:29,536 Also with of interest, 46 00:03:30,086 --> 00:03:32,396 dinner tonight you are all cordially invited. 47 00:03:32,396 --> 00:03:35,516 Do go to cs50.net/rsvp. 48 00:03:35,576 --> 00:03:38,616 If you did not so already and you would like to join us, 49 00:03:38,666 --> 00:03:41,716 the plan is to meet at 6:30 tonight at Maxwell-Dworkin 50 00:03:41,716 --> 00:03:43,096 which is also just up the street. 51 00:03:43,096 --> 00:03:44,936 If these names are unfamiliar to you, 52 00:03:45,176 --> 00:03:47,486 just go to the course's home page, cs50.net, 53 00:03:47,566 --> 00:03:49,616 and we have direct links to the addresses 54 00:03:49,616 --> 00:03:51,626 so that you can find your way on campus. 55 00:03:51,886 --> 00:03:53,976 So now those of you who are joining us for the first 56 00:03:54,076 --> 00:03:56,796 and even those who are here on Wednesday, allow me to excerpt 57 00:03:56,836 --> 00:04:00,546 from the syllabus something that is particularly important 58 00:04:00,716 --> 00:04:01,826 to me and to the course. 59 00:04:02,126 --> 00:04:04,236 So there's this excerpt there, what ultimately matters 60 00:04:04,236 --> 00:04:06,396 in this course is not so much where you end up relative 61 00:04:06,396 --> 00:04:09,086 to your classmates, but where you end up-- 62 00:04:09,086 --> 00:04:11,846 but where you in week 12, at the end of the course, 63 00:04:12,106 --> 00:04:14,226 end up relative to yourself in week 0. 64 00:04:14,226 --> 00:04:16,196 There's no predetermined distribution of grades, 65 00:04:16,196 --> 00:04:17,456 there's no curve per se. 66 00:04:17,636 --> 00:04:19,456 We very much do grade students in this course 67 00:04:19,456 --> 00:04:22,166 in an individual basic whether doing a pass-fail 68 00:04:22,166 --> 00:04:24,426 which certainly encouraged per the pink pass-fail 69 00:04:24,426 --> 00:04:26,266 of change slips if you need them at any point 70 00:04:26,646 --> 00:04:28,596 or if you take it for a letter grade. 71 00:04:28,596 --> 00:04:31,016 And more over as we hit it on Wednesday, 72 00:04:31,246 --> 00:04:33,516 we do take into account students [inaudible] backgrounds. 73 00:04:33,666 --> 00:04:35,446 So once it comes time to section 74 00:04:35,446 --> 00:04:36,866 and sectioning will start next week, 75 00:04:36,946 --> 00:04:38,176 you needn't do anything just yet, 76 00:04:38,316 --> 00:04:39,306 we'll announce it next week. 77 00:04:39,716 --> 00:04:41,896 We'll have three different tracks of sections. 78 00:04:41,896 --> 00:04:44,086 The track of section for those less comfortable, 79 00:04:44,336 --> 00:04:47,016 those more comfortable, and those somewhere in between. 80 00:04:47,016 --> 00:04:49,166 And when it comes time to section, 81 00:04:49,446 --> 00:04:51,046 you kinda know what bucket you're in. 82 00:04:51,046 --> 00:04:52,566 If you're in the less comfortable group, 83 00:04:52,566 --> 00:04:55,116 odds are that's a label you'll immediately gravitate toward. 84 00:04:55,116 --> 00:04:57,426 And similarly if you're particularly advance, 85 00:04:57,426 --> 00:04:58,976 you're eager to those hacker editions, 86 00:04:59,256 --> 00:05:00,916 you're probably among those come comfortable. 87 00:05:00,916 --> 00:05:01,886 And if you're kinda of on the fence, 88 00:05:02,216 --> 00:05:03,876 somewhere in between is a-- 89 00:05:04,146 --> 00:05:06,126 is a large portion of the class as well. 90 00:05:06,126 --> 00:05:08,356 So realize that the course tries to keep everyone 91 00:05:08,356 --> 00:05:10,766 on track not only for those without experience 92 00:05:10,766 --> 00:05:12,266 but also keeping interested 93 00:05:12,266 --> 00:05:14,826 and challenged those with more experience. 94 00:05:14,886 --> 00:05:16,826 In terms of the support structure that awakes-- 95 00:05:16,826 --> 00:05:20,566 that awaits, realize that the first problems sets PDF was post 96 00:05:20,566 --> 00:05:22,576 into the course's websites this morning 97 00:05:22,896 --> 00:05:24,346 and it's due next Thursday. 98 00:05:24,346 --> 00:05:26,376 But toward that end, there's this walkthrough, 99 00:05:26,376 --> 00:05:27,706 every week for every problem 100 00:05:27,756 --> 00:05:30,336 that we'll have a code walkthrough so to speak, 101 00:05:30,596 --> 00:05:32,746 where about one of the teaching fellows will walk you 102 00:05:32,816 --> 00:05:35,966 through the process of diving into that problem set. 103 00:05:35,966 --> 00:05:36,926 They're not mandatory. 104 00:05:37,176 --> 00:05:38,666 They are simply there, so that if you're one 105 00:05:38,666 --> 00:05:41,256 of those students whether in this course or in general 106 00:05:41,256 --> 00:05:42,936 who picks up a P set and is often-- 107 00:05:43,176 --> 00:05:46,206 I'm not really sure where to begin or how to tackle it, well, 108 00:05:46,206 --> 00:05:48,716 that's exactly what these video tape walkthroughs will be. 109 00:05:48,716 --> 00:05:50,226 We'll walk you through the spec itself. 110 00:05:50,226 --> 00:05:52,446 We'll propose ideas, things to think about. 111 00:05:52,676 --> 00:05:54,416 So realize that is the support structure 112 00:05:54,416 --> 00:05:55,516 that would be taking place 113 00:05:55,516 --> 00:05:58,226 and almost every Sunday whenever there's a P set of the week, 114 00:05:58,416 --> 00:05:59,816 at 7 p.m. also 115 00:05:59,816 --> 00:06:02,106 in Maxwell-Dworkin whose address can be found 116 00:06:02,106 --> 00:06:05,026 on the course's website under problem sets. 117 00:06:05,356 --> 00:06:08,156 Office hours too will commence this year coinciding 118 00:06:08,156 --> 00:06:10,616 with Brain Break in four-- in three different dining halls, 119 00:06:10,886 --> 00:06:13,366 simply check out the course's website for the schedule thereof 120 00:06:13,366 --> 00:06:15,636 and you will see and you we will work out the kings 121 00:06:15,636 --> 00:06:19,406 of [inaudible], our brand new fancy online system iPad based 122 00:06:19,406 --> 00:06:21,306 systems [inaudible] coming up on Monday in [inaudible], 123 00:06:21,306 --> 00:06:25,316 Tuesday in Leverett, and then Wednesday 124 00:06:25,316 --> 00:06:27,286 and Thursday Lowell House. 125 00:06:27,286 --> 00:06:31,346 So keep an eye on the course's website for details. 126 00:06:31,666 --> 00:06:34,716 So rather than just tell you a little bit about 50 in terms 127 00:06:34,716 --> 00:06:37,386 of pictures, what we thought we do is actually draw 128 00:06:37,386 --> 00:06:41,546 on some voices of CS50 past from both former TFs, 129 00:06:41,546 --> 00:06:44,126 former CAs as well as former students. 130 00:06:44,126 --> 00:06:45,566 So if we could dim the light again, 131 00:06:45,856 --> 00:06:49,866 allow me to convey some messages from your predecessors. 132 00:06:50,516 --> 00:06:56,356 [ Noise ] 133 00:06:56,856 --> 00:07:02,696 [ Beep Sound ] 134 00:07:03,196 --> 00:07:07,366 >> My name is Jason, and I took CS50 in the fall. 135 00:07:07,366 --> 00:07:07,926 I'm a freshman. 136 00:07:08,496 --> 00:07:10,646 And I was sort of looking 137 00:07:10,756 --> 00:07:12,676 for something I never studied before. 138 00:07:12,676 --> 00:07:15,956 So-- And I knew it's gonna be fun but also a lot of work. 139 00:07:16,336 --> 00:07:19,216 And I found all of those and more in CS50. 140 00:07:19,216 --> 00:07:20,526 So I had a fantastic experience 141 00:07:20,526 --> 00:07:22,016 and I'm pretty sure it changed my life 142 00:07:22,016 --> 00:07:23,476 and changed what I was interested in. 143 00:07:23,726 --> 00:07:26,966 So I'm here to encourage other people to take CS50 as well. 144 00:07:26,966 --> 00:07:32,976 So hopefully they can as wonderful experience as I did. 145 00:07:32,976 --> 00:07:35,046 >> So tell us how you got into the CS concentration. 146 00:07:35,486 --> 00:07:38,786 >> I took CS in high school and I really liked it, 147 00:07:38,856 --> 00:07:40,646 and I real like it all at Harvard, 148 00:07:40,716 --> 00:07:42,846 so I'm happy with it, I guess. 149 00:07:43,156 --> 00:07:43,626 >> Very cool! 150 00:07:43,626 --> 00:07:46,286 What do you think about CS as a potential minor, 151 00:07:46,286 --> 00:07:48,376 do you think it's a good option for lot people? 152 00:07:48,486 --> 00:07:49,966 What would you sell some around that way? 153 00:07:50,236 --> 00:07:53,626 >> I think it's really useful because CS is really liberating, 154 00:07:53,956 --> 00:07:57,026 once you know how do just like a small script you can make 155 00:07:57,526 --> 00:08:01,166 that [inaudible] people have to do or you can do, I don't know, 156 00:08:01,166 --> 00:08:04,316 minor things just make your life easier, which is really nice. 157 00:08:04,316 --> 00:08:05,256 So [inaudible] is good too. 158 00:08:06,496 --> 00:08:07,876 >> [Inaudible], thank you so much. 159 00:08:08,446 --> 00:08:12,576 There you have it, CS empowering. 160 00:08:13,886 --> 00:08:17,136 >> So this is my final project that I developed last year. 161 00:08:18,706 --> 00:08:21,956 Actually, was up in space for a majority the time taking a lot 162 00:08:22,146 --> 00:08:26,116 of these photos which was the probably the biggest time 163 00:08:26,116 --> 00:08:27,386 consuming aspect to this. 164 00:08:27,386 --> 00:08:28,376 But it's pretty cool. 165 00:08:29,076 --> 00:08:34,746 Apple got it lot of their ideas from me, so did Google Earth. 166 00:08:35,916 --> 00:08:39,346 It's really, really unique, you know, can find your house, 167 00:08:39,716 --> 00:08:43,576 even if you live in the middle of the ocean like over here. 168 00:08:45,326 --> 00:08:45,926 Good place. 169 00:08:46,806 --> 00:08:48,376 Also if you like wanna play-- 170 00:08:49,056 --> 00:08:52,386 let's play some chess, you can play chess. 171 00:08:52,516 --> 00:08:55,016 It's a great little development too. 172 00:08:55,016 --> 00:08:57,166 I learned a lot and thanks 173 00:08:57,446 --> 00:08:59,736 to CS50 you can create things just like this. 174 00:09:00,236 --> 00:09:02,466 [ Laughter ] 175 00:09:02,966 --> 00:09:05,776 >> Oh, definitely, CS50 was a lot fun. 176 00:09:06,956 --> 00:09:08,926 I remember when I was looking at the courses 177 00:09:09,076 --> 00:09:10,756 like before I came here. 178 00:09:10,756 --> 00:09:15,336 Like I knew it's gonna my math course and, you know, oh, 179 00:09:15,336 --> 00:09:16,146 a lot of them I pick 180 00:09:16,146 --> 00:09:18,606 out of having trying CS50 I did [inaudible] I was gonna take, 181 00:09:18,606 --> 00:09:21,256 but after the first day of shopping, you know, 182 00:09:21,256 --> 00:09:26,446 and then I entered, okay, this is for me. 183 00:09:26,446 --> 00:09:29,636 >> [Inaudible] about CS50 at 4 a.m. in the morning. 184 00:09:29,636 --> 00:09:29,866 >> I like it. 185 00:09:29,866 --> 00:09:34,106 It's-- It really has a sense of creativity 'cause there's a lot 186 00:09:34,106 --> 00:09:36,086 of creativity flowing around everywhere. 187 00:09:36,086 --> 00:09:36,153 [ Laughter ] 188 00:09:36,153 --> 00:09:40,916 >> Everybody just seems like really excited and it's already 189 00:09:40,916 --> 00:09:44,816 like 4:30 and everyone is awake and working on their projects. 190 00:09:44,816 --> 00:09:45,506 It's pretty cool. 191 00:09:45,506 --> 00:09:45,573 [ Laughter ] 192 00:09:45,573 --> 00:09:47,746 >> Like hackaton. 193 00:09:47,746 --> 00:09:48,926 [ Simultaneous Talking ] 194 00:09:48,926 --> 00:09:50,906 >> We had so much fun. 195 00:09:51,376 --> 00:09:52,556 >> We were raging in the corner. 196 00:09:52,556 --> 00:09:52,856 Yeah. 197 00:09:53,266 --> 00:09:53,616 >> Music. 198 00:09:53,776 --> 00:09:55,496 >> Eating all the candy. 199 00:09:56,106 --> 00:09:58,226 >> Eating-- They're eating lots of candy, 200 00:09:58,386 --> 00:10:00,096 that was disgusting, that was fun. 201 00:10:00,096 --> 00:10:01,716 >> Yeah 202 00:10:01,916 --> 00:10:01,983 >> So. 203 00:10:02,286 --> 00:10:04,066 >> What do you think of the CS50 [inaudible]? 204 00:10:04,456 --> 00:10:05,606 >> There're a lot of people here. 205 00:10:05,606 --> 00:10:07,266 I think it's amazing that there're 206 00:10:07,306 --> 00:10:09,966 so many really great projects that are going. 207 00:10:10,046 --> 00:10:12,566 But it's definitely a challenging semester but I think 208 00:10:12,566 --> 00:10:14,166 at the end-- at the end you can say 209 00:10:14,166 --> 00:10:16,246 like I've gained some very tangible skills. 210 00:10:16,696 --> 00:10:17,866 So definitely use the future. 211 00:10:19,436 --> 00:10:21,976 >> I've really thought that has been one 212 00:10:21,976 --> 00:10:24,056 of the most practical courses that I've taken at Harvard 213 00:10:24,056 --> 00:10:27,456 and also lot of fun and I've really enjoyed learning how 214 00:10:27,456 --> 00:10:28,676 to use the technology. 215 00:10:29,576 --> 00:10:32,946 I'm really interested in medicine 216 00:10:32,946 --> 00:10:34,116 as you can probably tell from this. 217 00:10:34,116 --> 00:10:36,476 So I think I'm gonna go like to-- go and be a doctor. 218 00:10:36,526 --> 00:10:40,466 But I think that being able to work with programming 219 00:10:40,466 --> 00:10:45,446 and websites and computers is such a useful skill 220 00:10:45,446 --> 00:10:46,516 and everybody should really know it. 221 00:10:47,606 --> 00:10:50,486 >> Harvard President Faust, we just wanna ask you, 222 00:10:50,486 --> 00:10:51,176 what you think of the [inaudible]? 223 00:10:52,126 --> 00:10:52,946 >> Well, it was really fun. 224 00:10:52,946 --> 00:10:57,296 First I was struck by how much energy there is in this room 225 00:10:57,296 --> 00:10:59,576 and everyone so excited about their projects 226 00:10:59,576 --> 00:11:01,226 and everyone else's projects. 227 00:11:01,926 --> 00:11:06,686 But I was so struck by the ingenuity of the projects I saw. 228 00:11:06,686 --> 00:11:09,606 Lost and found seems to be a shared theme 229 00:11:09,676 --> 00:11:12,196 that obviously [inaudible] university why it's lost 230 00:11:12,196 --> 00:11:12,976 and found. 231 00:11:13,906 --> 00:11:16,696 So I-- and then I just saw an application which is 232 00:11:16,696 --> 00:11:18,546 about debating across Harvard 233 00:11:18,586 --> 00:11:22,326 where people can debate issues online and I thought there're 234 00:11:22,326 --> 00:11:24,326 so many questions that it would be great 235 00:11:24,326 --> 00:11:25,956 to just get people's responses on. 236 00:11:26,046 --> 00:11:28,746 So I though about what a contribution 237 00:11:28,746 --> 00:11:30,476 at the community that could be. 238 00:11:30,476 --> 00:11:33,836 And then I just saw a lot of other very ingenious websites 239 00:11:33,836 --> 00:11:36,806 about where to find libraries and different functions 240 00:11:36,806 --> 00:11:40,116 in libraries and a variety of things. 241 00:11:40,216 --> 00:11:41,786 So, what a great event. 242 00:11:42,516 --> 00:11:48,516 [ Noise ] 243 00:11:49,016 --> 00:11:55,000 [ Applause ] 244 00:11:55,306 --> 00:11:58,976 >> So, even though the CS50 fair each year is the climax 245 00:11:58,976 --> 00:12:01,146 of the course and the terminus of the course, 246 00:12:01,146 --> 00:12:03,516 many students do go on with their projects 247 00:12:03,516 --> 00:12:07,626 or with variants thereof to create their own startups, 248 00:12:07,626 --> 00:12:10,506 to incubate their ideas with friends particularly now 249 00:12:10,506 --> 00:12:12,086 that Harvard has its own J term. 250 00:12:12,086 --> 00:12:14,306 And so those of you who are particularly interested 251 00:12:14,306 --> 00:12:16,786 in pursuing some startup with your own or externally 252 00:12:17,026 --> 00:12:20,206 or just generally interest in on entrepreneurship, 253 00:12:20,416 --> 00:12:23,046 know that any number of resources exist that you'll come 254 00:12:23,046 --> 00:12:26,086 across particularly toward terms and Hack Harvard for instance. 255 00:12:26,086 --> 00:12:28,386 It's a relatively new student group on which some 256 00:12:28,386 --> 00:12:30,926 of our own teaching fellows and CAs now participate 257 00:12:31,076 --> 00:12:33,416 and this will be an opportunity and J term to come back 258 00:12:33,416 --> 00:12:36,246 to campus early and immerse yourself with the team 259 00:12:36,246 --> 00:12:38,226 of your friends and work on some project. 260 00:12:38,226 --> 00:12:41,666 Maybe even your CS50 project and take it to the next level, 261 00:12:41,666 --> 00:12:45,696 [inaudible] wonderful support structure surrounded 24/7 262 00:12:45,696 --> 00:12:47,576 by peers doing something similar. 263 00:12:47,816 --> 00:12:50,476 Know that the i3, the Harvard Collage Innovation Challenge 264 00:12:50,476 --> 00:12:50,916 will come up. 265 00:12:50,916 --> 00:12:53,606 And this is an opportunity to actually get potentially funding 266 00:12:53,606 --> 00:12:56,076 for some idea that you might have and so we'll be sure 267 00:12:56,076 --> 00:12:58,476 to announce the application deadline for an opportunity 268 00:12:58,476 --> 00:13:00,636 like that when it arises. 269 00:13:00,876 --> 00:13:04,136 Know too that Harvard and all of its schools is in a process 270 00:13:04,136 --> 00:13:06,026 in building out a little something like this 271 00:13:06,026 --> 00:13:09,576 across the river at HPS to be called the innovation lab 272 00:13:10,076 --> 00:13:12,596 for students and faculty and staff from across Harvard. 273 00:13:12,826 --> 00:13:15,036 This is meant to become a center of innovation, 274 00:13:15,036 --> 00:13:17,926 a place where you can go to work with work spaces, 275 00:13:17,926 --> 00:13:20,316 for invited guest, for food and such. 276 00:13:20,586 --> 00:13:21,986 And so this will be debuting 277 00:13:21,986 --> 00:13:23,946 in a few months once construction is complete 278 00:13:23,946 --> 00:13:26,276 and the idea is to really bring people and ideas 279 00:13:26,276 --> 00:13:29,576 from across campus particularly across schools to work 280 00:13:29,576 --> 00:13:31,156 on all things innovative. 281 00:13:31,326 --> 00:13:33,756 In particular if you're interested in J term 282 00:13:33,756 --> 00:13:37,116 in joining some of those folks out in Silicon Valley 283 00:13:37,116 --> 00:13:38,916 on a little field trip over J term, 284 00:13:38,916 --> 00:13:40,956 know that there'll be an application opportunity 285 00:13:41,186 --> 00:13:44,396 to just a couple of weeks to go with some 35 peers 286 00:13:44,696 --> 00:13:45,866 out to Silicon Valley. 287 00:13:45,866 --> 00:13:49,466 Meet with startup, see startups, talk to VCs, venture capitalist, 288 00:13:49,736 --> 00:13:53,366 and talk with folks who live in breath this particular world. 289 00:13:53,366 --> 00:13:55,796 And also closer to home, know that in a short term, 290 00:13:55,796 --> 00:13:58,146 there are mailing lists and plenty of your peers, 291 00:13:58,326 --> 00:14:01,226 an upper class man who discuss and explore these kinds 292 00:14:01,226 --> 00:14:04,016 of things, the whipping through these URLs fairly quickly. 293 00:14:04,016 --> 00:14:06,146 The slides are online so you can grab this later. 294 00:14:06,146 --> 00:14:09,016 But in email list called the Harvard College Entrepreneurship 295 00:14:09,056 --> 00:14:12,766 Form as well as the Harvard College Venture Partners exist 296 00:14:12,896 --> 00:14:13,486 as well. 297 00:14:13,846 --> 00:14:16,536 So in terms of CS50 today, we do have these pink forms 298 00:14:16,536 --> 00:14:19,226 which are only necessary if you decide to switch grading status 299 00:14:19,226 --> 00:14:20,556 between now and the 5th and Monday. 300 00:14:20,806 --> 00:14:23,586 We also have copies of the same handouts from Wednesday, 301 00:14:23,586 --> 00:14:26,236 one of which is the syllabus, the other of which is this, 302 00:14:26,236 --> 00:14:28,836 the unofficial CS50 guide to computer science at Harvard. 303 00:14:29,106 --> 00:14:30,906 The goal here is not to turn everyone in this room 304 00:14:30,906 --> 00:14:32,906 into a computer science concentrate or a minor, 305 00:14:33,106 --> 00:14:35,056 but to give you a sense of where else you can go. 306 00:14:35,056 --> 00:14:36,156 And particular the last-- 307 00:14:36,266 --> 00:14:38,706 very last back page of this is a cheat sheet 308 00:14:38,706 --> 00:14:40,946 of all the various directions in which you can go 309 00:14:41,166 --> 00:14:42,836 after just this course alone. 310 00:14:43,006 --> 00:14:44,776 And this brochure here is what was handed 311 00:14:44,776 --> 00:14:48,426 to all 2,000 attendees of the CS50 fair in 2010 312 00:14:48,586 --> 00:14:50,666 from which you saw excerpts just a moment ago. 313 00:14:50,916 --> 00:14:53,276 And these we handout so that you can get a sense 314 00:14:53,316 --> 00:14:57,176 in your own hands of the 500 some odd projects 315 00:14:57,176 --> 00:14:58,896 that your predecessors implemented along 316 00:14:58,896 --> 00:15:00,436 with their names, the descriptions 317 00:15:00,746 --> 00:15:02,926 and additional details as well 318 00:15:03,196 --> 00:15:05,036 as to what those folks were like. 319 00:15:05,076 --> 00:15:09,476 So do explore that if this is of interest to you. 320 00:15:09,816 --> 00:15:13,386 Now even now today, we're gonna dive into one of the core skills 321 00:15:13,386 --> 00:15:15,276 of computer science, namely programming. 322 00:15:15,276 --> 00:15:18,426 Bear in mind one that it's just tool the computer scientists 323 00:15:18,426 --> 00:15:20,746 tend to use and folks from other domains tend to use 324 00:15:20,896 --> 00:15:24,046 to solve problems on interest to themselves. 325 00:15:24,046 --> 00:15:26,596 It is not programming a goal into itself, 326 00:15:26,596 --> 00:15:29,606 but really a tool you can use expedite data analysis 327 00:15:29,606 --> 00:15:32,236 as we heard one of our student-- our own student say, 328 00:15:32,506 --> 00:15:34,676 to expedite just solving some real world problem 329 00:15:34,676 --> 00:15:37,376 that you wanna do more efficiently or mechanically 330 00:15:37,376 --> 00:15:39,096 than you could do, say by hand. 331 00:15:39,376 --> 00:15:42,166 But toward that end of actually learning 332 00:15:42,166 --> 00:15:44,046 to program it's perhaps useful 333 00:15:44,046 --> 00:15:47,576 to understand why these same ideas now increasingly imply 334 00:15:47,686 --> 00:15:48,546 in the real world? 335 00:15:48,546 --> 00:15:50,656 So a lot of you, many of you will not go off 336 00:15:50,656 --> 00:15:53,216 to take computer science minor or concentration 337 00:15:53,216 --> 00:15:55,346 and maybe not even a second course in computer science, 338 00:15:55,576 --> 00:15:57,916 but you're gonna go off at some point and some number of years 339 00:15:57,916 --> 00:16:00,736 to the real world, to business, to politics and the like, 340 00:16:00,736 --> 00:16:02,216 and presumably making decisions. 341 00:16:02,426 --> 00:16:04,786 And if you watch the news, particularly the daily show, 342 00:16:05,016 --> 00:16:06,766 you'll know that there's a whole lot of adults 343 00:16:06,766 --> 00:16:09,286 out there making really bad uninformed decisions 344 00:16:09,286 --> 00:16:11,896 particularly when it comes to technology, whether they're 345 00:16:11,896 --> 00:16:14,226 in positions of power or just consumers 346 00:16:14,226 --> 00:16:15,536 who are using technologies 347 00:16:15,536 --> 00:16:17,626 without even understanding how they work, 348 00:16:17,816 --> 00:16:20,606 or how they might threaten their own privacy and security. 349 00:16:20,836 --> 00:16:22,926 One of themes we'll discuss term's end 350 00:16:22,926 --> 00:16:24,806 when you introduce web programming 351 00:16:25,036 --> 00:16:28,166 and how you actually program dynamic websites and tools 352 00:16:28,166 --> 00:16:30,876 for the internet, we'll discuss issues of security, 353 00:16:31,086 --> 00:16:33,016 but just to tease you now, I though I'd share 354 00:16:33,016 --> 00:16:35,566 with you an example of something that literally crapped 355 00:16:35,566 --> 00:16:40,556 up the day before our one of our lecture's last fall on inter-- 356 00:16:40,556 --> 00:16:42,436 on the web programming in the internet. 357 00:16:42,686 --> 00:16:44,506 There's this tool with which from the whisperers, 358 00:16:44,506 --> 00:16:46,536 some of you are already clearly familiar with already. 359 00:16:46,536 --> 00:16:48,446 If not, you're about to be educated. 360 00:16:48,666 --> 00:16:53,036 So number months ago, a security researcher presented 361 00:16:53,036 --> 00:16:56,386 to the world a challenge that we as a society really need 362 00:16:56,386 --> 00:16:58,976 to fix some flaws that have existed in the web, 363 00:16:59,126 --> 00:17:02,176 in that protocol called "HTTP," which you've seen in front 364 00:17:02,176 --> 00:17:05,056 of URLs now for years that have existed for ages. 365 00:17:05,516 --> 00:17:06,916 Really since the beginning of a lot 366 00:17:06,916 --> 00:17:08,146 of these technologies' adaption 367 00:17:08,146 --> 00:17:10,796 but no one really took it seriously 368 00:17:10,796 --> 00:17:14,646 because it required exploiting weaknesses in these technologies 369 00:17:14,646 --> 00:17:19,536 and hacking certain things so to speak took more savvy than, say, 370 00:17:19,536 --> 00:17:21,006 the typical population might have. 371 00:17:21,006 --> 00:17:24,746 So this fellow wrote a plug in, an extension for firefox, 372 00:17:24,746 --> 00:17:26,436 the browser with which you're probably familiar, 373 00:17:26,696 --> 00:17:30,936 that makes it super easy to just log in to the Facebook account, 374 00:17:30,936 --> 00:17:33,206 the GMail account, the Twitter account, the Yahoo account, 375 00:17:33,206 --> 00:17:35,506 any number of big name accounts if you're 376 00:17:35,506 --> 00:17:37,886 within wireless range of these people. 377 00:17:37,886 --> 00:17:38,656 And when you run this tool, 378 00:17:38,656 --> 00:17:39,996 it looks a little something like this. 379 00:17:40,066 --> 00:17:41,326 This might be a browser window. 380 00:17:41,596 --> 00:17:43,056 A typical Firefox window 381 00:17:43,056 --> 00:17:45,156 and with this freely available tool installed, 382 00:17:45,416 --> 00:17:49,786 you can see a button at top left that just says start capturing. 383 00:17:50,066 --> 00:17:53,426 And so long as you're on a wireless Wi-Fi laptop 384 00:17:53,426 --> 00:17:55,816 and you're surrounded by other people whether it's on campus 385 00:17:55,816 --> 00:17:57,516 or in Starbucks or in an airport, 386 00:17:57,676 --> 00:17:58,946 there's all of these bits. 387 00:17:58,946 --> 00:18:01,176 All of this 0s and 1s going through the air 388 00:18:01,486 --> 00:18:03,706 that pretty much all of our laptops are 389 00:18:03,706 --> 00:18:05,416 on the honor system not to listen 390 00:18:05,416 --> 00:18:09,136 to unless they're destined from my own computer's address. 391 00:18:09,446 --> 00:18:11,546 Well, this tool simply turns itself into-- 392 00:18:11,786 --> 00:18:13,506 which definitely called "promiscuous mode" 393 00:18:13,576 --> 00:18:16,076 where it listens to all of these 0s and 1s flowing 394 00:18:16,076 --> 00:18:19,616 out the room whether or not they're belonging to me. 395 00:18:19,756 --> 00:18:22,026 And what you see with this particular tool, 396 00:18:22,026 --> 00:18:23,656 and the challenge this fellow laid 397 00:18:23,656 --> 00:18:26,326 down is once you start running this, you see everyone 398 00:18:26,326 --> 00:18:29,386 in the room or the wireless vicinity who's actually using 399 00:18:29,386 --> 00:18:31,316 Facebook, or Google, or the like. 400 00:18:31,636 --> 00:18:34,736 And with the simple double click on any one of these names bam, 401 00:18:34,736 --> 00:18:37,616 in that browser window would be Ian Gallagher's [phonetic] 402 00:18:37,616 --> 00:18:40,806 Facebook account or Eric's Google account or the like. 403 00:18:41,146 --> 00:18:43,976 And the reason behind this derives from these-- 404 00:18:44,056 --> 00:18:45,766 the use of websites of cookies. 405 00:18:45,826 --> 00:18:47,556 Something you're probably generally familiar with. 406 00:18:47,556 --> 00:18:50,196 And we'll talk about in more detail towards term's end. 407 00:18:50,456 --> 00:18:53,326 But these cookies are not often kept particularly secure. 408 00:18:53,486 --> 00:18:57,706 A lot of websites do not have URLs that start with https, 409 00:18:58,186 --> 00:18:59,586 where the S denotes secure. 410 00:18:59,826 --> 00:19:02,266 And even those that do, only use it some of the time, 411 00:19:02,266 --> 00:19:03,776 Facebook itself included. 412 00:19:03,776 --> 00:19:05,716 In fact there was just a few months ago, 413 00:19:05,906 --> 00:19:09,506 that Facebook finally started offering the option site-wide 414 00:19:09,766 --> 00:19:12,716 to use HTTPS to ward off this threat. 415 00:19:12,886 --> 00:19:15,936 But as recently as last fall, there was a good several months 416 00:19:16,226 --> 00:19:19,116 where your best friend or your roommate might very well been 417 00:19:19,176 --> 00:19:21,916 seeing everything you were doing inside of you Facebook account 418 00:19:21,916 --> 00:19:24,136 or the like because it is incredibly easy 419 00:19:24,136 --> 00:19:26,016 to steal cookies. 420 00:19:26,216 --> 00:19:28,336 And that's a topic we'll discuss towards term's end. 421 00:19:28,336 --> 00:19:30,126 And we'll also discuss defenses 422 00:19:30,126 --> 00:19:31,606 against these kinds of mechanisms. 423 00:19:31,866 --> 00:19:34,806 But if you're sort of wide eyed at this moment like, 424 00:19:34,806 --> 00:19:37,906 my God it's that easy or it's this possible to do. 425 00:19:37,906 --> 00:19:40,086 Well one of the goals of this course is again, 426 00:19:40,086 --> 00:19:42,906 not just about computer science and not just about programming 427 00:19:43,146 --> 00:19:46,166 but to empower you to then make educated decisions 428 00:19:46,166 --> 00:19:49,476 and maybe you don't care that anyone around you could log 429 00:19:49,476 --> 00:19:51,666 in to your Facebook profile 'cause you don't really use it 430 00:19:51,666 --> 00:19:54,366 anyway, but at least that's a conscious decision 431 00:19:54,366 --> 00:19:55,816 and not just an accidental one 432 00:19:56,026 --> 00:19:58,976 because you don't understand how these technologies work. 433 00:19:59,096 --> 00:20:01,906 >> Another exploit that came to light 434 00:20:01,906 --> 00:20:04,506 or another security implication that came 435 00:20:04,506 --> 00:20:07,936 to light a few months back too, related to Apple and the iPhone. 436 00:20:07,936 --> 00:20:09,436 So Apple, if you actually read the 437 00:20:09,436 --> 00:20:12,976 like 23-page document you have to agree to just to use iTunes 438 00:20:12,976 --> 00:20:15,156 and listen to music, let alone use an iPhone, 439 00:20:15,406 --> 00:20:16,936 it actually does say somewhere in there 440 00:20:16,936 --> 00:20:18,886 that we actually log everywhere you're going. 441 00:20:19,176 --> 00:20:22,456 And we store all of this information in iTunes 442 00:20:22,456 --> 00:20:24,916 and we even upload this information to our servers. 443 00:20:25,156 --> 00:20:27,386 Now as an aside, there're actually a lot of benefits 444 00:20:27,386 --> 00:20:29,846 to all 500 of us walking around the world 445 00:20:30,076 --> 00:20:32,106 with GPS transponders in our pockets. 446 00:20:32,106 --> 00:20:33,766 If we have iPhones or androids or any 447 00:20:33,766 --> 00:20:35,216 of these moderns smartphones 448 00:20:35,506 --> 00:20:39,416 because then we can provide useful services to us 449 00:20:39,416 --> 00:20:41,996 like what's near by me, Google Maps, these kinds of things. 450 00:20:41,996 --> 00:20:43,796 So there's a compelling user case for this. 451 00:20:44,146 --> 00:20:46,286 But what happens in this case a few months back, 452 00:20:46,516 --> 00:20:49,376 was apple accidentally or unknowingly 453 00:20:49,376 --> 00:20:53,426 or consciously was not encrypting the GPS coordinates 454 00:20:53,426 --> 00:20:56,586 of everywhere you and in turn your phone had been. 455 00:20:56,726 --> 00:20:58,246 And so this is minor worry [inaudible] 'cause 456 00:20:58,246 --> 00:21:00,016 if anyone has physical access 457 00:21:00,016 --> 00:21:03,256 to your computer whether it's a roommate or spouse or children 458 00:21:03,256 --> 00:21:05,126 or parents, well, they could-- 459 00:21:05,476 --> 00:21:07,506 they could certainly just start poking around. 460 00:21:07,506 --> 00:21:08,746 They could run this free tool 461 00:21:08,746 --> 00:21:11,156 which is again it was another proof of concept 462 00:21:11,206 --> 00:21:13,766 to demonstrate just how easy it is to do these things 463 00:21:14,036 --> 00:21:16,246 and how scary it is scary it is if you don't understand. 464 00:21:16,546 --> 00:21:19,366 Well, this will plot on the map absolutely everywhere you have 465 00:21:19,406 --> 00:21:21,496 been because this file was on encrypted. 466 00:21:21,496 --> 00:21:23,926 And so I actually did this on my phone out of curiosity. 467 00:21:23,926 --> 00:21:26,556 I ran this free program on my own installation of iTunes 468 00:21:26,776 --> 00:21:28,866 and what it generates for you is this nice map. 469 00:21:29,286 --> 00:21:32,016 And these big blue dots represents proportional 470 00:21:32,016 --> 00:21:35,696 to their size where I spent over that past year or two most 471 00:21:35,696 --> 00:21:37,596 of my time and you can see I spent a lot of time 472 00:21:37,596 --> 00:21:39,456 in the Northeast around Cambridge and such. 473 00:21:39,696 --> 00:21:42,376 I apparently went to Texas and somewhere in Pennsylvania 474 00:21:42,636 --> 00:21:43,726 as well as California. 475 00:21:44,016 --> 00:21:47,696 The tiny little red dot at top left there, anyone had a hunch 476 00:21:47,696 --> 00:21:50,756 as to why that one is so small relative to the others? 477 00:21:52,376 --> 00:21:54,956 So was actually just a layover in an airplane. 478 00:21:54,956 --> 00:21:57,636 When my phone actually got reception once we had a layover, 479 00:21:57,636 --> 00:22:00,026 I got out in the terminal, viola, Apple knows where I am, 480 00:22:00,026 --> 00:22:02,496 get back in the plane and they see me again ones I hit Texas 481 00:22:02,756 --> 00:22:04,206 or the East Coast. 482 00:22:04,206 --> 00:22:05,816 Well, if you zoom in on this it's one thing 483 00:22:05,816 --> 00:22:06,976 that kinda see these big blotches, 484 00:22:07,336 --> 00:22:09,966 most people in the world could guess I have spend a lot of time 485 00:22:09,966 --> 00:22:11,846 in Cambridge but if you really dive in, 486 00:22:11,846 --> 00:22:13,596 you just see how granular this is. 487 00:22:13,756 --> 00:22:15,476 So this is the greater Boston area 488 00:22:15,476 --> 00:22:18,816 and the dark splotch does indeed kind of overlap with Boston 489 00:22:18,816 --> 00:22:21,486 and Cambridge and I apparently spent sometime in the suburbs 490 00:22:21,486 --> 00:22:22,486 but not all that much. 491 00:22:22,706 --> 00:22:24,826 But you can see now the concentration of my time. 492 00:22:25,116 --> 00:22:28,356 I also happened to do a lot of work for a startup in New York 493 00:22:28,356 --> 00:22:30,326 and so I take the train and truck back 494 00:22:30,326 --> 00:22:31,706 and forth along the East Coast, 495 00:22:31,876 --> 00:22:33,586 and sure enough, Apple new that too. 496 00:22:34,206 --> 00:22:37,756 So at top right there, that's Boston up there, 497 00:22:37,876 --> 00:22:39,826 at the bottom left is Manhattan, 498 00:22:39,826 --> 00:22:41,676 in the middle there is Stanford Connecticut 499 00:22:41,676 --> 00:22:44,456 where Amtrak lets off and we typically pick up a rental car. 500 00:22:44,646 --> 00:22:46,306 And you can see that I've occasionally vacationed 501 00:22:46,306 --> 00:22:49,056 on Cape Cod which is that little hook shape thing going 502 00:22:49,056 --> 00:22:50,756 out into the Atlantic Ocean. 503 00:22:50,756 --> 00:22:53,076 And so, it was cool on the one hand, 504 00:22:53,076 --> 00:22:55,456 it was also a little worrisome, when I had no recollection 505 00:22:55,456 --> 00:22:58,166 of being in Pennsylvania and apparently my phone had been. 506 00:22:58,166 --> 00:22:59,976 And then finally, I figured it 507 00:22:59,976 --> 00:23:03,736 out that I was just visiting some university folks there. 508 00:23:04,056 --> 00:23:06,906 So this sort of stuff, these sorts of risks are all 509 00:23:06,906 --> 00:23:09,366 around us, and so by semester's end, not only will you know how 510 00:23:09,366 --> 00:23:13,366 to do things as those images and videos of your predecessors 511 00:23:13,366 --> 00:23:15,536 to pick, you'll also understand these things. 512 00:23:15,536 --> 00:23:18,446 So that even 50 is in fact the terminal course for you in CS, 513 00:23:18,866 --> 00:23:20,546 you're better equipped in the real world just 514 00:23:20,546 --> 00:23:22,896 to make smart decisions when it comes to your own phone, 515 00:23:23,146 --> 00:23:26,386 let alone policy and business decisions moving forward. 516 00:23:26,926 --> 00:23:31,286 So, with that said, I thought we would come back to this issue 517 00:23:31,536 --> 00:23:33,406 of the program we wrote on Wednesday 518 00:23:33,406 --> 00:23:34,976 that didn't really turn out so well. 519 00:23:34,976 --> 00:23:37,336 There were clearly some opportunities for improvements. 520 00:23:37,336 --> 00:23:40,706 And recall that the program that we wrote collectively as a class 521 00:23:41,196 --> 00:23:45,006 or as the volunteer gave us his form was this five-step program. 522 00:23:45,306 --> 00:23:48,156 And odds are, if you kind of reflected on the steps, 523 00:23:48,156 --> 00:23:49,656 you yourself wrote on Wednesday, 524 00:23:49,836 --> 00:23:51,826 well yours was probably relatively 525 00:23:51,826 --> 00:23:54,836 as short somewhat cursory maybe even incomplete. 526 00:23:54,966 --> 00:23:57,716 And granted if we gave you more than 60 or 120 seconds, 527 00:23:57,716 --> 00:23:59,656 maybe you'd have come up with something a little more 528 00:23:59,756 --> 00:24:00,326 fleshed out. 529 00:24:00,766 --> 00:24:02,876 But the reality is there're probably a lot 530 00:24:02,876 --> 00:24:04,536 of things you didn't in fact consider. 531 00:24:04,536 --> 00:24:06,206 And they're representative of the type-- 532 00:24:06,316 --> 00:24:08,186 the types of things you need to consider 533 00:24:08,416 --> 00:24:10,776 when commanding a computer to do something. 534 00:24:10,776 --> 00:24:12,196 So for instance, and if Rob, 535 00:24:12,196 --> 00:24:13,576 you could join me up here for a moment. 536 00:24:13,866 --> 00:24:18,456 What's was one of the most obvious flaws in step one? 537 00:24:18,456 --> 00:24:20,436 Take two slices bread from the loaf, 538 00:24:20,606 --> 00:24:22,506 what is that clearly assuming as Rob 539 00:24:22,556 --> 00:24:25,396 so professionally demonstrated yesterday? 540 00:24:26,596 --> 00:24:28,206 >> It's a loaf with sliced bread. 541 00:24:28,276 --> 00:24:30,026 >> So it's a loaf with sliced bread, right? 542 00:24:30,026 --> 00:24:32,686 So with this-- okay, so here is the loaf and we were-- 543 00:24:32,786 --> 00:24:34,186 we told you're allowed to assume. 544 00:24:34,186 --> 00:24:36,116 You have a jar of each of these things, a knife, 545 00:24:36,116 --> 00:24:39,116 and a loaf of bread, take two slices of bread from the loaf. 546 00:24:39,696 --> 00:24:40,696 You know, what is-- I mean, 547 00:24:40,696 --> 00:24:42,506 as you saw as from our volunteers ripped 548 00:24:42,506 --> 00:24:45,796 into to this thing because what does it mean to take two slices 549 00:24:45,796 --> 00:24:46,926 from this loaf, right? 550 00:24:46,926 --> 00:24:47,506 So what would be better? 551 00:24:47,506 --> 00:24:49,576 What would be a marginal improvement if we wanna go back 552 00:24:49,986 --> 00:24:53,286 and actually improve this with a better step one? 553 00:24:54,506 --> 00:24:56,036 Okay, so open the package. 554 00:24:56,226 --> 00:24:59,506 Well, let me just play kind of-- okay so open the package. 555 00:25:00,006 --> 00:25:02,626 So now we do this and I turn the little twisty thing 556 00:25:02,626 --> 00:25:04,876 and we can assume certain things otherwise this will very quickly 557 00:25:04,876 --> 00:25:06,436 devolve into complete tedium. 558 00:25:06,436 --> 00:25:09,166 So we know we can assume that I know how to open the bag. 559 00:25:09,376 --> 00:25:11,936 But now we've kind of written slightly flawed program, right. 560 00:25:11,936 --> 00:25:15,036 What if I make my sandwich and I then decide 561 00:25:15,036 --> 00:25:17,156 to make another sandwich, what am I now assuming? 562 00:25:17,156 --> 00:25:18,006 [ Inaudible Remarks ] 563 00:25:18,006 --> 00:25:19,426 >> It's already open, right. 564 00:25:19,426 --> 00:25:22,256 And I better say close the bag at the end of the program 565 00:25:22,256 --> 00:25:25,506 or maybe I should say something like, "If bag is closed, 566 00:25:25,746 --> 00:25:27,196 then opened bag, right." 567 00:25:27,196 --> 00:25:29,246 I wanna actually make an intelligent decision 568 00:25:29,436 --> 00:25:31,786 that takes us input, the state of my world to the state 569 00:25:31,786 --> 00:25:35,406 of the loaf of bread and then decide if in only if it's closed 570 00:25:35,636 --> 00:25:36,986 to open the bag, alright. 571 00:25:36,986 --> 00:25:39,416 So notice what's Rob is doing here is gonna be a little 572 00:25:39,416 --> 00:25:40,596 something called pseudocode. 573 00:25:40,596 --> 00:25:41,806 And it will get us into the habit 574 00:25:41,806 --> 00:25:44,576 of thinking more algorithmically, more carefully, 575 00:25:44,576 --> 00:25:47,016 more procedurally which for today's purpose is can 576 00:25:47,016 --> 00:25:47,666 be synonymous. 577 00:25:47,976 --> 00:25:50,586 So he's doing this little thing of indentation just 578 00:25:50,586 --> 00:25:53,596 to make clear that you only open the bag if the thing that's 579 00:25:53,596 --> 00:25:57,176 above it and slightly to the left is actually true, 580 00:25:57,176 --> 00:25:58,846 or is actually the case in reality. 581 00:25:59,016 --> 00:26:01,816 Alright, so now if bag is close, I opened it, otherwise, 582 00:26:01,816 --> 00:26:02,936 it's presumably just open. 583 00:26:02,936 --> 00:26:03,536 Now, what do I do? 584 00:26:05,096 --> 00:26:09,906 Let's start making the sandwich more properly. 585 00:26:10,216 --> 00:26:10,636 Yeah? 586 00:26:10,636 --> 00:26:10,936 [ Inaudible Remark ] 587 00:26:10,936 --> 00:26:11,236 >> Okay. 588 00:26:11,236 --> 00:26:12,246 [ Inaudible Remark ] 589 00:26:12,246 --> 00:26:14,656 >> Okay, good. 590 00:26:14,716 --> 00:26:17,386 So if loaf is sliced then take two slices. 591 00:26:17,676 --> 00:26:19,606 And again, just to be a little nitpicky here. 592 00:26:19,726 --> 00:26:21,996 You know, there's nothing saying I should be taking the bread 593 00:26:21,996 --> 00:26:23,366 from the open end of the bag. 594 00:26:23,366 --> 00:26:25,296 So there's another opportunity for improvement. 595 00:26:25,536 --> 00:26:26,666 But I can kinda push back 596 00:26:26,666 --> 00:26:29,706 on this one other else slice bread into-- 597 00:26:29,706 --> 00:26:31,536 slice loaf into slices, right. 598 00:26:31,816 --> 00:26:33,956 Like we kinda need to do something before that, right? 599 00:26:35,026 --> 00:26:37,886 Suppose that it is not sliced, what do I obviously need 600 00:26:37,886 --> 00:26:40,476 to do first before slicing this thing? 601 00:26:40,556 --> 00:26:41,836 So remove loaf from bag. 602 00:26:41,836 --> 00:26:43,016 So we might do that. 603 00:26:43,196 --> 00:26:45,296 But now, let's-- because this is pretty sliced, let's go back 604 00:26:45,296 --> 00:26:47,536 to the other condition and let's start to record both of these. 605 00:26:47,536 --> 00:26:51,696 So if loaf is already sliced, remove two slices from bag, 606 00:26:51,886 --> 00:26:55,156 from open end, it is fairly precise, else. 607 00:26:55,436 --> 00:26:57,166 So now let's introduce a fork in the road. 608 00:26:57,166 --> 00:26:59,706 Be previously we did something if something was true, 609 00:26:59,706 --> 00:27:01,256 but there was really no alternative. 610 00:27:01,256 --> 00:27:03,316 This time it kinda makes sense to have an alternative. 611 00:27:03,446 --> 00:27:06,636 So if loaf is already sliced, then remove two slices 612 00:27:06,636 --> 00:27:11,516 from the open bag, else, what do I wanna do? 613 00:27:11,516 --> 00:27:11,766 [ Inaudible Remark ] 614 00:27:11,766 --> 00:27:12,036 >> Sorry. 615 00:27:12,036 --> 00:27:12,926 [ Inaudible Remark ] 616 00:27:12,926 --> 00:27:15,816 >> Okay, so get a knife at some points and still, else, 617 00:27:15,816 --> 00:27:17,296 if it isn't sliced, what needs 618 00:27:17,326 --> 00:27:19,686 to happen first before I start slicing this bread? 619 00:27:20,466 --> 00:27:20,676 Yeah. 620 00:27:20,676 --> 00:27:21,136 [ Inaudible Remarks ] 621 00:27:21,136 --> 00:27:22,836 >> Remove bread from bag. 622 00:27:22,916 --> 00:27:25,186 So I would actually slide all of the bread out 623 00:27:25,186 --> 00:27:26,946 and then I could probably proceed 624 00:27:26,946 --> 00:27:27,986 to use this part of the knife. 625 00:27:28,056 --> 00:27:30,706 So now we're getting somewhere. 626 00:27:30,706 --> 00:27:34,106 So we've introduced what we'll call conditions, or branches, 627 00:27:34,106 --> 00:27:37,496 or decision points really in the real world. 628 00:27:37,496 --> 00:27:39,366 So now what we-- what might we do here? 629 00:27:39,366 --> 00:27:40,466 At this point in the story, 630 00:27:40,736 --> 00:27:42,826 we have removed potentially the bread from the bag 631 00:27:42,826 --> 00:27:46,616 and let's just put one more statement also indented cuts two 632 00:27:46,616 --> 00:27:48,486 slices of bread from loaf. 633 00:27:48,486 --> 00:27:49,956 Now here too, we could be nitpicky, 634 00:27:49,956 --> 00:27:51,496 I could cut a slice that's this big 635 00:27:51,496 --> 00:27:53,386 and be completely ridiculous unless you start 636 00:27:53,386 --> 00:27:54,896 to make some more forward progress here. 637 00:27:55,116 --> 00:27:57,316 But notice what Rob has done in pseudocode, 638 00:27:57,576 --> 00:28:00,536 both of these lines removed and cut or indented 639 00:28:00,766 --> 00:28:03,596 and this suggests that both of those things should now happen 640 00:28:03,746 --> 00:28:07,866 if the decision that we just made if it isn't sliced is true. 641 00:28:07,956 --> 00:28:10,716 So again, an example of logical flow here. 642 00:28:10,886 --> 00:28:12,446 Well let's try to wrap this one up now. 643 00:28:12,446 --> 00:28:17,846 So if we have at this point two slices of bread in hand, 644 00:28:17,976 --> 00:28:19,816 now what we-- now what should we do? 645 00:28:21,056 --> 00:28:21,166 Yeah. 646 00:28:22,026 --> 00:28:23,026 >> Put them on the table. 647 00:28:23,136 --> 00:28:23,936 >> Put them on the table. 648 00:28:24,116 --> 00:28:28,596 Okay. It could be better, but it's alright. 649 00:28:28,676 --> 00:28:31,776 So, you know, separately or some such adverb. 650 00:28:32,336 --> 00:28:33,606 What's next? 651 00:28:33,606 --> 00:28:34,526 [ Inaudible Remarks ] 652 00:28:34,526 --> 00:28:35,536 >> Okay, open-- right. 653 00:28:35,676 --> 00:28:39,146 And so this was the key point missing yesterday, right? 654 00:28:39,146 --> 00:28:40,686 Open the jar of peanut butter. 655 00:28:40,686 --> 00:28:42,196 That sort of something we took for granted. 656 00:28:42,196 --> 00:28:43,866 If this is the first time using it, 657 00:28:43,866 --> 00:28:46,256 here's another possible corner case so to speak. 658 00:28:46,256 --> 00:28:48,846 And this is a piece of jargon we'll often use in programming. 659 00:28:49,086 --> 00:28:51,356 Corner case is sort of a situation that, you know, 660 00:28:51,356 --> 00:28:52,496 make sense that it might happen 661 00:28:52,496 --> 00:28:53,786 but you didn't really think about it. 662 00:28:53,946 --> 00:28:55,446 And even though it might only happen one 663 00:28:55,446 --> 00:28:58,486 out of a hundred times, that one time it does happen, right, 664 00:28:58,486 --> 00:29:00,146 you're not gonna be able to get any peanut butter 665 00:29:00,146 --> 00:29:03,256 out of it unless you have another condition or branch. 666 00:29:03,506 --> 00:29:05,656 So let's go ahead and say, open the jar of peanut butter; 667 00:29:05,936 --> 00:29:08,936 if sealed, remove seal or something like that. 668 00:29:08,936 --> 00:29:11,606 And so that gets me to the point of conditionally doing this. 669 00:29:12,126 --> 00:29:14,416 So now I have the opened peanut butter, I have my two slices 670 00:29:14,416 --> 00:29:16,506 of bread separately what's next? 671 00:29:16,506 --> 00:29:17,836 [ Inaudible Remark ] 672 00:29:17,836 --> 00:29:19,056 >> Pick up knife? 673 00:29:19,556 --> 00:29:22,776 [ Inaudible Remark ] 674 00:29:23,276 --> 00:29:24,326 >> Or put it-- sorry? 675 00:29:24,326 --> 00:29:26,046 [ Inaudible Remark ] 676 00:29:26,046 --> 00:29:29,336 >> Put knife in peanut butter? 677 00:29:29,336 --> 00:29:29,536 [ Inaudible Remark ] 678 00:29:29,536 --> 00:29:30,716 >> Scoop out peanut butter? 679 00:29:30,716 --> 00:29:33,076 Right, this is very quickly gonna devolved 680 00:29:33,076 --> 00:29:34,676 into yesterday, right. 681 00:29:34,676 --> 00:29:37,026 Scoop out-- At least we got this part yesterday, right? 682 00:29:37,026 --> 00:29:39,006 Scoop out two table spoons of peanut butter. 683 00:29:39,006 --> 00:29:40,186 So let's go ahead and do that. 684 00:29:40,186 --> 00:29:45,556 So, scoop out two tea spoons of peanut butter and then? 685 00:29:45,556 --> 00:29:45,836 [ Inaudible Remark ] 686 00:29:45,836 --> 00:29:47,206 >> Spread it on piece of bread. 687 00:29:47,206 --> 00:29:50,096 But again, here too, you know this kind of reasonable. 688 00:29:50,166 --> 00:29:51,866 Stupid but correct. 689 00:29:53,296 --> 00:29:56,546 Or at least consistent with what you told me to do, so here too. 690 00:29:56,776 --> 00:29:59,166 So again, we don't need to turn this into the complete drama 691 00:29:59,166 --> 00:29:59,976 that we had yesterday. 692 00:30:00,286 --> 00:30:03,806 >> But just notice all of the various opportunities there are 693 00:30:03,806 --> 00:30:06,716 to make mistakes, all of these possible corner cases, 694 00:30:06,896 --> 00:30:08,526 and so one of the things that's a little tougher, 695 00:30:08,526 --> 00:30:10,536 a lot of people with programming initially is 696 00:30:10,536 --> 00:30:12,456 that you just kinda want this computer to behave 697 00:30:12,456 --> 00:30:15,936 as through it's a human just responding and interpreting 698 00:30:15,936 --> 00:30:17,666 with their best human judgment, your command. 699 00:30:17,896 --> 00:30:20,126 But the reality is that's not gonna happen and we're gonna see 700 00:30:20,126 --> 00:30:22,636 that today with our own programs. 701 00:30:22,636 --> 00:30:24,486 So thanks very much to Rob. 702 00:30:25,076 --> 00:30:25,756 Very well done. 703 00:30:26,516 --> 00:30:30,886 [ Applause ] 704 00:30:31,386 --> 00:30:32,966 >> Let's see if we can now translate. 705 00:30:32,966 --> 00:30:34,116 Well, again, we'll call pseudocode. 706 00:30:34,116 --> 00:30:36,546 And to be clear pseudocode is something that akin to English. 707 00:30:36,546 --> 00:30:38,136 It's not a programing language. 708 00:30:38,136 --> 00:30:39,196 It's not really English. 709 00:30:39,336 --> 00:30:41,546 It's some amalgam of the two and there's no one's standard. 710 00:30:41,546 --> 00:30:44,656 You just kinda go with your instincts and write out words 711 00:30:44,656 --> 00:30:46,096 that kind of communicate your idea. 712 00:30:46,096 --> 00:30:48,286 But when you're actually commanding a computer, 713 00:30:48,446 --> 00:30:49,866 you're actually gonna write something like this 714 00:30:49,866 --> 00:30:52,546 and we saw this in a slightly different screen on Wednesday. 715 00:30:52,546 --> 00:30:54,946 It was a little color coded but this is perhaps one 716 00:30:54,946 --> 00:30:58,516 of the simplest programs you can write that a computer can run 717 00:30:58,516 --> 00:31:01,686 in this language called C. So this is the language 718 00:31:01,686 --> 00:31:02,546 in which we'll spend a lot 719 00:31:02,546 --> 00:31:06,366 of our time transitioning ultimately the PHP and HTML 720 00:31:06,496 --> 00:31:08,756 and CSS and SQL and various markup 721 00:31:08,756 --> 00:31:10,876 and programming languages, but for now we have this. 722 00:31:10,876 --> 00:31:13,536 And there's gonna be a lot of cryptic details here. 723 00:31:13,536 --> 00:31:15,426 These include the angle brackets, 724 00:31:15,466 --> 00:31:17,146 the parenthesis, the curly braces. 725 00:31:17,416 --> 00:31:19,006 This is one of the challenges early 726 00:31:19,006 --> 00:31:20,326 on for those less comfortable 727 00:31:20,326 --> 00:31:22,146 and that there's all this crazy syntax. 728 00:31:22,216 --> 00:31:24,756 And the frustrating thing about computers is that even 729 00:31:24,756 --> 00:31:27,876 if you do something stupid and, you know, not even unreasonable 730 00:31:28,106 --> 00:31:30,666 like leave off the semicolon 'cause you forgot 731 00:31:30,666 --> 00:31:32,786 or you hit a colon or some other character instead, 732 00:31:32,786 --> 00:31:36,336 the whole thing is gonna break whether it's 5 or 6 lines 733 00:31:36,336 --> 00:31:38,956 or 5 million lines, a single flaw 734 00:31:38,956 --> 00:31:41,346 like that can derail an entire program. 735 00:31:41,596 --> 00:31:43,916 And know now that these are the kinds of silly things 736 00:31:43,916 --> 00:31:46,966 that you do tend to trip up-- trip over early on. 737 00:31:46,966 --> 00:31:48,476 But these are the kinds of things that you start 738 00:31:48,476 --> 00:31:50,326 to spot spontaneously. 739 00:31:50,326 --> 00:31:52,856 And so you'll find over the next 12 weeks that your-- 740 00:31:53,056 --> 00:31:55,826 the types of mistakes that you make become increasingly 741 00:31:55,826 --> 00:31:57,646 sophisticated and that's a good thing 742 00:31:57,906 --> 00:32:00,536 and they become increasingly interesting to solve 743 00:32:00,536 --> 00:32:02,566 as you begin to speak this language 744 00:32:02,566 --> 00:32:03,916 like you would of foreign language. 745 00:32:04,136 --> 00:32:06,976 Unfortunately computers don't really speak this language. 746 00:32:06,976 --> 00:32:10,766 This thing C is what we'll call a high level language 747 00:32:11,006 --> 00:32:13,806 because it's pretty close to a human's conversation. 748 00:32:13,986 --> 00:32:16,586 Alright, this is still English word, a few new things like int. 749 00:32:16,646 --> 00:32:17,786 I'm not really sure what that is. 750 00:32:18,076 --> 00:32:21,106 Integer it turns out, but it's still readable by a human. 751 00:32:21,106 --> 00:32:22,316 And this wasn't always the case. 752 00:32:22,316 --> 00:32:24,796 If you heard about things like punch cards in the like, 753 00:32:24,886 --> 00:32:28,806 programming was not always so relatively human friendly 754 00:32:29,066 --> 00:32:31,686 because at the end of the day computers still only understand 755 00:32:31,916 --> 00:32:32,666 things like this. 756 00:32:33,216 --> 00:32:35,316 So you might know just in generally 757 00:32:35,316 --> 00:32:38,816 that computer somehow operate in 0s and 1s and that's useful 758 00:32:38,816 --> 00:32:42,706 because 0s and 1s, very nicely map to electrical things, right? 759 00:32:42,706 --> 00:32:44,466 Right now in sanders, the lights are on. 760 00:32:44,686 --> 00:32:47,866 We could say that this huge theater is actually storing the 761 00:32:47,866 --> 00:32:48,666 number 1. 762 00:32:48,956 --> 00:32:51,166 If we killed all of the lights it might be storing the 763 00:32:51,166 --> 00:32:51,996 number 0. 764 00:32:52,176 --> 00:32:56,746 And this is why we have such a simple system, a simple alphabet 765 00:32:56,746 --> 00:32:58,646 for computers because they're electrical. 766 00:32:58,646 --> 00:32:59,776 You plug them into the wall. 767 00:32:59,776 --> 00:33:00,816 They operate on batteries. 768 00:33:01,016 --> 00:33:04,526 You have disability to either have electricity flowing or not 769 00:33:04,836 --> 00:33:06,556 and that gives you these two binary. 770 00:33:06,556 --> 00:33:08,156 "Bi" meaning two states 771 00:33:08,346 --> 00:33:11,496 and so you can represent data, things in this way. 772 00:33:11,496 --> 00:33:14,716 Now these are literally the 0s and 1s that are created. 773 00:33:14,906 --> 00:33:16,566 When you start with the program like this, 774 00:33:17,056 --> 00:33:19,626 you run it to a little tool called a compiler, 775 00:33:19,896 --> 00:33:22,616 you get out 0s and 1s like this and these 0s 776 00:33:22,616 --> 00:33:24,216 and 1s are just stored in the file. 777 00:33:24,216 --> 00:33:28,216 Akin to any sort of MP3 or Microsoft Word file. 778 00:33:28,436 --> 00:33:30,706 They're just stored in some file on a computer. 779 00:33:30,706 --> 00:33:31,826 And when you double click it 780 00:33:31,826 --> 00:33:34,366 or run some text-based commands these 0s 781 00:33:34,366 --> 00:33:38,346 and 1s will be fed usually 8 at a time, 32 at a time, 782 00:33:38,346 --> 00:33:40,636 64 at a time into that thing called the CPU 783 00:33:40,636 --> 00:33:42,566 which you probably generally know is the brains 784 00:33:42,566 --> 00:33:45,546 of your computer and that CPU then does something. 785 00:33:45,546 --> 00:33:49,586 And in this case it might print to the screen, "Oh, hi, world." 786 00:33:49,916 --> 00:33:52,156 Well now how do you actually get from all of these 0s 787 00:33:52,156 --> 00:33:53,506 and 1s to useful data? 788 00:33:53,996 --> 00:33:55,996 Well, it's actually relatively straightforward. 789 00:33:56,186 --> 00:33:58,856 So I'm just gonna open up again a simple little text document 790 00:33:58,886 --> 00:34:02,946 here just so we have something to type with and it turns 791 00:34:02,946 --> 00:34:07,466 out that if I want to represent the number we humans know as 0 792 00:34:07,676 --> 00:34:09,996 in binary, otherwise known as base 2. 793 00:34:10,176 --> 00:34:13,936 Well, the world has decided that 0 for a computer means 0 794 00:34:13,936 --> 00:34:15,486 to a human, so pretty simple. 795 00:34:15,716 --> 00:34:17,336 Well, if we wanna do the number 1. 796 00:34:17,336 --> 00:34:18,836 It's actually pretty simple. 797 00:34:19,036 --> 00:34:21,336 Unfortunately, now we're out of digits, right? 798 00:34:21,336 --> 00:34:25,606 The alphabet is only so expressive so now using only 0s 799 00:34:25,606 --> 00:34:26,996 and 1s we have to somehow be able 800 00:34:26,996 --> 00:34:30,156 to encode what we humans know is the number 2, otherwise, 801 00:34:30,156 --> 00:34:32,136 this is gonna be the most useless computer ever 802 00:34:32,306 --> 00:34:34,186 if the best it can do is count up to 1. 803 00:34:34,476 --> 00:34:35,536 Surely we can do better. 804 00:34:35,886 --> 00:34:37,286 So what can we do? 805 00:34:37,556 --> 00:34:39,316 Well, much like in the real world 806 00:34:39,316 --> 00:34:42,506 when you need another digit, you add 9 plus 2. 807 00:34:42,506 --> 00:34:45,076 Well 9 plus 2, what do you do when you kind 808 00:34:45,076 --> 00:34:45,956 of do that in grade school? 809 00:34:45,956 --> 00:34:48,356 You put a-- You carry the 1, right? 810 00:34:48,356 --> 00:34:49,466 So you get another column. 811 00:34:49,736 --> 00:34:51,056 We can do the same thing here. 812 00:34:51,256 --> 00:34:54,206 So to represent the number 2, why don't we do something 813 00:34:54,206 --> 00:34:57,416 like 1-0, and the number 3, 1-1. 814 00:34:57,596 --> 00:34:59,906 And now just to make things lined up prettily, 815 00:35:00,126 --> 00:35:03,016 let's just assume that every number in the world uses 2 bits 816 00:35:03,016 --> 00:35:05,126 and a bit is just a 0 or a 1. 817 00:35:05,186 --> 00:35:06,376 Binary digit, bit. 818 00:35:06,826 --> 00:35:10,406 So now using 0s and 1s I can represent what we humans think 819 00:35:10,406 --> 00:35:13,606 of as 0 and 1 and 2 and 3, 820 00:35:13,646 --> 00:35:15,686 and take a guess what's the number 4 gonna be 821 00:35:15,686 --> 00:35:16,436 represented with? 822 00:35:17,596 --> 00:35:18,946 Yeah, 1-0-0. 823 00:35:19,126 --> 00:35:20,856 And now I can go back and clean this up. 824 00:35:21,166 --> 00:35:23,976 To much like in the real world, you can have as many 0s 825 00:35:23,976 --> 00:35:25,216 to the left of some number. 826 00:35:25,216 --> 00:35:28,366 It makes no material difference, same thing with a computer here. 827 00:35:28,596 --> 00:35:32,076 But in reality computers do use some fixed number of bits. 828 00:35:32,476 --> 00:35:35,266 So anytime you store a number or a letter in a computer, 829 00:35:35,436 --> 00:35:39,846 it's almost always using, say, 8 bits at a time or 16 or 32 830 00:35:39,846 --> 00:35:42,806 or 64, generally, some multiple of 2. 831 00:35:42,806 --> 00:35:44,136 There conventions that we'll see. 832 00:35:44,406 --> 00:35:46,756 But this is precisely the same idea. 833 00:35:47,236 --> 00:35:52,136 Now how if you were given a number like let's say 1-1-1. 834 00:35:52,136 --> 00:35:56,796 How do you get from 1-1-1 to the decimal, the base 10 equivalent, 835 00:35:56,796 --> 00:35:58,906 just the real world expression of that number? 836 00:35:59,186 --> 00:36:01,936 Well, think of it how we do this in the real world. 837 00:36:02,096 --> 00:36:04,516 If I just gonna-- let me just move my cursor over here. 838 00:36:04,796 --> 00:36:08,596 If you have the number like 123 in the real world, well, 839 00:36:08,596 --> 00:36:12,306 how do this series of digits, 1, 2, 3, 840 00:36:12,556 --> 00:36:15,666 translate into conceptually what we know as 123? 841 00:36:15,876 --> 00:36:16,826 Well, again, if you think back 842 00:36:16,826 --> 00:36:18,916 to grade school this is ones column 843 00:36:19,206 --> 00:36:23,856 and this is the tens column and this is the hundreds column, 844 00:36:24,076 --> 00:36:26,136 and now let me just space this out so that they kind 845 00:36:26,136 --> 00:36:27,356 of not line up nicely. 846 00:36:27,586 --> 00:36:29,026 So how do you get from 1, 2, 847 00:36:29,086 --> 00:36:32,136 3 to what we conceptually think of as 123? 848 00:36:32,406 --> 00:36:36,186 Well, in the ones column we have 3 so that's 1 times 3. 849 00:36:36,556 --> 00:36:39,186 In the tens column we have a 2, so that's 10 times 2. 850 00:36:39,186 --> 00:36:42,276 In one hundreds column we have a 1 so that's 100 times 1. 851 00:36:42,506 --> 00:36:45,196 Add all those up, 100 plus 20 plus 3. 852 00:36:45,366 --> 00:36:48,756 Viola! You get this notion of 123. 853 00:36:49,086 --> 00:36:51,016 So now let's go back to this challenge. 854 00:36:51,016 --> 00:36:53,846 We kind of figured this out just by working our way up. 855 00:36:53,846 --> 00:36:55,296 Let's now work our way backwards. 856 00:36:55,296 --> 00:36:58,746 If we start with 1-1-1, how does the binary system work? 857 00:36:58,746 --> 00:37:01,686 Well in the binary system, the system that computers use, 858 00:37:01,896 --> 00:37:04,636 we actually start with, thankfully, the ones column. 859 00:37:05,066 --> 00:37:06,926 But it's not the tens column that comes next, 860 00:37:07,026 --> 00:37:10,706 it's the twos column and after that it's the fours column. 861 00:37:11,076 --> 00:37:15,496 And so whereas in the real world of base 10 and decimal, 862 00:37:15,496 --> 00:37:18,916 the columns-- the columns represent powers of 10, 863 00:37:19,176 --> 00:37:21,426 in the binary world, binary again meaning two, 864 00:37:21,426 --> 00:37:22,816 it's just powers of 2. 865 00:37:22,916 --> 00:37:23,736 It's as simple as that. 866 00:37:23,736 --> 00:37:26,126 So you have the ones column, the twos columns, the fours, 867 00:37:26,126 --> 00:37:29,356 the eight, sixteen, thirty two, sixty four, and so forth. 868 00:37:29,356 --> 00:37:31,326 And so now we have the ability to express numbers 869 00:37:31,366 --> 00:37:32,336 in just the different way. 870 00:37:32,336 --> 00:37:36,776 But the advantage is we don't need 0 and 1 and 2 and 3 and 4 871 00:37:36,776 --> 00:37:40,236 and 5 and say, all of these-- we don't need 10 different digits. 872 00:37:40,466 --> 00:37:43,176 All we need is to turn the power on or turn it off. 873 00:37:43,176 --> 00:37:46,006 And by doing that rapidly in sequence, we can build 874 00:37:46,006 --> 00:37:48,456 up some representation in electricity 875 00:37:48,936 --> 00:37:51,216 with numbers like this. 876 00:37:51,636 --> 00:37:54,336 So with that said, if I have a 1 in the fours column, 877 00:37:54,336 --> 00:37:56,796 a 1 in the twos column, and the 1 878 00:37:56,886 --> 00:37:59,016 in the ones column what does that now give me? 879 00:37:59,016 --> 00:37:59,676 [ Inaudible Remarks ] 880 00:37:59,676 --> 00:38:00,656 >> 7, right? 881 00:38:00,706 --> 00:38:04,126 1, 4 plus 1, 2 plus 1, 1, that gives me 7. 882 00:38:04,216 --> 00:38:06,576 And we can work our way up from there. 883 00:38:06,816 --> 00:38:08,786 So just to round this out, 884 00:38:09,416 --> 00:38:13,676 the reason that we often hear the term not so much bits 885 00:38:13,676 --> 00:38:17,176 in the real world but bytes, megabytes, gigabytes, terabytes 886 00:38:17,176 --> 00:38:19,526 and so forth is 'cause our single bit is actually pretty 887 00:38:19,526 --> 00:38:20,926 useless certainly these days 888 00:38:21,106 --> 00:38:22,946 and so somewhere along the way the world decided 889 00:38:22,946 --> 00:38:26,676 that it's more useful to express units of measure in terms 890 00:38:26,676 --> 00:38:28,356 of eight of these things so8 bits, 891 00:38:28,356 --> 00:38:31,886 eight 0s and/or 1s is what we call a byte. 892 00:38:32,356 --> 00:38:36,306 So if you have some crazy short like MP3 or music file 893 00:38:36,306 --> 00:38:38,556 on your computer that was just a single byte, 894 00:38:39,046 --> 00:38:40,026 obviously, unrealistic. 895 00:38:40,026 --> 00:38:41,206 They're usually millions of bytes. 896 00:38:41,476 --> 00:38:43,036 That would just mean there're 8 bits 897 00:38:43,036 --> 00:38:46,606 to compose whatever song you're very briefly listening to. 898 00:38:46,606 --> 00:38:49,846 And if it's 3 megabytes, that means you have 3 million bytes 899 00:38:50,196 --> 00:38:52,056 or really 24 million bits 900 00:38:52,056 --> 00:38:54,256 if you multiply the number of bytes by 8. 901 00:38:54,356 --> 00:38:56,406 So when we talk about a bytes worth 902 00:38:56,406 --> 00:38:58,556 of bits we have not just the ones, the twos, 903 00:38:58,556 --> 00:39:00,216 the fours column, we have all the way 904 00:39:00,216 --> 00:39:03,456 up to the one hundred twenty eights column there. 905 00:39:03,456 --> 00:39:06,166 So now, a little something silly 906 00:39:06,166 --> 00:39:07,746 like this might make some more sense. 907 00:39:08,516 --> 00:39:13,181 [ Noise ] 908 00:39:13,681 --> 00:39:18,346 [ Laughter ] 909 00:39:18,846 --> 00:39:20,126 >> We got through it at least 1. 910 00:39:20,166 --> 00:39:20,826 Excellent! 911 00:39:21,646 --> 00:39:24,176 So if it's not clicking, come back to it later 912 00:39:24,176 --> 00:39:27,546 but now perhaps even more comic books even will make sense. 913 00:39:27,636 --> 00:39:29,746 But numbers alone are not all that useful, right? 914 00:39:29,746 --> 00:39:32,086 The last-- You might use numbers in a computer 915 00:39:32,296 --> 00:39:34,696 but more likely these days you're sending instant messages 916 00:39:34,696 --> 00:39:37,196 or downloading photos or reading emails in the like. 917 00:39:37,456 --> 00:39:39,716 So the next step up from just numbers is probably 918 00:39:39,716 --> 00:39:40,906 something alphabetical. 919 00:39:40,906 --> 00:39:44,196 The ability to express yourself as a human in English or Spanish 920 00:39:44,196 --> 00:39:46,116 or whatever language, you need to be able 921 00:39:46,116 --> 00:39:49,116 to represent other symbols using though at the end 922 00:39:49,116 --> 00:39:50,246 of the day electricity. 923 00:39:50,246 --> 00:39:52,546 That's on or off, 0s or 1s. 924 00:39:52,686 --> 00:39:55,246 Well, thankfully the world years ago came up with a system 925 00:39:55,376 --> 00:39:57,156 and this chart actually looks more overwhelming 926 00:39:57,156 --> 00:39:57,816 that it needs to. 927 00:39:57,816 --> 00:39:59,646 It's just because there's a whole lot of information. 928 00:40:00,046 --> 00:40:03,396 >> Notice that you have the same two columns repeated again 929 00:40:03,396 --> 00:40:03,866 and again. 930 00:40:03,866 --> 00:40:06,516 Code and Char for character, code, char, 931 00:40:06,516 --> 00:40:07,786 code, char, code, char. 932 00:40:08,046 --> 00:40:10,876 So the way to read this is that at the top left, 933 00:40:11,156 --> 00:40:14,436 it says the number 32 and that's a decimal number 32, 934 00:40:14,776 --> 00:40:17,056 and that means that the space bar character 935 00:40:17,056 --> 00:40:20,166 on the keyboard is implemented inside of a computer 936 00:40:20,336 --> 00:40:23,106 by just storing the number 32. 937 00:40:23,166 --> 00:40:24,576 How do you store the number 32? 938 00:40:24,576 --> 00:40:26,276 Well you use some sequence of bits. 939 00:40:26,416 --> 00:40:28,876 Now how do we get to this sequence of bits of 32? 940 00:40:28,876 --> 00:40:31,296 Well, let me just again come to a place holder here. 941 00:40:31,296 --> 00:40:34,396 If I've got the ones column, the twos, the fours, the eights, 942 00:40:34,396 --> 00:40:37,226 the sixteens, the thirty-twos, I can kind of figure this out. 943 00:40:37,256 --> 00:40:40,616 This is the ones column, this is the twos column, the fours, 944 00:40:40,616 --> 00:40:43,636 eights, sixteen, thirty-two, wahla! 945 00:40:43,786 --> 00:40:46,786 If you wanna represent that space bar character in something 946 00:40:46,786 --> 00:40:48,986 like an e-mail or a Microsoft Word document, 947 00:40:49,196 --> 00:40:51,546 all the computer stores is the bits 10000 948 00:40:51,546 --> 00:40:56,836 and actually it probably uses at least a byte's worth. 949 00:40:56,836 --> 00:40:59,116 So this is one, two, three, four, five, six, 950 00:40:59,386 --> 00:41:01,196 so probably what it's really storing 951 00:41:01,196 --> 00:41:03,556 for the spacebar character is eight total bits 952 00:41:03,596 --> 00:41:05,346 but the first two are zeros. 953 00:41:05,726 --> 00:41:06,636 Now, the spacebar is kind 954 00:41:06,666 --> 00:41:08,566 of underwhelming 'cause you can't really even see it 955 00:41:08,566 --> 00:41:10,946 but if you look back at this chart and fast-forward 956 00:41:10,946 --> 00:41:14,056 to roughly the middle of the chart, what is the code, 957 00:41:14,056 --> 00:41:16,736 the decimal number for the letter capital A? 958 00:41:16,736 --> 00:41:21,696 Yeah, it's apparently 65 and if you scroll down to the rest 959 00:41:21,696 --> 00:41:24,986 of the chart, the lower case A is represented with what? 960 00:41:26,206 --> 00:41:27,266 97, right? 961 00:41:27,266 --> 00:41:28,706 So let's do the 65. 962 00:41:28,736 --> 00:41:31,436 Well, 65 is also pretty easy 'cause things line up nicely. 963 00:41:31,656 --> 00:41:34,146 So this is the spacebar character which we'll represent 964 00:41:34,146 --> 00:41:36,776 with this, even though that's a different character altogether. 965 00:41:37,016 --> 00:41:41,256 The capital A then is gonna have again eight bits typically, one, 966 00:41:41,256 --> 00:41:42,676 two, three, four, five, six, seven, 967 00:41:42,676 --> 00:41:45,136 eight but this time I need the number 65. 968 00:41:45,136 --> 00:41:48,626 So I have the ones column, the twos, the fours, the eights, 969 00:41:48,896 --> 00:41:50,446 sixteens, thrity-twos. 970 00:41:50,446 --> 00:41:53,926 Aha! 64, that's helpful but I need something else. 971 00:41:54,516 --> 00:41:56,146 This now needs to become a one. 972 00:41:56,406 --> 00:41:57,016 And so that's it. 973 00:41:57,016 --> 00:41:58,956 When you're hitting the letter A on your keyboard 974 00:41:58,956 --> 00:42:01,686 to do something completely simple like send and IM 975 00:42:01,686 --> 00:42:04,776 or send an e-mail, what's really being stored in that e-mail 976 00:42:04,776 --> 00:42:06,806 by your computer or in turn Gmail or the 977 00:42:06,806 --> 00:42:12,056 like is some sequence of bits, 0100001 and what you seen 978 00:42:12,056 --> 00:42:16,206 on the screen is the letter A. So, 979 00:42:16,556 --> 00:42:19,486 how do these things actually get stored in reality? 980 00:42:19,746 --> 00:42:22,386 Let's see if we can translate this idea of electricity 981 00:42:22,386 --> 00:42:23,936 to something that's a little more visual. 982 00:42:23,936 --> 00:42:26,506 Let me go ahead and open up a little demo here, 983 00:42:26,506 --> 00:42:29,166 and we can dim the lights just a bit if you don't mind, 984 00:42:29,626 --> 00:42:32,846 for this look inside of what's been inside your computer all 985 00:42:32,846 --> 00:42:33,416 these years. 986 00:42:33,416 --> 00:42:34,476 [ Background Music ] 987 00:42:34,476 --> 00:42:36,996 >> The hard drive is where your PC stores most 988 00:42:36,996 --> 00:42:38,116 of its permanent data. 989 00:42:38,706 --> 00:42:41,706 To do that, the data travels from RAM along 990 00:42:41,706 --> 00:42:44,306 with software signals that tell the hard drive how 991 00:42:44,306 --> 00:42:45,426 to store that data. 992 00:42:46,086 --> 00:42:48,616 The hard drive circuits translate those signals 993 00:42:48,616 --> 00:42:50,226 into voltage fluctuations. 994 00:42:50,956 --> 00:42:53,706 These in turn control the hard drive's moving parts, 995 00:42:54,296 --> 00:42:57,156 some of the few moving parts left in the modern computer. 996 00:42:57,926 --> 00:42:59,586 Some of the signals control a motor 997 00:42:59,586 --> 00:43:01,446 which spins metal coated platters. 998 00:43:02,166 --> 00:43:04,666 Your data is actually stored on these platters. 999 00:43:05,486 --> 00:43:08,536 Other signals move the read/write heads to read 1000 00:43:08,536 --> 00:43:09,996 or write data on the platters. 1001 00:43:10,746 --> 00:43:12,576 This machinery is so precise 1002 00:43:13,066 --> 00:43:15,716 that a human hair couldn't even pass between the heads 1003 00:43:15,716 --> 00:43:19,726 and spinning platters, yet it all works at terrific speeds. 1004 00:43:20,556 --> 00:43:23,136 >> So if you've even wondered why dropping a laptop is 1005 00:43:23,166 --> 00:43:24,976 generally a bad idea, it's because one 1006 00:43:24,976 --> 00:43:29,206 of the few remaining mechanical parts inside of a laptop is one, 1007 00:43:29,206 --> 00:43:31,216 the hard drive and two, the fan. 1008 00:43:31,216 --> 00:43:33,566 And that fan, is actually the cheap, easily replaceable one. 1009 00:43:33,566 --> 00:43:35,746 This thing is a bad break because obviously all 1010 00:43:35,746 --> 00:43:36,636 of your data is on it. 1011 00:43:36,916 --> 00:43:38,816 But we're also getting to the point as in a side 1012 00:43:38,846 --> 00:43:41,956 where hard drives that spin like this are increasingly passe. 1013 00:43:41,956 --> 00:43:46,986 In fact, a lot of you with Macs or relatively new PCs have SSD, 1014 00:43:47,066 --> 00:43:49,146 solid state drives, and what's nice there is 1015 00:43:49,146 --> 00:43:51,476 that they're still electrical but they're indeed solid 1016 00:43:51,476 --> 00:43:53,236 and that there are no such moving parts, 1017 00:43:53,406 --> 00:43:56,576 which means you're much safer in tossing your laptop 1018 00:43:56,576 --> 00:43:58,426 across the room to let it land on you bed. 1019 00:43:58,426 --> 00:44:00,836 The only thing you really risk breaking then is maybe the 1020 00:44:00,836 --> 00:44:03,386 screen or the fan, but at least your data, 1021 00:44:03,386 --> 00:44:05,866 with much higher probability these days is going 1022 00:44:05,866 --> 00:44:06,296 to be in tact. 1023 00:44:06,696 --> 00:44:08,916 Though perhaps don't try that at home. 1024 00:44:09,226 --> 00:44:11,346 Let's dive in just a little deeper to now translate 1025 00:44:11,346 --> 00:44:15,626 that high level visual to the actual bits that we promised. 1026 00:44:15,626 --> 00:44:15,693 [ Background Music ] 1027 00:44:15,693 --> 00:44:17,696 >> Let's look at what we just saw in slow motion. 1028 00:44:18,396 --> 00:44:20,766 When a great pulse of electricity is sent 1029 00:44:20,766 --> 00:44:23,906 to the read/write head it flips on a tiny electromagnet 1030 00:44:23,906 --> 00:44:24,976 for a fraction of a second. 1031 00:44:25,126 --> 00:44:29,116 The magnet creates a field which changes the polarity of a tiny, 1032 00:44:29,116 --> 00:44:31,236 tiny portion of the metal particles 1033 00:44:31,286 --> 00:44:32,436 which coat each platter surface. 1034 00:44:32,436 --> 00:44:36,036 A pattern series of these tiny charged batteries 1035 00:44:36,036 --> 00:44:39,516 on the disk represents a single bit of data 1036 00:44:39,516 --> 00:44:43,486 in the binary number system used by computers. 1037 00:44:43,516 --> 00:44:44,386 Now, if the current is sent one way 1038 00:44:44,416 --> 00:44:45,526 through the read/write head the area is polarized 1039 00:44:45,556 --> 00:44:45,976 in one direction. 1040 00:44:46,046 --> 00:44:48,636 If the current is sent in the opposite direction, 1041 00:44:48,636 --> 00:44:50,726 the polarization is reversed. 1042 00:44:50,726 --> 00:44:53,386 How do you get data off the hard disk? 1043 00:44:53,386 --> 00:44:54,406 Just reverse the process. 1044 00:44:54,946 --> 00:44:56,746 So as the particles on the disk that get the current 1045 00:44:56,746 --> 00:45:00,146 in the read/write head moving put together millions 1046 00:45:00,146 --> 00:45:01,976 of these magnetized segments and you've got a file. 1047 00:45:02,876 --> 00:45:06,186 Now, the pieces of a single may be scattered all 1048 00:45:06,186 --> 00:45:08,576 over the drive's platters, kind of like the mess 1049 00:45:08,636 --> 00:45:09,776 of papers on your desk. 1050 00:45:10,836 --> 00:45:14,136 So a special extra file keeps track of where everything is. 1051 00:45:14,276 --> 00:45:15,936 Don't you wish you had something like that? 1052 00:45:17,126 --> 00:45:19,926 >> So to summarize, even though we began the notion of bits 1053 00:45:19,926 --> 00:45:22,686 with electricity, you can't always store things electrically 1054 00:45:22,686 --> 00:45:24,356 if there's no power and certainly most 1055 00:45:24,356 --> 00:45:27,336 of us unplug our laptops or desktops or just lose power once 1056 00:45:27,336 --> 00:45:29,566 in a while and then it would be nice if we not lose all 1057 00:45:29,566 --> 00:45:30,646 of these zeros and ones. 1058 00:45:30,866 --> 00:45:32,866 And so, thus was born magnetic storage 1059 00:45:32,866 --> 00:45:34,196 which again per the inside 1060 00:45:34,196 --> 00:45:37,126 of this hard drive stores tiny little magnetic particles 1061 00:45:37,156 --> 00:45:39,296 that have some poles, north pole, south pole, 1062 00:45:39,466 --> 00:45:41,196 and the idea is that you take that particle 1063 00:45:41,196 --> 00:45:42,586 and if you wanna represent a zero, 1064 00:45:42,796 --> 00:45:44,116 you sort of orient it this way 1065 00:45:44,286 --> 00:45:46,716 or if you instead you wanna represent in a one, 1066 00:45:46,716 --> 00:45:50,046 you flip it around so that it's south-north instead 1067 00:45:50,046 --> 00:45:50,806 of north-south. 1068 00:45:50,806 --> 00:45:53,666 And then-- there are yet other ways to represent these bits 1069 00:45:53,796 --> 00:45:57,476 but for now at this point in the story, we can now just take 1070 00:45:57,476 --> 00:46:00,136 for granted that there exists some technology 1071 00:46:00,136 --> 00:46:03,396 or some technologies with which to represent zeros and ones 1072 00:46:03,436 --> 00:46:06,936 and to covert high level things like C and as we're 1073 00:46:06,936 --> 00:46:09,586 about to see Scratch into the zeros and ones 1074 00:46:09,856 --> 00:46:11,236 that computers understand. 1075 00:46:11,476 --> 00:46:15,276 So the program with which we began today was called Scratch. 1076 00:46:15,546 --> 00:46:17,646 This is a graphical programming language developed 1077 00:46:17,646 --> 00:46:19,596 by MIT's media lab down the road the 1078 00:46:19,736 --> 00:46:23,196 and Nicole's program here is the result of her dragging 1079 00:46:23,196 --> 00:46:27,076 and dropping puzzle pieces into this middle palette here, 1080 00:46:27,076 --> 00:46:30,676 the so-called scripts area, such that anytime she wanted 1081 00:46:30,676 --> 00:46:33,596 to command one of these little characters to do something, 1082 00:46:33,856 --> 00:46:37,366 she had to tell it very precisely to move up, 1083 00:46:37,366 --> 00:46:39,046 to move down, to move left, to move right, 1084 00:46:39,266 --> 00:46:42,796 maybe to conditionally move in some direction, if too close 1085 00:46:43,136 --> 00:46:47,226 to the policeman, then move to the left else move to the right. 1086 00:46:47,226 --> 00:46:49,896 So you can implement interactions between all 1087 00:46:49,896 --> 00:46:51,856 of these various characters on the screen 1088 00:46:52,076 --> 00:46:54,186 and you can have sounds and costumes 1089 00:46:54,186 --> 00:46:55,186 and you can really have fun 1090 00:46:55,186 --> 00:46:57,916 with it once you understand the basics. 1091 00:46:57,916 --> 00:46:58,806 So let me go ahead and do this. 1092 00:46:58,806 --> 00:47:01,056 Let me go ahead and just create a new file with this. 1093 00:47:01,346 --> 00:47:03,736 This author is freely available and in problem set one, 1094 00:47:03,736 --> 00:47:05,976 both standard and hacker edition where you'll be challenged 1095 00:47:05,976 --> 00:47:07,226 to use this for the first time. 1096 00:47:07,466 --> 00:47:08,746 Let's just get a sense of this 1097 00:47:08,746 --> 00:47:11,636 and how we can now express ourselves using this very 1098 00:47:11,776 --> 00:47:14,666 simple, very low-barrier language, but you'll see 1099 00:47:14,666 --> 00:47:17,816 in just a minute with some more visual demos just how fancy your 1100 00:47:17,816 --> 00:47:18,966 programs can become. 1101 00:47:19,266 --> 00:47:22,426 So at top right here, we'll have what we'll call the stage. 1102 00:47:22,426 --> 00:47:24,806 So this is just a rectangular area in which Scratch, 1103 00:47:25,136 --> 00:47:28,266 the default sprite who looks like this cat here lives. 1104 00:47:28,306 --> 00:47:31,216 And the stage is where things can move up, down, left, right, 1105 00:47:31,276 --> 00:47:32,816 spin around, and so forth. 1106 00:47:33,076 --> 00:47:36,746 On the middle of the screen, we have the so-called scripts area 1107 00:47:37,006 --> 00:47:39,976 as this tab name suggests and this is where we're gonna drag 1108 00:47:39,976 --> 00:47:42,846 and drop these puzzle pieces and hopefully they'll interlock 1109 00:47:42,846 --> 00:47:45,836 in a nice graphical way that informs me, the programmer, 1110 00:47:45,836 --> 00:47:48,806 that indeed this is okay to connect them in this way. 1111 00:47:49,016 --> 00:47:52,486 The end result might not be what I intend but at least if I want 1112 00:47:52,486 --> 00:47:55,406 to do something conditionally just like Rob indented 1113 00:47:55,406 --> 00:47:57,996 with the spacebar when using a little text editor here, 1114 00:47:58,156 --> 00:48:00,906 we're gonna see puzzle pieces that look graphically like this, 1115 00:48:01,216 --> 00:48:03,486 that's an if condition, and the-- 1116 00:48:03,486 --> 00:48:05,466 it has just enough space on the inside 1117 00:48:05,466 --> 00:48:07,276 so that you can fit another puzzle piece in there 1118 00:48:07,486 --> 00:48:10,226 and it only interlocks if it's appropriate in-- 1119 00:48:10,606 --> 00:48:12,756 to actually put those two pieces together. 1120 00:48:12,966 --> 00:48:14,126 Well, what are all these pieces? 1121 00:48:14,156 --> 00:48:19,016 Well, the third and final feature of the program is the-- 1122 00:48:19,016 --> 00:48:22,296 the palette here of all of your various puzzle pieces 1123 00:48:22,296 --> 00:48:25,016 and they're nicely color-coded into categories 1124 00:48:25,016 --> 00:48:29,016 like motion-related puzzle pieces, looks, sounds, controls, 1125 00:48:29,016 --> 00:48:31,876 sensing and so forth, and so initially you'll see 1126 00:48:31,876 --> 00:48:34,486 that you just don't really know where to look but you kinda know 1127 00:48:34,486 --> 00:48:36,726 as you'll probably find in the problem set, what you want 1128 00:48:36,726 --> 00:48:38,206 to achieve and as in the side, 1129 00:48:38,206 --> 00:48:40,056 the problem set is actually quite open-ended. 1130 00:48:40,056 --> 00:48:43,286 As you'll see, it's going to be make something of interest 1131 00:48:43,286 --> 00:48:46,226 to you with Scratch, and so you'll come up with an idea 1132 00:48:46,226 --> 00:48:49,456 and you'll then have to figure how now to express that. 1133 00:48:49,506 --> 00:48:51,346 So let's express the simplest of programs. 1134 00:48:51,346 --> 00:48:53,016 I'm gonna click the control palette, 1135 00:48:53,236 --> 00:48:55,366 which is where I have puzzle pieces with which 1136 00:48:55,366 --> 00:48:58,006 to really get things started and I'm gonna drag 1137 00:48:58,006 --> 00:49:01,476 and drop the very first one when green flag clicks. 1138 00:49:01,906 --> 00:49:04,856 Now this shape, notice, has a little curved edge on top 1139 00:49:04,856 --> 00:49:06,686 and that just kind of implies to you graphically 1140 00:49:06,686 --> 00:49:09,476 that you can't put anything on top but the little indentation 1141 00:49:09,476 --> 00:49:11,536 on the bottom is much like a real world puzzle piece. 1142 00:49:11,586 --> 00:49:12,766 Something can lock into that. 1143 00:49:13,166 --> 00:49:15,276 Well what do I want Scratch to perhaps do? 1144 00:49:15,596 --> 00:49:18,846 Let me go to the looks category and there's a whole bunch 1145 00:49:18,846 --> 00:49:21,676 of stuff here and I don't really care about all the intricacies 1146 00:49:21,676 --> 00:49:23,536 but I'm gonna go ahead and drag this one, say. 1147 00:49:23,536 --> 00:49:26,256 And now notice graphically if I move it close to it, 1148 00:49:26,256 --> 00:49:27,876 it kind of wants to snap together. 1149 00:49:28,086 --> 00:49:30,986 So if I let go of my mouse, it indeed snaps together 1150 00:49:30,986 --> 00:49:34,726 and I can make it say exactly what that other program might-- 1151 00:49:34,806 --> 00:49:37,246 might say, "Oh, hi world!" 1152 00:49:37,246 --> 00:49:40,176 And now if I zoom out, nothing's happened just 1153 00:49:40,176 --> 00:49:43,036 yet because the way to start the program, 1154 00:49:43,036 --> 00:49:46,516 to double click its icons so to speak is, as you might infer, 1155 00:49:46,516 --> 00:49:47,896 by clicking this green flag. 1156 00:49:47,996 --> 00:49:50,616 So if I click the green flag, the program runs, 1157 00:49:50,816 --> 00:49:53,286 which means all those puzzle pieces start executing. 1158 00:49:53,286 --> 00:49:56,396 They start running top to bottom and as soon as it hits the one 1159 00:49:56,686 --> 00:49:58,376 that it says, say "Oh, hi world", 1160 00:49:58,766 --> 00:50:00,906 that's indeed what Scratch does. 1161 00:50:01,426 --> 00:50:02,896 >> Well, what is this an example of? 1162 00:50:02,936 --> 00:50:04,916 Well, we can start tossing some jargon 1163 00:50:04,916 --> 00:50:07,496 on this that's actually going to come back 1164 00:50:07,496 --> 00:50:10,276 in every single future language we explore. 1165 00:50:10,486 --> 00:50:12,926 So, this here is a self-contained program 1166 00:50:12,926 --> 00:50:14,126 that we ourselves just wrote. 1167 00:50:14,296 --> 00:50:16,216 But generally, anything that's purple 1168 00:50:16,216 --> 00:50:17,906 in Scratch is what we'll call a statement. 1169 00:50:17,986 --> 00:50:20,056 It just tells the Scratch program 1170 00:50:20,236 --> 00:50:22,366 or the Scratch character to do something. 1171 00:50:22,596 --> 00:50:24,286 You might have "Wait one second". 1172 00:50:24,426 --> 00:50:26,496 This would be another statement that does what it says. 1173 00:50:26,736 --> 00:50:28,836 You might have-- and then now it's getting interesting, 1174 00:50:28,836 --> 00:50:29,726 "Play sound meow." 1175 00:50:30,286 --> 00:50:31,786 So now we have the means 1176 00:50:31,786 --> 00:50:33,346 of expressing things audio [inaudible] 1177 00:50:33,786 --> 00:50:35,636 like Nicole did with her program. 1178 00:50:35,806 --> 00:50:37,726 And if we actually now wanna integrate these 1179 00:50:37,726 --> 00:50:39,816 into our programs, let's see what we might do. 1180 00:50:39,856 --> 00:50:42,016 I'm gonna go ahead and now open up rather 1181 00:50:42,016 --> 00:50:43,966 than writing all these programs from Scratch. 1182 00:50:44,306 --> 00:50:46,906 Another such example, all of which are posted online 1183 00:50:46,906 --> 00:50:49,326 so that can play yourself, and you can see 1184 00:50:49,326 --> 00:50:51,076 and infer pretty straight forwardly even 1185 00:50:51,076 --> 00:50:53,586 if you've never programmed a computer before what this 1186 00:50:53,586 --> 00:50:54,196 thing's gonna do. 1187 00:50:54,576 --> 00:50:56,226 It's apparently gonna say, "Oh, hi world," 1188 00:50:56,226 --> 00:50:57,746 for a second and it's gonna wait. 1189 00:50:57,746 --> 00:50:59,456 It's gonna say it again, it's gonna wait, 1190 00:50:59,456 --> 00:51:01,236 it's gonna say it again, alright? 1191 00:51:01,236 --> 00:51:02,316 So let's see what happens. 1192 00:51:02,356 --> 00:51:03,526 Let's go up to the top right. 1193 00:51:03,746 --> 00:51:05,906 As in the side, you can also full screen these things 1194 00:51:05,906 --> 00:51:07,596 by clicking a certain icon. 1195 00:51:07,926 --> 00:51:09,576 So now if I wanna play this full screen, 1196 00:51:10,216 --> 00:51:14,176 we have a program that's three times as good 1197 00:51:14,176 --> 00:51:16,356 but just as underwhelming. 1198 00:51:16,356 --> 00:51:19,286 So let's see if we can make this a little more interesting. 1199 00:51:19,286 --> 00:51:20,536 Let me go ahead instead and open 1200 00:51:20,536 --> 00:51:22,086 up version three of this program. 1201 00:51:23,436 --> 00:51:25,996 And now, it's gonna be a little more interesting 'cause I'm 1202 00:51:25,996 --> 00:51:27,846 gonna make use of that other type of statement. 1203 00:51:28,516 --> 00:51:30,846 [ Cat Meowing ] 1204 00:51:31,346 --> 00:51:33,676 [ Laughter ] 1205 00:51:34,176 --> 00:51:36,556 >> Alright, so now, how did this happen? 1206 00:51:36,786 --> 00:51:38,606 Well, we just used a different statement. 1207 00:51:38,606 --> 00:51:40,946 Instead of doing the say, which was a visual one, 1208 00:51:40,946 --> 00:51:44,306 we use the audio one, play sound meow, and it just starts to flex 1209 00:51:44,306 --> 00:51:45,406 around with the various menus, 1210 00:51:45,406 --> 00:51:47,656 you can import other sounds as in the side. 1211 00:51:47,926 --> 00:51:51,396 You can go here, you can say import, we can then go 1212 00:51:51,396 --> 00:51:57,366 into things like animal and we can-- we hear crickets, 1213 00:51:57,626 --> 00:52:03,846 we can hear [noise] oh, I got to click on it. 1214 00:52:03,846 --> 00:52:04,456 [Noise] And so forth. 1215 00:52:04,586 --> 00:52:13,936 That has no academic bearing onto that. 1216 00:52:14,396 --> 00:52:16,916 So, let's see if we now can take things 1217 00:52:16,956 --> 00:52:18,916 to the next level 'cause this is not the most exciting 1218 00:52:18,916 --> 00:52:19,346 of programs. 1219 00:52:19,346 --> 00:52:21,196 Yes, we're commanding the computer to do something 1220 00:52:21,196 --> 00:52:23,976 but I'm not yet all that excited, so I need a way 1221 00:52:23,976 --> 00:52:26,436 to express more interesting forms of logic. 1222 00:52:26,776 --> 00:52:29,716 So it turns out once upon a time there was a man named Mr. Boole, 1223 00:52:29,716 --> 00:52:31,506 whose name is now attached to this notion, 1224 00:52:31,676 --> 00:52:34,446 a Boolean expression in programming, not just Scratch, 1225 00:52:34,446 --> 00:52:37,216 really any programming language out there is something 1226 00:52:37,216 --> 00:52:40,616 that is either true or false, yes or no, 1227 00:52:40,616 --> 00:52:42,746 on or off, one or zero. 1228 00:52:42,936 --> 00:52:45,706 So long as you have some kind of binary answer, you can express 1229 00:52:45,706 --> 00:52:47,566 that as a Boolean expression. 1230 00:52:47,786 --> 00:52:51,266 Now in Scratch, Boolean expressions have this diagonal 1231 00:52:51,266 --> 00:52:53,556 shape here and inside of that, 1232 00:52:53,556 --> 00:52:56,246 in this case is touching mouse pointer question mark. 1233 00:52:56,456 --> 00:52:58,946 So a Boolean expression is indeed some kind of question 1234 00:52:58,946 --> 00:53:01,696 that you can ask and it's either going to evaluate 1235 00:53:01,926 --> 00:53:04,326 to true or false, yes or no. 1236 00:53:04,326 --> 00:53:07,006 So in this case, you can ask Scratch to do something only 1237 00:53:07,006 --> 00:53:08,936 if it's touching the mouse pointer. 1238 00:53:08,936 --> 00:53:11,516 That is the little arrow that I move around with my mouse. 1239 00:53:11,746 --> 00:53:15,186 You might also do something like this, is the mouse down? 1240 00:53:15,456 --> 00:53:17,976 You might also say is some number on the left less 1241 00:53:18,096 --> 00:53:19,276 than some number on the right? 1242 00:53:19,516 --> 00:53:21,586 You might instead say is it-- 1243 00:53:21,836 --> 00:53:25,156 the case that the thing on the left and the thing 1244 00:53:25,156 --> 00:53:26,966 on the right are both true. 1245 00:53:26,966 --> 00:53:28,796 So you can check two conditions at once. 1246 00:53:28,796 --> 00:53:31,586 Am I touching some sprite and am I also touching the mouse, 1247 00:53:31,816 --> 00:53:33,226 and together can you then build 1248 00:53:33,226 --> 00:53:35,206 up even more interesting expressions. 1249 00:53:35,476 --> 00:53:37,986 And there are not-- this is not an unfamiliar concept. 1250 00:53:37,986 --> 00:53:40,666 If you use for instance CS50's encore shopping tool 1251 00:53:40,796 --> 00:53:43,486 or really any, frankly, forum on the web, 1252 00:53:43,716 --> 00:53:45,406 you've often encountered check boxes 1253 00:53:45,406 --> 00:53:47,006 and radio buttons and so forth. 1254 00:53:47,126 --> 00:53:48,836 Well, how are we implementing something 1255 00:53:48,836 --> 00:53:50,746 like these filters one Harvard courses? 1256 00:53:51,016 --> 00:53:53,036 Well, we're essentially implementing this notion 1257 00:53:53,246 --> 00:53:54,386 of a Boolean expression. 1258 00:53:54,646 --> 00:53:58,916 If you check the box offered this year, that is only going 1259 00:53:58,916 --> 00:54:02,256 to return true for courses that are indeed offered 1260 00:54:02,256 --> 00:54:05,206 in fall 2011 or spring 2012. 1261 00:54:05,416 --> 00:54:07,006 So we too are embodying this idea 1262 00:54:07,006 --> 00:54:09,276 of a Boolean expression all throughout the source code 1263 00:54:09,276 --> 00:54:10,546 that implements Harvard courses 1264 00:54:10,826 --> 00:54:14,126 and asking ourselves before we show any search results, 1265 00:54:14,386 --> 00:54:17,296 yes or no, true or false, one or zero. 1266 00:54:17,296 --> 00:54:18,226 And it's the same idea. 1267 00:54:18,226 --> 00:54:19,556 It's not expressed graphically. 1268 00:54:19,556 --> 00:54:21,196 It's expressed in a language called PHP, 1269 00:54:21,196 --> 00:54:23,606 which we ourselves will use to our term's end. 1270 00:54:23,876 --> 00:54:24,996 The ideas are the same. 1271 00:54:25,186 --> 00:54:26,596 Now, Boolean expressions are alone-- 1272 00:54:27,036 --> 00:54:28,756 are only yes or no questions. 1273 00:54:28,976 --> 00:54:31,636 You still need to act on them and go off in this direction 1274 00:54:31,636 --> 00:54:33,996 or this way, when you encounter some fork in the road. 1275 00:54:34,216 --> 00:54:36,286 So Scratch has puzzle pieces that looks like this 1276 00:54:36,286 --> 00:54:39,476 as I depicted earlier where if something is true then you wanna 1277 00:54:39,476 --> 00:54:41,426 do what's inside of this block. 1278 00:54:41,636 --> 00:54:43,006 But you can be fancier still 1279 00:54:43,056 --> 00:54:45,356 if something is true else you can do this, 1280 00:54:45,356 --> 00:54:47,286 and Rob did that in our example 1281 00:54:47,496 --> 00:54:50,396 of the slightly refined PBK example and you can actually 1282 00:54:50,396 --> 00:54:51,706 in Scratch stack these things. 1283 00:54:51,976 --> 00:54:53,996 So even though the space between the if 1284 00:54:53,996 --> 00:54:55,736 and the else there is actually pretty small 1285 00:54:55,936 --> 00:54:58,256 such that there's really no puzzle pieces that fit in there. 1286 00:54:58,436 --> 00:55:01,716 As we'll see in a moment as you drag puzzle pieces toward things 1287 00:55:01,716 --> 00:55:04,416 like this they will also grow in a similar way 1288 00:55:04,656 --> 00:55:06,436 to fit additional puzzle pieces. 1289 00:55:06,436 --> 00:55:07,856 So we can even do things like this. 1290 00:55:08,296 --> 00:55:12,856 If else if else, and now you can have a three-way intersection, 1291 00:55:13,036 --> 00:55:15,346 a three-way decision points in your program. 1292 00:55:15,606 --> 00:55:17,526 So let's now see what this allows us to do. 1293 00:55:17,526 --> 00:55:19,706 Let me go back to my examples of high. 1294 00:55:20,156 --> 00:55:21,936 Let me open the fourth such iteration, 1295 00:55:22,356 --> 00:55:24,726 and I can do something pretty stupid but at least 1296 00:55:24,726 --> 00:55:28,736 to demonstrate that this works if 1 is less than 2, play meow. 1297 00:55:28,936 --> 00:55:29,636 Meow! Works. 1298 00:55:30,876 --> 00:55:32,656 Meow! Works. 1299 00:55:34,006 --> 00:55:38,656 Meow! Okay, obviously, it's gonna keep working. 1300 00:55:38,966 --> 00:55:41,196 So we can do more interesting conditions. 1301 00:55:41,196 --> 00:55:44,466 So let's open a fifth iteration of this, and now you see 1302 00:55:44,466 --> 00:55:46,386 that the program can get more interesting especially 1303 00:55:46,386 --> 00:55:49,066 if the program you might start creating in your head is a game. 1304 00:55:49,066 --> 00:55:52,126 You probably don't want the game to be completely deterministic. 1305 00:55:52,206 --> 00:55:54,116 Every time you play it, the bad guys are 1306 00:55:54,156 --> 00:55:56,826 in the exact same place, makes it pretty easy to win, right? 1307 00:55:56,826 --> 00:55:59,726 Most any popular game has some kind of randomness built in 1308 00:55:59,726 --> 00:56:02,526 and computers can allow us what's called pseudorandomness. 1309 00:56:02,596 --> 00:56:04,426 They can come up with [inaudible] looks random 1310 00:56:04,426 --> 00:56:06,686 but it actually isn't but more on that in the future. 1311 00:56:06,866 --> 00:56:09,536 Scratch too can do something like pick a random number from 1 1312 00:56:09,536 --> 00:56:13,246 to 10 and you can then ask the questions if it's less than 6, 1313 00:56:13,246 --> 00:56:16,356 well, in other words, with 50 percent probability, go ahead 1314 00:56:16,356 --> 00:56:17,616 and play the sound meow. 1315 00:56:17,866 --> 00:56:18,706 So let's try this now. 1316 00:56:18,706 --> 00:56:22,356 I'll click the green flag, nothing, click it again. 1317 00:56:23,576 --> 00:56:28,806 Meow! Yes, again, nothing, nothing, nothing. 1318 00:56:29,476 --> 00:56:30,506 Meow! There we go. 1319 00:56:30,666 --> 00:56:32,416 If we do this in infinite number of times, 1320 00:56:32,586 --> 00:56:34,896 50 percent of them will indeed be on 1321 00:56:35,056 --> 00:56:36,996 and the other 50 percents will be off. 1322 00:56:37,236 --> 00:56:40,106 Now this too is making for very short programs. 1323 00:56:40,106 --> 00:56:42,556 And so in most any program we use today, there are some notion 1324 00:56:42,556 --> 00:56:44,476 of looping, doing something again 1325 00:56:44,476 --> 00:56:45,956 and again and again or forever. 1326 00:56:46,116 --> 00:56:48,346 Even the simplest thing on your computer like the clock 1327 00:56:48,376 --> 00:56:49,446 that tells you what time it is, 1328 00:56:49,706 --> 00:56:51,986 that's probably a program implemented with some kind 1329 00:56:51,986 --> 00:56:55,096 of loop, an infinite loop at that because you want it 1330 00:56:55,096 --> 00:56:58,496 to do something, keep updating the seconds every time 1331 00:56:58,616 --> 00:57:01,336 on every strike of the clock. 1332 00:57:01,336 --> 00:57:03,606 So you might wanna have loops that repeat infinitely, 1333 00:57:03,816 --> 00:57:07,276 some loops that repeat finitely but in short you wanna be able 1334 00:57:07,276 --> 00:57:08,876 to do something again and again. 1335 00:57:09,136 --> 00:57:12,046 And now our programs again can get progressively neither. 1336 00:57:12,296 --> 00:57:16,036 So in variant 6 here, notice I don't have to drag and drop 1337 00:57:16,036 --> 00:57:18,776 at [inaudible] all these puzzle pieces saying again and again 1338 00:57:18,826 --> 00:57:20,326 and again and again, do something. 1339 00:57:20,616 --> 00:57:22,636 I can express it much more succinctly with a loop. 1340 00:57:22,966 --> 00:57:25,256 And so here, I might play this particular program. 1341 00:57:30,066 --> 00:57:34,436 [Cat sound] This too will get annoying frankly quickly. 1342 00:57:35,636 --> 00:57:37,446 Your roommates will be thrilled this week. 1343 00:57:38,046 --> 00:57:39,286 But let's open something 1344 00:57:39,346 --> 00:57:41,606 that does a little something more dynamic. 1345 00:57:41,656 --> 00:57:43,406 This is version 7 of this. 1346 00:57:43,806 --> 00:57:45,076 So this is kind of interesting. 1347 00:57:45,076 --> 00:57:47,056 And now again, the programs are getting bigger and bigger. 1348 00:57:47,156 --> 00:57:49,326 And to be clear, this is exactly where Nicole started. 1349 00:57:49,326 --> 00:57:50,766 You'll see that we're only gonna equip you 1350 00:57:50,766 --> 00:57:53,296 with the basic concepts and fundamental skills here 1351 00:57:53,486 --> 00:57:55,716 and then it will be up to you to run with it. 1352 00:57:55,926 --> 00:57:58,636 So when green flag is clicked, do the following forever. 1353 00:57:58,906 --> 00:58:02,346 If I'm ever touching the mouse pointer, that is the cat, 1354 00:58:02,706 --> 00:58:04,886 play sound meow then wait 2 seconds. 1355 00:58:05,106 --> 00:58:06,246 So let's see how this works. 1356 00:58:06,246 --> 00:58:08,516 Let me hit play, nothing happens. 1357 00:58:08,516 --> 00:58:10,586 Now, notice the puzzle pieces do highlight in white 1358 00:58:10,586 --> 00:58:11,536 when they're actually running 1359 00:58:11,536 --> 00:58:13,076 so you can see your program running. 1360 00:58:13,326 --> 00:58:17,886 Now if I move my mouse toward the cat, [cat sound]. 1361 00:58:18,276 --> 00:58:20,106 So it's kind of like petting the cat. 1362 00:58:20,456 --> 00:58:22,896 So that might be how we implement that. 1363 00:58:23,096 --> 00:58:26,296 Now we might go to say version 8 of this 1364 00:58:26,296 --> 00:58:28,656 and let's see how this cat behaves. 1365 00:58:28,686 --> 00:58:30,076 So this is sort of the opposite kind 1366 00:58:30,076 --> 00:58:35,936 of cat whereby [background cat sound] he meows and meow. 1367 00:58:35,936 --> 00:58:37,316 So again there's some loop in there. 1368 00:58:37,316 --> 00:58:39,066 This is not a cat you wanna touch. 1369 00:58:39,206 --> 00:58:42,106 [Growl] And then he does that. 1370 00:58:42,106 --> 00:58:43,696 Well, how does that actually get implemented? 1371 00:58:43,696 --> 00:58:45,936 Well we just need another fork in the road, right? 1372 00:58:45,936 --> 00:58:49,396 If touching mouse pointer, then play some lion sound, else, 1373 00:58:49,556 --> 00:58:52,526 play meow again and again and again. 1374 00:58:53,026 --> 00:58:55,636 Well, another very common constructing programming is this 1375 00:58:55,636 --> 00:58:58,396 notion of a variable, something that you take for granted 1376 00:58:58,396 --> 00:59:01,836 in algebra but in algebra, X and Y and Z are not very interesting 1377 00:59:01,836 --> 00:59:03,816 or expressive but they still store values. 1378 00:59:03,816 --> 00:59:06,876 In programming, you wanna store more interesting things not just 1379 00:59:06,876 --> 00:59:09,206 numbers but maybe sentences or user input, 1380 00:59:09,306 --> 00:59:10,466 photos, they've uploaded. 1381 00:59:10,686 --> 00:59:13,266 And so in Scratch, you can define what are called variables 1382 00:59:13,496 --> 00:59:17,366 not using just boring names like X, Y and Z but socks on feet 1383 00:59:17,456 --> 00:59:21,376 or the slices of bread left and so forth. 1384 00:59:21,476 --> 00:59:23,706 And you can check those values in your program. 1385 00:59:23,926 --> 00:59:27,726 So now we'll transition to a much more dynamic program also 1386 00:59:27,726 --> 00:59:28,896 in by a former student. 1387 00:59:29,246 --> 00:59:31,176 This one called Fruit-Craft RPG. 1388 00:59:31,176 --> 00:59:35,486 And in this Scratch program, which again written by a student 1389 00:59:35,486 --> 00:59:36,976 after just a couple of days, 1390 00:59:37,166 --> 00:59:38,556 runs a little something like this. 1391 00:59:38,556 --> 00:59:40,696 At top left, you see a graphical depiction 1392 00:59:40,856 --> 00:59:43,886 and this is just something he drag and drop into his program 1393 00:59:43,886 --> 00:59:46,676 and it shows you the contents of these variables. 1394 00:59:47,166 --> 00:59:48,666 Now notice that with my mouse, 1395 00:59:48,926 --> 00:59:50,606 I can now have things that are interactive. 1396 00:59:50,916 --> 00:59:53,176 I can walk around this guy's home and table. 1397 00:59:53,476 --> 00:59:55,736 I can follow the arrow out the door. 1398 00:59:55,916 --> 00:59:58,096 And now think about how this might be implemented. 1399 00:59:58,416 --> 01:00:01,436 It's many more script, it's many more puzzle pieces 1400 01:00:01,436 --> 01:00:01,976 but what's it doing? 1401 01:00:02,046 --> 01:00:04,666 >> There's probably a loop that says forever. 1402 01:00:04,876 --> 01:00:07,916 If down arrow pressed, then what does it do? 1403 01:00:08,006 --> 01:00:09,916 Well, there's another puzzle piece that says move 1404 01:00:09,916 --> 01:00:12,716 and you say 10 pixels, 10 dots on the screen. 1405 01:00:12,906 --> 01:00:14,536 And if you have another "if" condition that says, 1406 01:00:14,536 --> 01:00:16,856 "If up arrow pressed, go up or left 1407 01:00:17,126 --> 01:00:18,876 or right," the exact same ideas. 1408 01:00:19,186 --> 01:00:20,796 So now notice I'm outside my house. 1409 01:00:20,796 --> 01:00:22,046 I can go over to this orange. 1410 01:00:22,486 --> 01:00:23,996 And now notice at top left, 1411 01:00:24,256 --> 01:00:26,846 we see what's generally called an array. 1412 01:00:26,846 --> 01:00:29,276 An array is the simplest of this thing called a data structure, 1413 01:00:29,276 --> 01:00:30,436 a word I use on Wednesday. 1414 01:00:30,436 --> 01:00:32,616 But a data structure is generally like a bucket 1415 01:00:32,816 --> 01:00:35,476 where you can store not just one but any number of things, 1416 01:00:35,516 --> 01:00:36,986 in this case some fruit. 1417 01:00:36,986 --> 01:00:37,676 Let's go get this. 1418 01:00:38,516 --> 01:00:39,266 Let's go get this 1419 01:00:39,266 --> 01:00:40,606 on the question marks we're [inaudible]. 1420 01:00:40,946 --> 01:00:42,116 So remember that you can check 1421 01:00:42,116 --> 01:00:43,976 if you're touching something else on the screen, 1422 01:00:43,976 --> 01:00:45,466 and sure enough, if I go close enough, 1423 01:00:45,666 --> 01:00:46,846 there's an "if' condition that says, 1424 01:00:46,846 --> 01:00:49,806 "If sprite touching question mark sign, 1425 01:00:50,106 --> 01:00:52,426 apparently it's gonna then say, got some fruit, 1426 01:00:52,426 --> 01:00:53,286 bring it to the fruit place." 1427 01:00:53,286 --> 01:00:54,726 So there are some built-in instructions. 1428 01:00:55,026 --> 01:00:56,176 Well, let's go get the rest of this. 1429 01:00:56,176 --> 01:00:58,506 And notice my inventory at top left change 1430 01:00:58,856 --> 01:01:00,776 and now I'm gonna enter the fruit place. 1431 01:01:00,906 --> 01:01:04,986 And now notice here, if touching door change the whole scenery. 1432 01:01:04,986 --> 01:01:07,616 And so the costume of the stage has just changed. 1433 01:01:07,846 --> 01:01:11,326 Now let's see if this guy has got any final words for us here 1434 01:01:11,326 --> 01:01:14,436 and then we'll introduce some actual sound. 1435 01:01:15,006 --> 01:01:19,176 Now that over there was the grand prize of this game. 1436 01:01:19,776 --> 01:01:23,136 So we need just a couple more tricks to express ourselves 1437 01:01:23,136 --> 01:01:25,096 and implement more sophisticated things. 1438 01:01:25,096 --> 01:01:27,766 So this notion of an array in Scratch looks a little something 1439 01:01:27,766 --> 01:01:29,556 like this where you can add something like a word 1440 01:01:29,556 --> 01:01:31,946 like orange or apple to a variable 1441 01:01:31,946 --> 01:01:33,426 in this case called "inventory." 1442 01:01:33,666 --> 01:01:36,896 But you can also do multiple things at once, right? 1443 01:01:36,896 --> 01:01:40,126 Thus far the only example we've seen involving multiple sprites 1444 01:01:40,126 --> 01:01:41,976 on this screen was this RPG game. 1445 01:01:42,186 --> 01:01:44,706 But here, we see more generally the notion of threads. 1446 01:01:44,746 --> 01:01:47,726 A computer program these days can do multiple things at once 1447 01:01:47,726 --> 01:01:48,946 and a slight white lie. 1448 01:01:49,156 --> 01:01:51,656 It can create the illusion of doing multiple things at once. 1449 01:01:51,656 --> 01:01:53,866 It's just so much faster than you, the human are, 1450 01:01:54,036 --> 01:01:55,846 you don't really notice that it's doing a little bit of this, 1451 01:01:55,846 --> 01:01:58,036 a little bit of this, a little bit of this and repeating 1452 01:01:58,036 --> 01:01:59,266 so fast that you don't realize 1453 01:01:59,306 --> 01:02:01,646 that actually it's not all happening at the same time. 1454 01:02:01,866 --> 01:02:04,476 But in Scratch we can implement this idea of multiple threads, 1455 01:02:04,656 --> 01:02:07,576 multiple scripts or multiple sprites executing 1456 01:02:07,576 --> 01:02:10,126 at the very same time rather than one after the other. 1457 01:02:10,126 --> 01:02:13,256 And what this allows us to do is write a program like this 1458 01:02:13,256 --> 01:02:16,396 where two different sprites somehow interact. 1459 01:02:16,866 --> 01:02:19,956 So now notice one last piece of the UI here, at bottom right, 1460 01:02:20,556 --> 01:02:22,576 you see icons for each 1461 01:02:22,636 --> 01:02:24,946 of the multiple sprites in your program. 1462 01:02:24,946 --> 01:02:27,406 If you don't want just a cat, you can have a bird, 1463 01:02:27,406 --> 01:02:29,226 you can have a piece of fruit, you can have a house, 1464 01:02:29,306 --> 01:02:31,806 any number of sprites and then you just add a graphic to them 1465 01:02:31,806 --> 01:02:34,736 and they look more interesting than just a simple orange cat. 1466 01:02:35,256 --> 01:02:38,366 So now notice I have the cat selected so these scripts 1467 01:02:38,366 --> 01:02:41,476 at top left are all of these scripts that belong 1468 01:02:41,476 --> 01:02:45,296 to that sprite, to that cat and that script, 1469 01:02:45,366 --> 01:02:47,956 those scripts will only control that particular cat. 1470 01:02:48,686 --> 01:02:50,806 Well now, if we click over to the bird here, 1471 01:02:50,986 --> 01:02:53,446 the bird has his own set of puzzle pieces 1472 01:02:53,796 --> 01:02:56,536 and now let's see what this game is gonna do. 1473 01:02:56,756 --> 01:02:57,876 One green flag clicked, 1474 01:02:57,936 --> 01:03:01,916 apparently the bird is gonna go to negative 150, 150. 1475 01:03:02,086 --> 01:03:05,226 So it turns out that stage, it's like a graphic in like Photoshop 1476 01:03:05,226 --> 01:03:07,056 or some program where you have all these little dots 1477 01:03:07,056 --> 01:03:08,466 and you just figure out by trial 1478 01:03:08,466 --> 01:03:11,046 and error what numbers represent what position on the screen. 1479 01:03:11,376 --> 01:03:14,176 Point in direction 45 degrees so at a certain angle. 1480 01:03:14,276 --> 01:03:15,196 And then forever, 1481 01:03:15,196 --> 01:03:17,776 if not touching the cat, do the following. 1482 01:03:17,776 --> 01:03:19,786 Move three steps and if you're on the edge, bounce. 1483 01:03:20,486 --> 01:03:22,466 Now the cat is gonna something a little different 1484 01:03:22,516 --> 01:03:24,546 so let's play this in parallel. 1485 01:03:25,516 --> 01:03:30,666 [ Noise ] 1486 01:03:31,166 --> 01:03:32,666 >> Right? So think about what the cat is doing. 1487 01:03:32,756 --> 01:03:36,386 If touching bird-- [growl], okay, 1488 01:03:36,526 --> 01:03:38,176 not so good for the bird in this case. 1489 01:03:38,376 --> 01:03:39,696 But there's now interaction 1490 01:03:39,696 --> 01:03:41,416 that you can see 'cause what was the cat doing? 1491 01:03:41,416 --> 01:03:43,286 Well, let's go back to his scripts and zoom in. 1492 01:03:43,536 --> 01:03:45,866 He too goes to some specific X, Y coordinate. 1493 01:03:46,116 --> 01:03:47,936 But then, point in direction random. 1494 01:03:48,056 --> 01:03:49,936 So we decided, let's at least have him point 1495 01:03:49,986 --> 01:03:52,116 into some direction so that every time we do this demo, 1496 01:03:52,306 --> 01:03:53,916 it's not the same pan demonstration. 1497 01:03:53,916 --> 01:03:55,506 There's a little something variant. 1498 01:03:55,786 --> 01:03:57,526 And then forever the cat does this. 1499 01:03:57,526 --> 01:04:01,256 If touching bird play the lion sound then stop, else, 1500 01:04:01,326 --> 01:04:02,746 and this time the "else" is implicit 1501 01:04:02,746 --> 01:04:04,676 which is perfectly fine too if you have an-- 1502 01:04:04,746 --> 01:04:06,126 or rather it's not implicit, 1503 01:04:06,426 --> 01:04:08,346 rather the "if" condition is gonna execute 1504 01:04:08,516 --> 01:04:11,546 but the bottom two blocks will always execute point towards 1505 01:04:11,546 --> 01:04:12,966 bird, move one step. 1506 01:04:13,376 --> 01:04:15,626 So we can actually make the cat much better at this game 1507 01:04:15,816 --> 01:04:18,276 if we make the cat move say 10 steps at a time 1508 01:04:18,276 --> 01:04:19,546 by just changing that number. 1509 01:04:19,946 --> 01:04:21,896 And now we go back here and hit play. 1510 01:04:23,176 --> 01:04:25,586 [Growl] Okay, happens all that much more quickly. 1511 01:04:26,156 --> 01:04:27,566 So there's one last feature here. 1512 01:04:27,716 --> 01:04:29,916 And this in programming in general, not just Scratch, 1513 01:04:29,916 --> 01:04:34,386 it's called "event," whereby you can two sprites, 2 characters 1514 01:04:34,386 --> 01:04:36,996 on the screen actually somehow intercommunicate 1515 01:04:37,126 --> 01:04:39,956 and we can implement this age old game of Marco Polo 1516 01:04:39,956 --> 01:04:43,206 that you might have played in a pool whereby two humans need 1517 01:04:43,206 --> 01:04:44,426 to somehow communicate. 1518 01:04:44,616 --> 01:04:47,876 So here we have the boy, Marco, and he's highlighted down here. 1519 01:04:48,036 --> 01:04:49,596 And so at top left, we see 1520 01:04:49,596 --> 01:04:51,146 that Marco is gonna behave as follows. 1521 01:04:51,386 --> 01:04:55,416 Forever if the space key is pressed, he's going to say Marco 1522 01:04:55,416 --> 01:04:58,496 for 2 seconds and then he's gonna broadcast an event. 1523 01:04:59,076 --> 01:05:02,096 Thus far, we've seen ways where two sprites can interact 1524 01:05:02,096 --> 01:05:03,486 by checking where they are, 1525 01:05:03,746 --> 01:05:06,766 which we haven't seen one sprite send another sprite a message. 1526 01:05:07,036 --> 01:05:09,966 When we say, say Marco, that's just for our human benefit, 1527 01:05:09,966 --> 01:05:12,056 to see some little cartoon bubble on the screen. 1528 01:05:12,246 --> 01:05:14,486 If we want the boy to communicate 1529 01:05:14,486 --> 01:05:18,336 to the girl programmatically by sending some kind of 0 1530 01:05:18,336 --> 01:05:21,376 and 1 message, we have to do what's called broadcast an event 1531 01:05:21,826 --> 01:05:25,886 which is just a message that now other sprites can listen for. 1532 01:05:25,886 --> 01:05:26,966 So let's look at the girl. 1533 01:05:27,196 --> 01:05:30,086 The girl is actually defined quite simply not 1534 01:05:30,086 --> 01:05:31,206 with the green flag trick 1535 01:05:31,476 --> 01:05:34,366 but with this other starting point when I receive event. 1536 01:05:34,696 --> 01:05:37,476 So she's listening for Marco to send her this message, 1537 01:05:37,536 --> 01:05:38,856 this event called "event." 1538 01:05:39,236 --> 01:05:43,446 And when she receives it, she is gonna say Polo for 2 seconds. 1539 01:05:43,876 --> 01:05:45,436 So let's go ahead and see this in action. 1540 01:05:45,786 --> 01:05:47,576 Nothing happens at first but remember, 1541 01:05:47,606 --> 01:05:49,706 once I hit the space bar, I see this 1542 01:05:49,706 --> 01:05:53,316 and now the girl replies in turn. 1543 01:05:53,316 --> 01:05:54,306 So now we have the means 1544 01:05:54,526 --> 01:05:57,046 of conveying two different messages to people. 1545 01:05:57,456 --> 01:05:59,076 Well, these are just building blocks, 1546 01:05:59,076 --> 01:06:01,026 how can we take things up to the next level? 1547 01:06:01,296 --> 01:06:05,036 Well, let me go ahead and we could call one brave volunteer 1548 01:06:05,036 --> 01:06:08,456 to the stage and show you yet another example. 1549 01:06:08,946 --> 01:06:11,936 Only us in the front are playing along today I see. 1550 01:06:12,206 --> 01:06:15,796 Okay. How 'bout, let's say you, 1551 01:06:15,796 --> 01:06:17,326 right in front, easier to get to. 1552 01:06:17,326 --> 01:06:17,716 Come on up. 1553 01:06:17,716 --> 01:06:18,076 What's your name? 1554 01:06:18,526 --> 01:06:18,796 >> Trevor [phonetic]. 1555 01:06:19,056 --> 01:06:19,406 >> Trevor. 1556 01:06:19,406 --> 01:06:20,196 Trevor, come on up. 1557 01:06:20,196 --> 01:06:21,806 You have to be comfortable appearing on camera 1558 01:06:22,496 --> 01:06:24,406 and also performing poorly on a game. 1559 01:06:25,856 --> 01:06:28,876 So here we have a little something also made 1560 01:06:28,876 --> 01:06:30,136 by one of our own alumni. 1561 01:06:30,136 --> 01:06:34,256 Come on up and I give you in a moments the culmination of some 1562 01:06:34,256 --> 01:06:37,806 of these fundamentals called Scratch, Scratch revolution. 1563 01:06:38,596 --> 01:06:40,216 [Laughter] And if Barry [phonetic] we could turn 1564 01:06:40,216 --> 01:06:41,466 up the sound a bit more. 1565 01:06:42,346 --> 01:06:42,676 >> Oh, great. 1566 01:06:42,676 --> 01:06:45,376 >> Here we have-- let me set the stage verbally. 1567 01:06:45,736 --> 01:06:47,486 Notice we got a whole bunch of variables 1568 01:06:47,586 --> 01:06:49,896 that this former student dragged into the stage 1569 01:06:49,896 --> 01:06:51,846 so that you could see the variable score, 1570 01:06:51,936 --> 01:06:54,926 the awesome score, the cool score, the good, the boo score. 1571 01:06:55,206 --> 01:06:56,866 Then there are these arrows and each 1572 01:06:56,866 --> 01:06:58,016 of these arrows is a sprite. 1573 01:06:58,016 --> 01:07:00,116 And notice he used some randomness 1574 01:07:00,116 --> 01:07:02,006 to have these things appear in different locations. 1575 01:07:02,266 --> 01:07:03,736 Here is just a very poor man's way 1576 01:07:03,766 --> 01:07:05,216 of implementing instructions. 1577 01:07:05,216 --> 01:07:07,316 You just kind of do it with the built-in text editor 1578 01:07:07,316 --> 01:07:07,906 in the program. 1579 01:07:08,176 --> 01:07:10,056 Press Spacebar to begin then you're gonna-- 1580 01:07:10,156 --> 01:07:11,956 Trevor is gonna hit the arrow keys in time 1581 01:07:11,956 --> 01:07:13,246 with arrows to score points. 1582 01:07:13,246 --> 01:07:15,856 Watch out if your score gets negative, bad things are going 1583 01:07:15,856 --> 01:07:18,426 to happen, little like DDR, if familiar. 1584 01:07:18,806 --> 01:07:20,666 So if our volumes indeed cranked up, 1585 01:07:21,096 --> 01:07:22,586 we'll see how well you can do here. 1586 01:07:22,586 --> 01:07:23,756 So you got the instructions in mind? 1587 01:07:24,026 --> 01:07:24,446 >> I guess so. 1588 01:07:24,446 --> 01:07:26,766 >> Okay, arrow keys are right here, spacebar begins. 1589 01:07:27,516 --> 01:08:06,516 [ Music ] 1590 01:08:07,016 --> 01:08:07,083 [ Background Music ] 1591 01:08:07,486 --> 01:08:11,366 >> Now notice, it's gonna be some kind of timer 1592 01:08:11,366 --> 01:08:13,356 that realizes it's time to raise the bar. 1593 01:08:14,516 --> 01:08:17,266 [ Music ] 1594 01:08:17,766 --> 01:08:20,516 [ Laughter ] 1595 01:08:21,016 --> 01:08:21,083 [ Background Music ] 1596 01:08:21,236 --> 01:08:23,046 >> So a big hand for Trevor if we could here. 1597 01:08:23,046 --> 01:08:25,956 [Background applause] Very well done. 1598 01:08:29,006 --> 01:08:30,466 So unless we have the culmination 1599 01:08:30,466 --> 01:08:32,106 of all these various puzzle pieces-- 1600 01:08:32,106 --> 01:08:33,626 but it doesn't even stop there. 1601 01:08:33,626 --> 01:08:36,486 In fact, for the hacker edition of this week's problem 1602 01:08:36,536 --> 01:08:38,586 that you'll be challenged not only to implement something 1603 01:08:38,586 --> 01:08:39,336 of interest to you 1604 01:08:39,576 --> 01:08:41,526 but to integrate a little something like this. 1605 01:08:41,606 --> 01:08:44,726 A sensor board which is just this little plastic board that's 1606 01:08:44,726 --> 01:08:48,226 got a whole bunch of metallic traces, wires connected to it 1607 01:08:48,366 --> 01:08:49,826 and it takes a whole bunch of inputs. 1608 01:08:49,866 --> 01:08:51,926 There's this little slider which is like a joystick. 1609 01:08:52,206 --> 01:08:53,846 There's this little connector here which allows you 1610 01:08:53,846 --> 01:08:55,846 to connect this to your Mac or PC. 1611 01:08:56,066 --> 01:08:57,466 There's a light sensor. 1612 01:08:57,466 --> 01:08:59,506 There are resistance sensors. 1613 01:08:59,506 --> 01:09:01,416 There is a sound and light sensors. 1614 01:09:01,416 --> 01:09:03,036 There're all sorts of sensors built 1615 01:09:03,036 --> 01:09:05,076 into this otherwise very primitive looking device. 1616 01:09:05,336 --> 01:09:07,766 And so if you think now about some of the toys you might have 1617 01:09:07,766 --> 01:09:10,376 or electronic devices, what's generally inside of them 1618 01:09:10,376 --> 01:09:13,426 if they respond to inputs like touch and sound and feel, 1619 01:09:13,616 --> 01:09:15,346 are these basic building blocks. 1620 01:09:15,346 --> 01:09:17,086 So for the hacker of the addition of the problem 1621 01:09:17,086 --> 01:09:19,306 that you'll be challenged to connect up a cable 1622 01:09:19,306 --> 01:09:22,056 to your own computer and not just take input from the user 1623 01:09:22,056 --> 01:09:26,296 at the keyboard but rather from this actual physical device. 1624 01:09:26,526 --> 01:09:31,926 Well, we thought we would share just one last example here also 1625 01:09:31,926 --> 01:09:33,336 by one of our former students. 1626 01:09:33,336 --> 01:09:37,076 This was to a song that you'll see takes advantage of loops 1627 01:09:37,256 --> 01:09:40,196 and conditions and sounds and animation 1628 01:09:40,526 --> 01:09:43,276 to give us this final song. 1629 01:09:44,516 --> 01:10:20,766 [ Music ] 1630 01:10:21,266 --> 01:10:57,516 [ Movie Clip ] 1631 01:10:58,016 --> 01:10:58,083 [ Background Music ] 1632 01:10:58,336 --> 01:10:59,386 >> That's it for today. 1633 01:10:59,886 --> 01:11:01,616 This is CS50 Problem Set [inaudible] on the website. 1634 01:11:02,296 --> 01:11:04,136 We will see you next week. 1635 01:11:05,516 --> 01:11:11,693 [ Music ] 1636 01:11:12,193 --> 01:11:18,370 [ Applause ]