1 00:00:09,516 --> 00:00:57,556 [Inaudible Background Speaker and Music] 2 00:00:58,056 --> 00:01:01,816 >> On January 24, Apple Computer will introduce Macintosh, 3 00:01:02,266 --> 00:01:07,436 and you'll see why 1984 won't be like 1984. 4 00:01:08,946 --> 00:01:12,316 >>David: So that commercial aired once in 1984, 5 00:01:12,316 --> 00:01:16,096 during the Super Bowl and this was 25 years ago now, 6 00:01:16,096 --> 00:01:19,236 and it was Apple first debuted the Macintosh, and at the time, 7 00:01:19,236 --> 00:01:21,746 they were facing Big Blue, IBM, and those IBM PC's, 8 00:01:21,746 --> 00:01:24,066 and most of you probably haven't even used 9 00:01:24,066 --> 00:01:26,806 in their original form, but it was a big deal 10 00:01:26,976 --> 00:01:31,266 as to what the Apple had begun do in 1984 with the industry 11 00:01:31,266 --> 00:01:32,626 and with computers as we now know it. 12 00:01:32,866 --> 00:01:35,386 And, today is focused on precisely 13 00:01:35,626 --> 00:01:37,466 that general world of hardware. 14 00:01:37,466 --> 00:01:39,846 We've spent much of the semester working our way on up, 15 00:01:40,136 --> 00:01:41,896 we went through C, we went through PHP, 16 00:01:41,896 --> 00:01:45,416 a little Java script and AJAX, and HTML, and all of that, 17 00:01:45,416 --> 00:01:47,766 and then today, finally, we'll come full circle 18 00:01:47,766 --> 00:01:50,506 and actually look underneath the hood as to how all 19 00:01:50,506 --> 00:01:51,826 of this magic has been happening. 20 00:01:51,826 --> 00:01:54,206 When you compile something with GCC, when you run something 21 00:01:54,206 --> 00:01:56,916 with PHP, what is, in fact, happening underneath the hood? 22 00:01:56,976 --> 00:01:58,136 But a few announcements first. 23 00:01:58,416 --> 00:02:01,186 So, one little copy paste fail, this handout is indeed 24 00:02:01,186 --> 00:02:03,746 about Quiz 1, not about Quiz zero, 25 00:02:03,746 --> 00:02:06,336 which the first sentence says, my apologies, but yes, 26 00:02:06,336 --> 00:02:11,526 Quiz 1 is in, on Wednesday 11/18 and do peruse the handout here 27 00:02:11,526 --> 00:02:13,836 for all of the available resources coming up at you, 28 00:02:13,836 --> 00:02:17,456 including review sessions and quiz review in sections. 29 00:02:17,766 --> 00:02:19,696 Also, take note that on Monday, 30 00:02:19,696 --> 00:02:21,536 we're going to be having a few guest lecturers 31 00:02:21,536 --> 00:02:23,376 from the Computer Science faculty. 32 00:02:23,926 --> 00:02:25,126 Each will talk a little bit 33 00:02:25,126 --> 00:02:28,046 about Computer Science beyond CS50 and specifically some 34 00:02:28,046 --> 00:02:29,256 of the courses you can take. 35 00:02:29,526 --> 00:02:32,406 It's actually much more exciting taking Computer Science courses 36 00:02:32,406 --> 00:02:35,036 here these days, than in my day, where pretty much 37 00:02:35,036 --> 00:02:39,496 after you took 50, you took 51 and after 51, you took 121, 38 00:02:39,496 --> 00:02:41,666 and after 121, you took 124, 39 00:02:41,666 --> 00:02:43,746 like there was a very clearly defined path, 40 00:02:44,426 --> 00:02:46,896 but there wasn't much digression from it. 41 00:02:46,896 --> 00:02:49,116 Now, there's so many more faculty and courses, 42 00:02:49,406 --> 00:02:53,196 that after CS50, you guys will be able to, if you so chose 43 00:02:53,196 --> 00:02:56,716 for reasons of majoring, minoring, or just for fun, CS51, 44 00:02:56,716 --> 00:02:59,736 which is about functional programming, and abstraction, 45 00:02:59,796 --> 00:03:01,286 which you'll hear a little more about on Monday. 46 00:03:01,706 --> 00:03:04,766 CS61, which is about systems programming, it's in that course 47 00:03:04,766 --> 00:03:06,646 where you diffuse the binary bomb, 48 00:03:06,646 --> 00:03:08,276 that piece that I described a while back. 49 00:03:08,716 --> 00:03:11,956 You can take 121 next fall, which is a theory course, 50 00:03:12,186 --> 00:03:13,976 and speaks to the fundamentals 51 00:03:13,976 --> 00:03:15,896 of what computers can and can't do. 52 00:03:16,016 --> 00:03:19,066 CS124, which is data structures and algorithms, 53 00:03:19,066 --> 00:03:21,176 which picks up essentially where we left off 54 00:03:21,176 --> 00:03:22,876 with hash tables, tables, and tried. 55 00:03:23,316 --> 00:03:26,086 CS171, which is about visualization 56 00:03:26,086 --> 00:03:28,566 and taking interesting large data sets and presenting it 57 00:03:28,566 --> 00:03:30,326 to human in ways they can understand. 58 00:03:30,716 --> 00:03:33,506 CS105, privacy and security, which is more 59 00:03:33,506 --> 00:03:35,986 of a seminar course, where you talk about the implications 60 00:03:35,986 --> 00:03:38,296 of various technologies on society, 61 00:03:38,296 --> 00:03:40,646 and its privacy and security. 62 00:03:40,646 --> 00:03:43,216 CS179, which is a new course, 63 00:03:43,456 --> 00:03:45,966 in which you will actually do iPhone development and focus 64 00:03:45,966 --> 00:03:48,906 on the design of good, user interfaces, 65 00:03:48,976 --> 00:03:51,096 so there's quite the platter of courses 66 00:03:51,096 --> 00:03:51,686 from which you'll be able 67 00:03:51,686 --> 00:03:53,676 to chose this spring, this coming fall. 68 00:03:53,676 --> 00:03:55,466 And realize, too, at the end of this course, 69 00:03:56,156 --> 00:03:58,656 CS50 is a terminal course for many students. 70 00:03:58,656 --> 00:04:00,326 Usually about half of the students in 50, 71 00:04:00,616 --> 00:04:02,996 don't take Computer Science, and that perfectly fine, 72 00:04:02,996 --> 00:04:04,756 because the course is meant to provide you 73 00:04:04,756 --> 00:04:07,756 with enough background, enough skill set to actually go off 74 00:04:07,756 --> 00:04:09,916 and do interesting things, even beyond the course, 75 00:04:10,246 --> 00:04:13,366 but realize that, if you are interested in minoring 76 00:04:13,366 --> 00:04:16,096 in Computer Science, the department is quite eager 77 00:04:16,096 --> 00:04:18,146 to entice to all the more students into it, 78 00:04:18,146 --> 00:04:20,376 and you have many different things to chose from these days. 79 00:04:20,586 --> 00:04:23,506 Majoring, all the better, but even if you just want to dabble 80 00:04:23,506 --> 00:04:25,856 in Computer Science, realize that this course, in particular, 81 00:04:25,856 --> 00:04:28,126 opens a lot of doors, within the engineering school, 82 00:04:28,456 --> 00:04:29,596 so do keep that in mind. 83 00:04:29,596 --> 00:04:31,676 We'll have a little cheat sheet, probably on the website 84 00:04:31,956 --> 00:04:35,006 or on paper on Monday, just to give you a more clear sense 85 00:04:35,006 --> 00:04:37,676 than this verbal tour, as to what awaits you. 86 00:04:38,226 --> 00:04:40,456 So, one pitch, before I turn things 87 00:04:40,456 --> 00:04:42,396 over to a couple of other folks. 88 00:04:42,396 --> 00:04:45,166 The first is, this one here, so the website is now 89 00:04:45,166 --> 00:04:47,866 up as promised, we do indeed want some TF's 90 00:04:47,866 --> 00:04:49,276 and CA's and graders. 91 00:04:49,276 --> 00:04:49,986 What does this mean? 92 00:04:50,206 --> 00:04:52,876 A teaching fellow for this course, as you may have inferred 93 00:04:52,876 --> 00:04:54,686 from the person you've been working with all term, 94 00:04:54,936 --> 00:04:57,576 someone who leads sections, who grades problem sets, 95 00:04:57,576 --> 00:04:59,506 who works with students one on one in office hours, 96 00:04:59,506 --> 00:05:00,966 fields questions on the bulletin boards 97 00:05:00,966 --> 00:05:03,276 and does all those things you're familiar with TFN. 98 00:05:03,626 --> 00:05:07,796 I would say that TFN50 is a fairly unique experience. 99 00:05:07,796 --> 00:05:10,946 It's definitely intense, perhaps as intense as taking the course, 100 00:05:10,946 --> 00:05:13,836 but so much fun, and dare say, so much more fun being 101 00:05:13,836 --> 00:05:16,336 on this side of things, than on that side of things, 102 00:05:16,336 --> 00:05:18,936 and it's a nice way to main, to remain part 103 00:05:19,186 --> 00:05:21,046 of the community that you might feel. 104 00:05:21,306 --> 00:05:22,726 CA's are volunteer's. 105 00:05:22,766 --> 00:05:25,716 CS50 alumni who offer 2 hours of office hours per week, 106 00:05:25,956 --> 00:05:28,396 it's largely self-scheduled, it's meant to be very flexible 107 00:05:28,396 --> 00:05:30,746 so that we can keep as many alumni involved in the course, 108 00:05:31,016 --> 00:05:34,966 and to help their successors in the course and the computer lab. 109 00:05:34,966 --> 00:05:36,036 And then finally graders, 110 00:05:36,256 --> 00:05:38,996 I'll spend a few hours a week hours a week helping 111 00:05:38,996 --> 00:05:40,026 out with key sets. 112 00:05:40,026 --> 00:05:42,956 And finally, that's enough from me for the moment, 113 00:05:42,956 --> 00:05:44,956 let me invite an alumnus from CS50 114 00:05:44,956 --> 00:05:47,286 and a former TFN [inaudible] man, and now President 115 00:05:47,286 --> 00:05:49,596 of HCS, Kato Yuchiama. 116 00:05:50,246 --> 00:05:54,336 Oh sure, yeah. 117 00:05:54,686 --> 00:06:00,586 Let me get him a microphone, which is over here, okay. 118 00:06:01,326 --> 00:06:01,776 All yours. 119 00:06:02,786 --> 00:06:03,056 >> Kato Yuchiama: Hey. 120 00:06:03,736 --> 00:06:06,946 My name's Kato, I'm President of Harvard Computer Society. 121 00:06:07,816 --> 00:06:09,186 Today I'm here to invite you to an event 122 00:06:09,186 --> 00:06:11,226 that we are holding Friday in conjunction with the C's 123 00:06:11,226 --> 00:06:12,836 and CS department faculty. 124 00:06:13,096 --> 00:06:15,596 We're holding CS concentration cider and pie, 125 00:06:15,596 --> 00:06:20,456 so this is your opportunity to eat cider and pie. 126 00:06:20,746 --> 00:06:24,026 Well, in fact, it's actually for people interested in CS, 127 00:06:24,586 --> 00:06:27,326 people already concentrating in, people thinking 128 00:06:27,326 --> 00:06:29,196 of [inaudible] fielding in CS, you know, 129 00:06:29,196 --> 00:06:30,446 if you want to take any of those courses 130 00:06:30,446 --> 00:06:33,726 that David just mentioned, it's your opportunity 131 00:06:33,786 --> 00:06:36,066 to meet CS professors, and also upper classmen 132 00:06:36,066 --> 00:06:38,336 who are already concentrating in CS, so it's a great opportunity 133 00:06:38,336 --> 00:06:41,006 to ask questions, and it's not just the CS professor kind 134 00:06:41,006 --> 00:06:44,556 of thing because now you can ask people whether that class is, 135 00:06:44,556 --> 00:06:47,206 you know, is 124 actually a good class? 136 00:06:47,236 --> 00:06:48,376 You know, professors won't tell you the real answer, 137 00:06:48,406 --> 00:06:48,976 but upper classmen will. 138 00:06:49,916 --> 00:06:52,916 So, as it says here, it's a great opportunity 139 00:06:52,916 --> 00:06:55,606 to meet faculty, learn about cool classes, you can eat, 140 00:06:55,706 --> 00:07:00,626 not eat, meet CS undergrads, eat the food, win great prizes, 141 00:07:00,626 --> 00:07:03,086 we're still deciding that, but we are sure 142 00:07:03,136 --> 00:07:04,786 that there will be great prizes that you can win. 143 00:07:05,226 --> 00:07:09,056 And, also, its, you know, it's in a kind, 144 00:07:09,116 --> 00:07:10,636 we've never had a opportunity like this, 145 00:07:10,766 --> 00:07:13,106 at least in the 3 years that I've been here, 146 00:07:13,606 --> 00:07:16,106 so it should be great, should be great fun. 147 00:07:16,936 --> 00:07:21,826 So, that CS Concentration Cider and Pie, we asked that you RSVP 148 00:07:21,986 --> 00:07:25,986 on our Facebook event, if you're, if you want to RSVP 149 00:07:26,576 --> 00:07:29,746 at CS, go to HCS.Harvard.edu/cider, 150 00:07:29,746 --> 00:07:34,946 that's Harvard Computer Society.Harvard.edu/cider, 151 00:07:34,946 --> 00:07:36,666 you don't need to RSVP, so you can show up, its Friday 3 152 00:07:36,696 --> 00:07:38,316 to 4:30 in Maxwell's Dworkin lobby, and if you don't know 153 00:07:38,346 --> 00:07:39,006 where Maxwell Dworkin is, 154 00:07:39,036 --> 00:07:40,686 you can use David's awesome maps.cs50.net tool to look it 155 00:07:40,716 --> 00:07:41,976 up on the map, so thank you, and have a great time. 156 00:07:42,016 --> 00:07:42,286 [Applause] 157 00:07:42,286 --> 00:07:44,186 >>David: Thanks very much, I'll give this back to Jennifer. 158 00:07:45,296 --> 00:07:46,796 All right, so one pitch, if you didn't pick 159 00:07:46,796 --> 00:07:49,346 up your shuttle boy card, we have some 160 00:07:49,386 --> 00:07:51,036 with the teaching fellows on your way out today. 161 00:07:51,036 --> 00:07:54,056 It was kind of funny, we were looking over, 162 00:07:54,146 --> 00:07:56,136 so we have this form on the courses website now, 163 00:07:56,136 --> 00:07:59,046 as some of you may have noticed, and we wrote a little script 164 00:07:59,176 --> 00:08:01,456 in PHP that inserts registrations 165 00:08:01,456 --> 00:08:04,316 for shuttle boy card into our database, and what was funny was 166 00:08:04,316 --> 00:08:07,596 to see all the interest in this card on like Thursday, 167 00:08:07,596 --> 00:08:09,736 and Friday, after Wednesdays lecture, 168 00:08:09,736 --> 00:08:11,776 when we actually handed them out in person, 169 00:08:11,776 --> 00:08:15,176 so this little request form began this variable list 170 00:08:15,176 --> 00:08:16,906 of who was not here on Wednesday. 171 00:08:16,906 --> 00:08:19,826 The irony is, they're probably still not here today, 172 00:08:20,076 --> 00:08:22,016 but that's okay, we send them our best, and, 173 00:08:22,016 --> 00:08:24,326 we actually some 400 plus response, 174 00:08:24,326 --> 00:08:26,016 so we'll start mailing those out to your friends 175 00:08:26,016 --> 00:08:28,806 who probably filled out that form this week. 176 00:08:28,806 --> 00:08:31,896 A big shout out to our own Drew Rob, who is completely, 177 00:08:31,896 --> 00:08:33,946 trounced everyone on the big board. 178 00:08:34,406 --> 00:08:40,106 I looked up the word for this, its 113 quintillion dollars 179 00:08:40,106 --> 00:08:43,096 that he has made atop the big board, really putting 180 00:08:43,096 --> 00:08:45,636 to shame the leaders from last week, so this was all just 181 00:08:45,636 --> 00:08:48,836 for fun, clearly there was some opportunities to take advantage 182 00:08:48,836 --> 00:08:53,076 of here, but congrats to Drew and all of you nonetheless. 183 00:08:53,686 --> 00:08:56,726 So, without further ado, coming at you now, 184 00:08:56,836 --> 00:08:59,706 last advertisement today is store.cs50.net. 185 00:08:59,886 --> 00:09:02,336 The CS department actually has a tradition of having silly T- 186 00:09:02,336 --> 00:09:03,796 shirts and what-not at the end of the semester, 187 00:09:03,986 --> 00:09:07,456 I still remember my I Survived CS51 T-shirt 188 00:09:07,456 --> 00:09:09,796 from many years ago, and so we've continued on in 189 00:09:09,796 --> 00:09:12,176 that tradition, and thanks to this fancy website, 190 00:09:12,396 --> 00:09:16,976 can we sell all sorts of things to ourselves and such, 191 00:09:17,246 --> 00:09:20,946 so feel free to take that out, but allow me to indulge us 192 00:09:21,376 --> 00:09:25,456 in a little display perhaps of what's been designed 193 00:09:25,456 --> 00:09:26,856 by our own TF's this year. 194 00:09:30,516 --> 00:09:49,516 [ Music and Applause ] 195 00:09:50,016 --> 00:10:28,506 [ Inaudible Speaker ] 196 00:10:29,006 --> 00:11:06,826 [ Applause & Music ] 197 00:11:07,326 --> 00:11:10,226 >>David: So, as you know, final projects are coming 198 00:11:10,226 --> 00:11:13,606 up as is the CS50 fair, and we, CS50, were particularly proud 199 00:11:13,606 --> 00:11:15,036 to see very recently that some 200 00:11:15,036 --> 00:11:17,426 of our own CS50 alumni turned teaching fellows, 201 00:11:17,426 --> 00:11:20,206 some of them now, have been awarded a wonderful prize 202 00:11:20,206 --> 00:11:22,106 from AT & T, some of you may have seen this float 203 00:11:22,106 --> 00:11:24,576 around the house list, some of you may have on your own iPhone 204 00:11:24,576 --> 00:11:28,866 and iPods, the Rover App, by Harvard Student Agencies, 205 00:11:28,866 --> 00:11:32,106 and this actually grew out of CS50 final project a couple 206 00:11:32,106 --> 00:11:36,306 of years ago, and I thought I would give them a moment, 207 00:11:36,306 --> 00:11:38,866 give them a little bit of CS50 shout out here 208 00:11:39,026 --> 00:11:41,216 by showing this few minute video that they put together 209 00:11:41,216 --> 00:11:43,846 with AT & T. So, if you can think of something 210 00:11:43,986 --> 00:11:45,736 as magical yourselves to do this year, 211 00:11:45,946 --> 00:11:48,766 perhaps it will be your video we show at next year's class. 212 00:11:48,766 --> 00:11:48,976 Here we go. 213 00:11:49,516 --> 00:11:54,516 [ Silence ] 214 00:11:55,016 --> 00:11:59,000 [Music] 215 00:11:59,046 --> 00:12:01,146 >>Hi, my name is Winston, I'm from Virginia 216 00:12:01,746 --> 00:12:04,686 and I studied Physics here at Harvard, but I just really 217 00:12:04,686 --> 00:12:13,116 like working with my hands and making things. 218 00:12:13,566 --> 00:12:14,296 >>I'm Joy. 219 00:12:14,636 --> 00:12:15,826 I'm from San Diego, but I'm Canadian. 220 00:12:15,856 --> 00:12:16,996 I'm majoring in Computer Science and minoring 221 00:12:17,026 --> 00:12:18,586 in Visual Environmental Studies, and I like good designs 222 00:12:18,616 --> 00:12:18,976 and intuitive [inaudible]. 223 00:12:19,286 --> 00:12:22,136 >>I'm Cameron, I'm from Colorado, 224 00:12:22,576 --> 00:12:26,796 and [inaudible] Computer Science concentrator here. 225 00:12:26,966 --> 00:12:28,426 >>Okay, my name is Drew, and [inaudible] 226 00:12:29,116 --> 00:12:31,876 and study Physics [inaudible] enjoyed programming. 227 00:12:31,946 --> 00:12:36,156 >>My name is Alex, I'm an Engineering major 228 00:12:36,536 --> 00:12:40,136 from New Jersey, and for a very long time I've been interested 229 00:12:40,166 --> 00:12:40,976 in making [inaudible] devices more useful. 230 00:12:41,516 --> 00:12:44,606 [Music] 231 00:12:45,106 --> 00:12:45,886 >>Joy: Rover is a mobile platform 232 00:12:45,986 --> 00:12:49,786 to connect students with the community. 233 00:12:50,236 --> 00:12:57,956 The [inaudible] version, we implemented a student guidebook 234 00:12:57,956 --> 00:13:00,276 into a mobile format that had [inaudible] 235 00:13:00,376 --> 00:13:02,256 as well [inaudible] platform for version [inaudible] to be able 236 00:13:02,286 --> 00:13:02,976 to connect to the student. 237 00:13:03,526 --> 00:13:07,876 >>We also helped to connect students to their peers 238 00:13:08,356 --> 00:13:10,396 through student-to-student interactions. 239 00:13:10,396 --> 00:13:12,526 For example, student groups are often interested 240 00:13:12,526 --> 00:13:13,876 in getting more students to come to their events, 241 00:13:13,906 --> 00:13:15,196 so instead of posting fliers on a bulletin board, 242 00:13:15,226 --> 00:13:15,976 we can post fliers on Rover. 243 00:13:16,786 --> 00:13:19,506 Also, for example, you can have a free [inaudible], 244 00:13:19,796 --> 00:13:21,256 somewhat similar to the [inaudible], 245 00:13:21,256 --> 00:13:24,076 where anytime there's an event on campus that has free food, 246 00:13:24,346 --> 00:13:28,886 students can take advantage of that. 247 00:13:28,886 --> 00:13:30,116 >>Joy: And this platform is also a lot of potential 248 00:13:30,146 --> 00:13:31,076 for administration to communicate 249 00:13:31,106 --> 00:13:31,976 with students in a timely fashion, 250 00:13:33,606 --> 00:13:36,486 almost everyone has a mobile device, 251 00:13:36,916 --> 00:13:41,686 and so the platform will be a quick way to reach 252 00:13:41,896 --> 00:13:48,466 out to student, also for student to professor communication, 253 00:13:49,046 --> 00:13:50,116 [inaudible] great deal. 254 00:13:52,286 --> 00:13:53,996 >>All of this [inaudible] social networks. 255 00:13:54,306 --> 00:13:56,886 So, for example, if a student, who's a friend 256 00:13:56,916 --> 00:13:58,386 of yours is taking advantage of lots of free food deals, 257 00:13:58,416 --> 00:13:59,586 or is visiting a local merchant that they like 258 00:13:59,616 --> 00:14:00,876 or has had a great experience with a professor, 259 00:14:00,906 --> 00:14:02,316 we want to broadcast that to all of their other friends 260 00:14:02,346 --> 00:14:02,976 who are also using Rover. 261 00:14:03,736 --> 00:14:08,836 >>And, lastly, at the back end of all of this is analytics 262 00:14:08,836 --> 00:14:10,876 for our partners and merchants 263 00:14:10,986 --> 00:14:14,396 so that we can know exactly who's clicking on what, 264 00:14:14,716 --> 00:14:16,816 and when, and this really provides business intelligence 265 00:14:16,846 --> 00:14:17,656 and usage statistics for us, 266 00:14:17,686 --> 00:14:18,976 so that we know what's mostly useful for student. 267 00:14:20,256 --> 00:14:23,156 >>Rover is unique because it's an application that's written 268 00:14:23,326 --> 00:14:26,826 for students, entirely by students, with students in mind. 269 00:14:26,826 --> 00:14:29,496 All of the content on Rover is produced by students, 270 00:14:29,846 --> 00:14:32,506 all the deals are things that students really want. 271 00:14:32,536 --> 00:14:33,976 What student doesn't want a free burrito, for example. 272 00:14:34,516 --> 00:14:41,546 [ Music ] 273 00:14:42,046 --> 00:14:44,946 >>[Inaudible speaker comment] and we found out about how 274 00:14:45,096 --> 00:14:50,876 AT & T Big Mobile on campus helped them expand 275 00:14:50,986 --> 00:14:53,916 from just one campus to a number of campuses nationwide, 276 00:14:53,986 --> 00:14:55,836 and so by entering Big Mobile on campus, 277 00:14:56,396 --> 00:14:57,986 it really helped us think 278 00:14:58,306 --> 00:15:00,326 about how can we take what we've done here, 279 00:15:00,356 --> 00:15:01,976 in the Harvard Square community and extended it nationwide. 280 00:15:02,286 --> 00:15:04,376 >>[Inaudible] fantastic experience to work 281 00:15:05,196 --> 00:15:08,486 with AT & T people, to really bring out, 282 00:15:08,906 --> 00:15:15,276 to expose our application to, perhaps, a larger audience 283 00:15:15,886 --> 00:15:19,976 than we ever could have pitched it to without AT & T, 284 00:15:20,006 --> 00:15:21,566 so it's just a tremendous opportunity for us, and the fact 285 00:15:21,596 --> 00:15:22,976 that we have some nice prizes too, doesn't hurt as well. 286 00:15:24,046 --> 00:15:24,566 >>There's hundreds 287 00:15:24,786 --> 00:15:28,246 of applications being built every day, 288 00:15:28,246 --> 00:15:34,886 and it's certainly sometimes hard to distinguish yourself 289 00:15:34,986 --> 00:15:36,236 from all [inaudible] applications 290 00:15:36,236 --> 00:15:41,756 that are being developed, so this is huge help. 291 00:15:41,756 --> 00:15:45,126 >>I really like making things 292 00:15:45,126 --> 00:15:46,006 that our friends are able to use. 293 00:15:46,036 --> 00:15:47,026 I like making things that I like to use, 294 00:15:47,056 --> 00:15:47,956 and I know this application was made 295 00:15:47,986 --> 00:15:48,826 with Rover is something I consult, 296 00:15:48,856 --> 00:15:49,636 you know four or five times a day. 297 00:15:49,666 --> 00:15:50,986 >>Just to connect students and like mobile business, 298 00:15:51,016 --> 00:15:52,336 or like to get students into your local theatres, 299 00:15:52,366 --> 00:15:54,016 we have local arts and it's just the community, and we think 300 00:15:54,046 --> 00:15:54,976 that connection can be really powerful. 301 00:15:55,516 --> 00:15:57,546 [Music] 302 00:15:58,046 --> 00:15:59,996 >>David: So, and there, if you have an iPhone or iPod touch, 303 00:15:59,996 --> 00:16:02,546 and congrats to our alumni and where they've taken that. 304 00:16:02,546 --> 00:16:05,526 It's a, it's worth noting, lest you be quite awe struck 305 00:16:05,566 --> 00:16:07,096 by what these guys have all pulled off, 306 00:16:07,256 --> 00:16:10,366 that there's this kind of unspoken rule in programming, 307 00:16:10,846 --> 00:16:12,516 where anything you might ever want to do, 308 00:16:12,516 --> 00:16:15,206 and you've probably experienced this, probably takes twice 309 00:16:15,206 --> 00:16:18,096 as long, three times as long as you actually expect it to, 310 00:16:18,096 --> 00:16:20,786 so realize that this product is actually the work now 311 00:16:20,786 --> 00:16:24,636 of a couple of years of ongoing development, so realize that, 312 00:16:24,636 --> 00:16:28,066 don't worry that the bar has been set so high 313 00:16:28,066 --> 00:16:30,296 for your own final projects, what these guys essentially did 314 00:16:30,296 --> 00:16:32,866 for their first version was a very functional, 315 00:16:32,866 --> 00:16:36,136 and very nice prototype, sort of version 1 of this all, 316 00:16:36,286 --> 00:16:37,986 and they've continued to build on that as well, 317 00:16:37,986 --> 00:16:39,816 so we hope you too will dive into something 318 00:16:39,816 --> 00:16:43,176 that interests you, if not, for just this duration 319 00:16:43,176 --> 00:16:45,836 of this semester, even beyond, so congrats to those guys. 320 00:16:46,096 --> 00:16:52,306 All right, so today's goal is to focus a bit on what's been going 321 00:16:52,306 --> 00:16:53,636 on underneath the hood. 322 00:16:53,686 --> 00:16:54,806 So, what do we mean by that? 323 00:16:54,806 --> 00:16:57,276 Well, we took for granted, for some time, 324 00:16:57,276 --> 00:17:00,336 that you can write programming code in a language called C, 325 00:17:00,706 --> 00:17:03,746 you can then run a compiler called GCC, 326 00:17:03,746 --> 00:17:06,786 and out of that comes a program, and just in English, 327 00:17:07,016 --> 00:17:08,726 what does it mean to compile a program 328 00:17:08,726 --> 00:17:12,286 from source code into object code? 329 00:17:12,486 --> 00:17:13,146 Anyone at all? 330 00:17:13,146 --> 00:17:16,226 Yeah, in the back. 331 00:17:16,226 --> 00:17:16,426 >>[Inaudible Speaker Comment] 332 00:17:16,426 --> 00:17:18,516 >> David: Okay, so take text and interpret it, 333 00:17:18,516 --> 00:17:20,956 or let me tweak your words, convert it to binary. 334 00:17:21,016 --> 00:17:23,436 So, take something that's sort of pseudo English, pseudo code, 335 00:17:23,476 --> 00:17:25,226 or actual code, I'll run it 336 00:17:25,226 --> 00:17:27,456 through this program called the compiler, and the output 337 00:17:27,456 --> 00:17:30,076 of that is not just ascii characters that humans can read, 338 00:17:30,076 --> 00:17:33,256 but its zero's and one's that actual CPU's understand. 339 00:17:33,486 --> 00:17:36,686 So, what does it mean when Intel says, "Intel is inside" 340 00:17:36,686 --> 00:17:38,506 or you see this little sticker on PC's. 341 00:17:38,726 --> 00:17:41,016 Well, that means that the CPU, inside of the computer, 342 00:17:41,016 --> 00:17:43,816 was made by this company called Intel, now what does that mean? 343 00:17:43,816 --> 00:17:47,526 That means that they decided, some years ago now, 344 00:17:47,816 --> 00:17:51,016 that every CPU, the brains of a computer, 345 00:17:51,246 --> 00:17:52,856 would understand certain instructions, 346 00:17:53,056 --> 00:17:55,596 and what's rather mind blowing is that the instructions 347 00:17:55,686 --> 00:17:58,926 that all of our programs, whether p-set 1 348 00:17:58,926 --> 00:18:02,806 or p-set 8 reduced to, are basic things like addition 349 00:18:02,886 --> 00:18:05,876 and subtraction and multiplication, moving something 350 00:18:05,876 --> 00:18:08,846 from memory from here to here, loading something from disc 351 00:18:09,126 --> 00:18:12,156 or from here to here, these very basic primitives 352 00:18:12,156 --> 00:18:14,266 that we completely take for granted now, 353 00:18:14,596 --> 00:18:16,216 are really what's composed all 354 00:18:16,216 --> 00:18:17,896 of the programs you guys have been writing. 355 00:18:18,156 --> 00:18:20,066 So, just to put this into some perspective, 356 00:18:20,066 --> 00:18:22,726 let me go over to a terminal window here, and I'm going 357 00:18:22,726 --> 00:18:24,936 to open just a file called, Hello dot C, 358 00:18:24,936 --> 00:18:27,506 I didn't bother printing this out because it's pretty familiar 359 00:18:27,506 --> 00:18:29,496 by now, and that all there is to this. 360 00:18:29,496 --> 00:18:31,816 This is our canonical Hello World program. 361 00:18:32,116 --> 00:18:35,836 Well, this language C was actually an enhancement some 362 00:18:35,836 --> 00:18:38,996 years ago over a language called Assembly language, so, 363 00:18:39,206 --> 00:18:41,826 what you're about to see is a language that's much closer 364 00:18:41,826 --> 00:18:43,656 to the hardware, it's much more arcane, 365 00:18:43,836 --> 00:18:46,916 and it's certainly not nearly as much fun, if I'm even allowed 366 00:18:46,916 --> 00:18:48,986 to use that word in this context, than programming 367 00:18:48,986 --> 00:18:52,106 in C. So, what I'm going to do is run the compiler, GCC, 368 00:18:52,206 --> 00:18:54,416 but I'm going to use perhaps an unfamiliar flag, 369 00:18:54,416 --> 00:18:57,596 I'm going to say "dash capital S", and then I'm going to say 370 00:18:57,596 --> 00:19:01,596 "Hello dot C" and what I'm going to get as output, per LS here, 371 00:19:01,836 --> 00:19:04,966 is a hello dot S, so this is an intermediate file 372 00:19:04,966 --> 00:19:07,836 that we actually never really see, not by default, 373 00:19:08,026 --> 00:19:11,526 but inside of here is what the compiler is doing 374 00:19:11,526 --> 00:19:13,216 for this very basic program. 375 00:19:13,216 --> 00:19:16,806 So, this is an intermediate step between C source code, 376 00:19:16,806 --> 00:19:19,406 and what's called object code, zeros, and ones. 377 00:19:19,406 --> 00:19:20,726 Well, what do I mean by that? 378 00:19:20,726 --> 00:19:22,966 Well, let's see, there's really not much to this file. 379 00:19:22,966 --> 00:19:24,796 It might look a little cryptic, let me shrink 380 00:19:24,796 --> 00:19:27,166 down the font a little bit, and re-open it, 381 00:19:27,166 --> 00:19:30,886 there's really not much too it, 20, 30 lines here, 382 00:19:30,886 --> 00:19:32,696 and there's some new syntax here, 383 00:19:32,696 --> 00:19:35,906 and all of this is actually specific to Intel Inside. 384 00:19:36,186 --> 00:19:38,546 Because I'm running this program on a computer 385 00:19:38,546 --> 00:19:40,456 that has Intel hardware inside of it, 386 00:19:40,666 --> 00:19:43,056 these are literally the instructions 387 00:19:43,236 --> 00:19:45,256 that that CPU understands. 388 00:19:45,256 --> 00:19:46,876 Well, let's see if we can't make sense of some of this. 389 00:19:47,286 --> 00:19:50,456 So, at the top here, this seems to be somewhat uninteresting, 390 00:19:50,456 --> 00:19:52,846 apparently the original name of the file. 391 00:19:52,916 --> 00:19:56,116 Here's a dot section directive, whatever that means, dot RO. 392 00:19:56,116 --> 00:19:58,336 What might this mean, dot RO? 393 00:19:58,886 --> 00:20:01,596 So, read-only, so read-only data, apparently, 394 00:20:01,596 --> 00:20:04,126 comes here at the top, now why does that make sense? 395 00:20:04,126 --> 00:20:06,716 Well, just below this read-only data section, 396 00:20:06,936 --> 00:20:08,086 there's this cryptic string, 397 00:20:08,086 --> 00:20:10,916 but then something a little more familiar, namely the string, 398 00:20:10,916 --> 00:20:13,656 Hello World, which I hardcoded into my program, 399 00:20:13,876 --> 00:20:15,966 and is therefore itself a read-only string. 400 00:20:15,996 --> 00:20:19,046 I could change what, I could add strings to this program 401 00:20:19,046 --> 00:20:21,076 and such, but this is the one I hardcoded in here, 402 00:20:21,436 --> 00:20:23,716 so there we have this piece of data, 403 00:20:24,056 --> 00:20:25,766 dot text, what did this denote? 404 00:20:26,546 --> 00:20:27,756 If you can think back a few weeks? 405 00:20:27,756 --> 00:20:30,216 What is the text section of your program? 406 00:20:32,296 --> 00:20:33,746 Anyone recall? 407 00:20:33,746 --> 00:20:34,046 >>[Inaudible Speaker Comment] 408 00:20:34,046 --> 00:20:36,296 >>David: Say it a little louder. 409 00:20:36,296 --> 00:20:37,536 >>[Inaudible Speaker Comment] 410 00:20:37,536 --> 00:20:38,716 >>David: So, what you were coding, 411 00:20:38,716 --> 00:20:41,216 so this was the actual program, 412 00:20:41,216 --> 00:20:42,656 the code that you actually wrote. 413 00:20:42,836 --> 00:20:44,576 The review sections, remember this rectangle? 414 00:20:44,576 --> 00:20:47,956 We had the heap, we had the stack, we had initialized data, 415 00:20:47,956 --> 00:20:50,036 uninitialized data, and those last two related 416 00:20:50,036 --> 00:20:52,446 to global variables, but then above everything 417 00:20:52,446 --> 00:20:54,726 in that picture was the text section, 418 00:20:54,976 --> 00:20:56,406 and text just meant your program, 419 00:20:56,616 --> 00:20:58,646 so this actually makes sense, because below text, 420 00:20:58,646 --> 00:21:01,046 dot text here, here comes our program. 421 00:21:01,316 --> 00:21:03,916 So, this looks like, here comes a functions that's apparently 422 00:21:03,916 --> 00:21:06,726 called Main, all right, here is the main function, 423 00:21:06,726 --> 00:21:07,766 what goes on here? 424 00:21:07,766 --> 00:21:10,666 Well, these are these very basic primitive that I alluded 425 00:21:10,666 --> 00:21:12,536 to earlier, and some of them we can infer. 426 00:21:12,686 --> 00:21:16,236 Looks like there's a subtract operation, an and operation, 427 00:21:16,276 --> 00:21:20,236 a move operation to move things around in memory, add is in here 428 00:21:20,236 --> 00:21:22,366 as well, and L usually denotes long, 429 00:21:22,366 --> 00:21:24,886 so these are actually manipulating 32 bit values, 430 00:21:24,886 --> 00:21:26,876 in this case here, but that's it. 431 00:21:26,876 --> 00:21:31,136 That's all it takes to implement Hello World, and some years ago, 432 00:21:31,136 --> 00:21:32,886 if you wanted to write Hello World, 433 00:21:33,236 --> 00:21:35,196 this was the stuff that you wrote. 434 00:21:35,536 --> 00:21:37,646 Rewind a little further, in what you actually wrote, 435 00:21:37,646 --> 00:21:40,116 were punch cards, right, things with holes and what-not, 436 00:21:40,116 --> 00:21:42,046 that you actually fed physically into a machine 437 00:21:42,046 --> 00:21:45,276 and it would parse it, so we've come a long way, and certainly, 438 00:21:45,276 --> 00:21:47,236 if you think now to implementing in PHP, 439 00:21:47,236 --> 00:21:50,076 like you did this past week and will this next week, 440 00:21:50,336 --> 00:21:52,556 we've come a significantly far way here, 441 00:21:52,826 --> 00:21:55,636 but it's all the same stuff that's been around for 20, 442 00:21:55,696 --> 00:21:58,836 30 years, even since Apple debuted that particular video. 443 00:21:59,056 --> 00:22:00,276 So, what's really going on? 444 00:22:00,276 --> 00:22:03,126 Well, let's take a look at some, let's come back to this picture 445 00:22:03,126 --> 00:22:04,456 in a moment, and consider this. 446 00:22:05,026 --> 00:22:06,386 So, when you compile something, 447 00:22:06,386 --> 00:22:07,926 we've kind of been waving our hands, 448 00:22:07,926 --> 00:22:09,836 or taking for granted some of the things that go on, 449 00:22:09,836 --> 00:22:11,876 none of them are very complicated, but we just, 450 00:22:11,876 --> 00:22:13,226 they all seem to happen at once. 451 00:22:13,576 --> 00:22:17,166 So, when you run GCC, there's five steps that happen 452 00:22:17,166 --> 00:22:19,386 between the time you write your code and run your code. 453 00:22:19,606 --> 00:22:21,436 So, the first step is called pre-processing. 454 00:22:22,166 --> 00:22:24,996 So pre-processing, we've actually used ourselves. 455 00:22:24,996 --> 00:22:29,436 Anytime you use slash include or slash define, 456 00:22:29,436 --> 00:22:31,836 if you say that in certain pieces of code we gave you, 457 00:22:32,076 --> 00:22:35,356 that's actually pre-processor directives, 458 00:22:35,656 --> 00:22:39,016 and GCC first does a pass from top to bottom, left to right 459 00:22:39,016 --> 00:22:41,516 over all of your code, and anywhere it sees, sorry, 460 00:22:41,516 --> 00:22:46,466 I think I might have said slash, sharp symbol, the sharp symbol 461 00:22:46,466 --> 00:22:48,996 and then include, or sharp define, it says "Oh, 462 00:22:49,156 --> 00:22:50,666 this is a pre- processor directive, 463 00:22:50,926 --> 00:22:52,686 let me do something with this. 464 00:22:52,686 --> 00:22:55,316 If its sharp define, what do I want to do? 465 00:22:55,316 --> 00:22:57,076 I want to do a find and replace for all 466 00:22:57,076 --> 00:22:59,186 of these global constants, and replace it 467 00:22:59,186 --> 00:23:00,916 with the actual value that's been defined. 468 00:23:01,136 --> 00:23:04,406 If it says sharp include, I want to go grab the foo dot H file, 469 00:23:04,476 --> 00:23:08,016 open it, and literally paste its contents into this location 470 00:23:08,016 --> 00:23:11,126 in the file, and then proceed with step 2. 471 00:23:11,406 --> 00:23:14,836 Its step 2 when your code is actually compiled, so we've kind 472 00:23:14,836 --> 00:23:16,026 of clumped all of these steps 473 00:23:16,026 --> 00:23:17,786 into just this one big word compiled, 474 00:23:18,116 --> 00:23:19,826 but compiling is really the second step. 475 00:23:20,166 --> 00:23:21,816 You've now got a big piece of code, 476 00:23:21,816 --> 00:23:23,416 all of these sharp includes 477 00:23:23,416 --> 00:23:27,646 and sharp defines have actually been pre-processed, so now, 478 00:23:27,646 --> 00:23:31,556 the compiler, GCC, takes all of that code and converts it 479 00:23:31,556 --> 00:23:36,166 from your source code, into assembly code, 480 00:23:36,166 --> 00:23:38,626 the stuff that we just saw on the board a moment ago. 481 00:23:38,876 --> 00:23:40,986 And, then there's another step that's happening behind the 482 00:23:40,986 --> 00:23:44,086 scenes, all of that assembly code is then converted 483 00:23:44,086 --> 00:23:46,936 or assembled into object code, 484 00:23:47,246 --> 00:23:50,196 so object code is ultimately the zeros and ones, 485 00:23:50,196 --> 00:23:53,766 so anytime you've seen, in your directory's those dot O files, 486 00:23:54,126 --> 00:23:56,086 some of them you didn't create yourself, right, 487 00:23:56,086 --> 00:23:58,856 and odds are you just wondered what they were, on first glance, 488 00:23:58,856 --> 00:24:00,476 make clean, usually deleted them, 489 00:24:00,616 --> 00:24:02,746 well what were all those dot O files? 490 00:24:03,046 --> 00:24:05,056 Those were object files, 491 00:24:05,056 --> 00:24:07,746 those were the binary files containing zeros and ones 492 00:24:07,746 --> 00:24:10,276 that were the result of compile speller dot C, 493 00:24:10,536 --> 00:24:14,236 or dictionary dot C, or any number of other dot C files 494 00:24:14,236 --> 00:24:15,136 that you happen to write. 495 00:24:15,566 --> 00:24:17,916 But, then there's one last step, and some of you tripped 496 00:24:17,916 --> 00:24:20,526 over this early on, if you didn't know what flags to use, 497 00:24:20,796 --> 00:24:24,036 sometimes you had to add that dash L flag to your make file, 498 00:24:24,036 --> 00:24:27,806 or dash L to the end of you GCC statement, and what did 499 00:24:27,806 --> 00:24:31,056 that mean or what's an example of having to use dash L 500 00:24:31,406 --> 00:24:32,896 on the GCC command line? 501 00:24:33,396 --> 00:24:36,726 It's kind of a hint up here in a big font, but. 502 00:24:36,726 --> 00:24:37,876 >>[Inaudible Speaker Comment] 503 00:24:37,876 --> 00:24:40,736 >>David: So, linking CS50, so anytime you use get [inaudible] 504 00:24:41,106 --> 00:24:46,016 or get float, or get string, you had to link N with dash L CS50, 505 00:24:46,016 --> 00:24:47,906 and it was kind of stupid, but you always had 506 00:24:47,906 --> 00:24:50,876 to put the dash L something at the very end 507 00:24:50,876 --> 00:24:53,336 of the command line, but that's actually consistent 508 00:24:53,336 --> 00:24:56,406 with the reality that his linking step is very much 509 00:24:56,406 --> 00:24:57,876 at the end of the whole process, 510 00:24:57,876 --> 00:25:00,096 it's sort of the last thing GCC needs to know. 511 00:25:00,376 --> 00:25:01,226 So, what does that mean? 512 00:25:01,226 --> 00:25:05,186 Well, when you compile your code, like let's take an example 513 00:25:05,186 --> 00:25:09,496 like Mario dot C. So when you have Mario dot C and you compile 514 00:25:09,496 --> 00:25:13,326 that with GCC, you ultimately get a Mario dot O file, 515 00:25:13,326 --> 00:25:16,036 but if you also use the get [inaudible] function 516 00:25:16,036 --> 00:25:18,436 from CS50's library, that means 517 00:25:18,436 --> 00:25:22,036 that you'd had sharp include CS50 dot H. So, 518 00:25:22,036 --> 00:25:23,966 the pre-processor copied and pasted all 519 00:25:23,966 --> 00:25:25,506 of the dot H files contents 520 00:25:25,506 --> 00:25:27,406 and in there were the function declarations, 521 00:25:27,406 --> 00:25:29,136 some global constants, stuff like that, 522 00:25:29,646 --> 00:25:32,416 but behind the scenes what was happening was GCC had 523 00:25:32,416 --> 00:25:37,026 to go compile and find CS50 dot C, and this is a bit 524 00:25:37,026 --> 00:25:40,116 of a white lie because we optimized away this particular 525 00:25:40,116 --> 00:25:42,016 need, but essentially at this point in the story, 526 00:25:42,016 --> 00:25:44,526 you have Mario dot C compiled to Mario dot O, 527 00:25:44,686 --> 00:25:48,046 you had CS50 dot C somewhere on the server compiled 528 00:25:48,046 --> 00:25:52,076 to CS50 dot O, so now you have these two independent files, 529 00:25:52,126 --> 00:25:54,146 both of which contain a bunch of zeros and ones, 530 00:25:54,336 --> 00:25:57,636 object code that Intel CPU's understand. 531 00:25:57,866 --> 00:26:00,816 You now need to literally merge these things together, 532 00:26:00,896 --> 00:26:04,976 link them together, so the last step that GCC does for you, 533 00:26:05,196 --> 00:26:07,946 is it takes this dot O file, it takes this dot O file, 534 00:26:07,946 --> 00:26:10,196 and it smashes them together and lays them 535 00:26:10,196 --> 00:26:13,076 out in an appropriate way in memory and on disc, 536 00:26:13,356 --> 00:26:17,016 so that what you have at the end is just one executable file, 537 00:26:17,076 --> 00:26:19,716 called Mario, or called Mario dot exe, 538 00:26:19,716 --> 00:26:21,466 or whatever the case may be, and then you, 539 00:26:21,466 --> 00:26:23,416 the user, can finally run that. 540 00:26:23,606 --> 00:26:25,156 So, just to put a picture to this, 541 00:26:25,156 --> 00:26:28,436 if we have the same example, Hello dot C, 542 00:26:28,696 --> 00:26:30,086 it's a little blurry on the screen here, 543 00:26:30,086 --> 00:26:31,776 but here are three of those steps. 544 00:26:31,776 --> 00:26:35,486 If I compile Hello dot C, here is that source code in C 545 00:26:35,746 --> 00:26:38,096 at the very top, that's, again, my so-called source code, 546 00:26:38,346 --> 00:26:41,206 I compile it, what that give me then, 547 00:26:41,206 --> 00:26:44,916 is this stuff called assembly language, which is much closer 548 00:26:44,916 --> 00:26:47,216 to the CPU's language. 549 00:26:47,216 --> 00:26:50,076 It's much clearer to the CPU what all this is, 550 00:26:50,296 --> 00:26:51,806 but it's much less clear, dare say, 551 00:26:51,806 --> 00:26:53,726 to the human, what all of this is. 552 00:26:53,776 --> 00:26:55,396 But, it's the same code converted 553 00:26:55,396 --> 00:26:58,426 to the basic building blocks; add, subtract, move, 554 00:26:58,696 --> 00:27:02,306 that the CPU itself understands, but it's still more English 555 00:27:02,306 --> 00:27:04,676 or pseudo code than it is actual zeros and ones, 556 00:27:04,956 --> 00:27:08,906 so the final step of assembling is what actually generates, 557 00:27:09,096 --> 00:27:11,806 during the assembly process, those zeros and ones, 558 00:27:11,806 --> 00:27:14,416 and these zeros and ones are literally what happens, 559 00:27:14,576 --> 00:27:17,386 when you compile Hello World on an X86, 560 00:27:17,486 --> 00:27:19,756 on an Intel computer, using GCC. 561 00:27:19,756 --> 00:27:21,356 Eventually, you get those zeros and ones. 562 00:27:21,356 --> 00:27:23,716 You actually get a lot more zeros and ones that would fit 563 00:27:23,716 --> 00:27:26,066 on the slide, but you get patterns of zeros 564 00:27:26,066 --> 00:27:27,466 and ones just like that. 565 00:27:27,856 --> 00:27:30,366 So, how does the CPU go about executing this program? 566 00:27:30,666 --> 00:27:33,826 Well, essentially it gets fed piece by piece by piece. 567 00:27:33,826 --> 00:27:36,366 And even though we, the humans, can't really see what's going 568 00:27:36,366 --> 00:27:39,456 on here, these patterns of zeros and ones here are laid 569 00:27:39,456 --> 00:27:43,766 out in sequences of 8 bits, and you may recall 570 00:27:43,766 --> 00:27:45,186 that most CPU's we've talked 571 00:27:45,186 --> 00:27:47,996 about in this class are 32 bits long, so, 572 00:27:47,996 --> 00:27:50,526 or are 32 bit architectures, although when we moved 573 00:27:50,526 --> 00:27:52,886 to the Cloud, it became 64 bits, but for the most part, 574 00:27:53,136 --> 00:27:56,166 32 bit computers are still very much in vogue, 575 00:27:56,536 --> 00:27:57,556 so what does this mean? 576 00:27:57,556 --> 00:28:00,786 Well this means a CPU can understand 32 bits at a time, 577 00:28:01,106 --> 00:28:03,586 so when you run a program, when you double-click its icon, 578 00:28:03,586 --> 00:28:07,146 run it at the command line, 32 bits at a time are fed 579 00:28:07,146 --> 00:28:11,086 from your program into the CPU, inside of your computer, 580 00:28:11,086 --> 00:28:13,676 and some of those bits, usually the first several bits, 581 00:28:14,016 --> 00:28:16,246 tell the CPU what instruction to use, 582 00:28:16,456 --> 00:28:18,216 whether its add or subtract or move. 583 00:28:18,506 --> 00:28:21,986 And then the last 8 bits and the last 8 bits, after you have 8 584 00:28:21,986 --> 00:28:24,946 or 16 at the beginning, the last bits usually reference these 585 00:28:24,946 --> 00:28:26,566 things called registers. 586 00:28:26,906 --> 00:28:29,516 So registers, we actually said very early on in the course, 587 00:28:29,516 --> 00:28:31,846 are the smallest units of memory that are use, 588 00:28:31,896 --> 00:28:34,266 that are actually useful to a typical computer. 589 00:28:34,266 --> 00:28:38,306 Inside of the CPU, are generally 32 or 64, 590 00:28:38,586 --> 00:28:41,656 things called registers, and these are very small chunks 591 00:28:41,656 --> 00:28:43,826 of memory, it's kind of like RAM, but much smaller, 592 00:28:44,116 --> 00:28:49,856 you have 32 bits of memory that is, ultimately, the location 593 00:28:50,246 --> 00:28:52,156 that your operands are stored. 594 00:28:52,156 --> 00:28:52,966 What do I mean by that? 595 00:28:52,966 --> 00:28:54,206 Well, CPU, at the end of the day, 596 00:28:54,206 --> 00:28:55,506 when it adds two things together, 597 00:28:55,506 --> 00:28:57,876 it literally adds this thing to this thing, 598 00:28:57,876 --> 00:29:01,126 it doesn't string 10 different values together and add them all 599 00:29:01,126 --> 00:29:03,916 at once, it generally operates on two inputs at a time, 600 00:29:04,226 --> 00:29:06,006 so usually two registers are used, 601 00:29:06,006 --> 00:29:08,286 two little tiny storage areas in memory, 602 00:29:08,556 --> 00:29:11,396 the CPU adds those values together, puts the results 603 00:29:11,396 --> 00:29:14,776 in another register, and the process repeats. 604 00:29:14,876 --> 00:29:17,996 So, in short, it's a huge leap to make, mentally, 605 00:29:17,996 --> 00:29:21,716 from a PHP program, or even a C program, down to this level 606 00:29:21,716 --> 00:29:24,656 of zeros and ones, but there's been many years of development 607 00:29:24,696 --> 00:29:28,616 from this low level to punch cards, to assembly code, to C, 608 00:29:28,616 --> 00:29:31,166 to PHP, so that everything actually has been built 609 00:29:31,166 --> 00:29:32,826 on top of prior work. 610 00:29:32,826 --> 00:29:35,536 So, if you like sort of what you're sensing is underneath the 611 00:29:35,536 --> 00:29:38,246 hood, the course in question, here at Harvard at least, 612 00:29:38,246 --> 00:29:40,676 would be CS141, this is computer hardware, 613 00:29:40,876 --> 00:29:42,606 and you can even get a taste of this kind of stuff 614 00:29:42,606 --> 00:29:45,736 in like Physics 123, which is a fun, hands-on course as well. 615 00:29:46,026 --> 00:29:47,716 So, there's a lot going on there, but at the end 616 00:29:47,716 --> 00:29:51,156 of the day, it reduces to these very basic principles. 617 00:29:51,526 --> 00:29:53,266 All right, so here's a more concrete example 618 00:29:53,266 --> 00:29:56,156 where we actually have multiple dot O files, 619 00:29:56,156 --> 00:29:57,366 or multiple dot C files. 620 00:29:57,366 --> 00:30:00,556 So, on the left here is just a picture of compiling, again, 621 00:30:00,556 --> 00:30:03,446 something like Hello dot C, but Hello dot C, remember, 622 00:30:03,486 --> 00:30:07,576 uses Print F, so that previous, this pictorial, 623 00:30:07,756 --> 00:30:10,286 was a bit misleading, because we didn't actually acknowledge 624 00:30:10,286 --> 00:30:13,306 that there was Print F and in what library is Print F defined, 625 00:30:14,636 --> 00:30:16,236 and what header file is it declared? 626 00:30:16,236 --> 00:30:17,696 >>[Inaudible Speaker Comment] 627 00:30:17,696 --> 00:30:19,026 >>David: Yeah, it's a standard IO dot H, 628 00:30:19,026 --> 00:30:20,426 so that's because someone else, 629 00:30:20,426 --> 00:30:22,426 the people who wrote the C compiler, 630 00:30:22,696 --> 00:30:25,386 wrote a file called Standard IO dot C, 631 00:30:25,426 --> 00:30:27,916 and Standard I dot O dot H, 632 00:30:28,126 --> 00:30:31,296 and inside the dot C file is the implementation of Print F, 633 00:30:31,296 --> 00:30:34,236 so I'm writing a program called Hello dot C, 634 00:30:34,236 --> 00:30:36,956 and I'm using Print F, yes, I compile it, 635 00:30:37,266 --> 00:30:40,346 that gives me assembly code, yes, I then assemble it, and, 636 00:30:40,346 --> 00:30:42,796 again, all of this happens for you with modern compilers, 637 00:30:42,796 --> 00:30:45,606 like GCC, and out of that comes zeros and ones, 638 00:30:45,806 --> 00:30:47,566 well there's actually another step here. 639 00:30:47,816 --> 00:30:51,996 In this first step, recall that I included Standard IO dot H, 640 00:30:52,236 --> 00:30:54,566 so the fact that that gets copied and pasted 641 00:30:54,566 --> 00:30:57,426 into my header file is a clue to the compiler that, oh, 642 00:30:57,426 --> 00:31:01,206 I actually need the functions that, 643 00:31:01,206 --> 00:31:04,736 the code that implements Print F. Well, where is that? 644 00:31:05,016 --> 00:31:06,356 Typically, it's going to be in a file 645 00:31:06,356 --> 00:31:10,026 like Standard IO dot C. This lives elsewhere on the system, 646 00:31:10,026 --> 00:31:11,926 you don't even know or care where it is, 647 00:31:12,296 --> 00:31:14,226 but what this inclusion, 648 00:31:14,226 --> 00:31:17,246 sharp include tells the compiler essentially is, oh, you're going 649 00:31:17,246 --> 00:31:20,906 to need to use this code, so let me find Standard IO dot C, 650 00:31:21,146 --> 00:31:23,686 let me compile it, or make sure it's already compiled, 651 00:31:23,686 --> 00:31:26,966 that gives me assembly code, then I need to assemble that, 652 00:31:26,966 --> 00:31:29,476 which gives me the zeros and ones, and then that final step, 653 00:31:29,476 --> 00:31:33,246 linking, is to actually merge my bits with the standard bits, 654 00:31:33,656 --> 00:31:36,006 merge them together and get one executable, 655 00:31:36,006 --> 00:31:39,296 the Hello binary, or Hello dot exe. 656 00:31:39,596 --> 00:31:44,686 So, why, though, have you never had to do dash L STD IO? 657 00:31:45,786 --> 00:31:48,156 Since it seems that that was the necessary magic 658 00:31:48,186 --> 00:31:50,176 to make this work for CS50's library. 659 00:31:50,176 --> 00:31:55,156 Why do you not need to type dash L Standard IO? 660 00:31:55,246 --> 00:31:56,856 Feels like there's an inconsistency here. 661 00:31:57,356 --> 00:32:00,966 >>[Inaudible Speaker Comment] 662 00:32:01,466 --> 00:32:02,696 >>David: Yeah, it's common enough 663 00:32:02,696 --> 00:32:04,216 that the compiler already links it in. 664 00:32:04,216 --> 00:32:04,966 So, what does that mean? 665 00:32:05,176 --> 00:32:06,786 Well, they're standard for a reason. 666 00:32:06,786 --> 00:32:09,576 The fact that it's Standard IO, Standard LIB, 667 00:32:09,836 --> 00:32:12,386 means that these are standard enough that you just don't have 668 00:32:12,386 --> 00:32:14,956 to provide that linker flag, it's essentially provided 669 00:32:14,956 --> 00:32:16,246 for you automatically. 670 00:32:16,466 --> 00:32:19,006 So that's all that's really been happening underneath the hood 671 00:32:19,006 --> 00:32:23,976 there, is this whole process, but largely unbeknownst to you, 672 00:32:23,976 --> 00:32:26,646 and just as an aside, there's one detail that's kind 673 00:32:26,646 --> 00:32:29,106 of interesting to realize, especially if you're a PC user, 674 00:32:29,106 --> 00:32:32,766 those of you with PC's, have you ever seen or heard of DLL files? 675 00:32:33,566 --> 00:32:34,796 Anyone? Kind of sort of? 676 00:32:34,796 --> 00:32:39,206 Okay, so what are they, if you've all seen them? 677 00:32:39,206 --> 00:32:39,276 >>[Inaudible Speaker Comment] 678 00:32:39,276 --> 00:32:41,186 >>David: Okay good, [inaudible] pedagogical answer. 679 00:32:41,186 --> 00:32:41,666 What are they? 680 00:32:41,956 --> 00:32:45,346 So, what is a DLL file, so that stands for dynamic link library, 681 00:32:45,586 --> 00:32:48,596 and without going into too much WIN32 or Windows detail, 682 00:32:48,866 --> 00:32:50,936 that's the same idea as what's going on here. 683 00:32:50,936 --> 00:32:53,916 There's two ways to link programs together. 684 00:32:54,196 --> 00:32:55,916 You can either statically link them, 685 00:32:56,006 --> 00:32:57,496 or you can dynamically link them. 686 00:32:57,496 --> 00:32:58,286 Well, what does that mean? 687 00:32:58,576 --> 00:33:02,156 This picture here is describing static linking, and in fact, 688 00:33:02,156 --> 00:33:04,776 it's kind of a white lie depiction 689 00:33:04,776 --> 00:33:06,586 of what you guys have been doing, because generally 690 00:33:06,586 --> 00:33:08,696 if you want this picture to happen, 691 00:33:09,036 --> 00:33:11,536 you have to pass GCC the dash static flag, 692 00:33:11,796 --> 00:33:14,896 and say statically compile this, but that's okay here, 693 00:33:15,436 --> 00:33:18,646 because the take away is that this means static compiling, 694 00:33:18,646 --> 00:33:21,516 which means, when you get this executable file, 695 00:33:21,556 --> 00:33:24,986 your Mario program, you Hello program, in theory, you can move 696 00:33:24,986 --> 00:33:28,336 that program from computer to computer to computer and so long 697 00:33:28,336 --> 00:33:30,806 as you move it to another computer that has the same CPU, 698 00:33:30,996 --> 00:33:33,156 you can run at the command line, or double-click it there, 699 00:33:33,156 --> 00:33:34,716 and it will simply work. 700 00:33:35,006 --> 00:33:37,926 By contrast, if you dynamically link a program, 701 00:33:38,156 --> 00:33:39,586 it's not necessarily going to work 702 00:33:39,586 --> 00:33:40,956 if you move it to another computer. 703 00:33:40,956 --> 00:33:42,146 Any of you who have ever tried 704 00:33:42,146 --> 00:33:44,626 to copy programs you've installed on your computer, 705 00:33:44,916 --> 00:33:48,056 Microsoft Word or Photoshop or AOL instant messenger, 706 00:33:48,366 --> 00:33:52,456 its generally not sufficient to click and drag the dot exe file, 707 00:33:52,456 --> 00:33:54,056 and put it on your other computer, 708 00:33:54,056 --> 00:33:55,596 or put it on our friends computer, 709 00:33:55,786 --> 00:33:58,526 because there's usually a lot more files that comprise 710 00:33:58,686 --> 00:34:01,626 that actual program, many of them these dot DLL files. 711 00:34:01,916 --> 00:34:05,256 So, the other way to link programs together is not 712 00:34:05,296 --> 00:34:09,306 to create one binary that is the result of combining bits 713 00:34:09,306 --> 00:34:11,176 from the left with bits from the right, 714 00:34:11,616 --> 00:34:14,516 but rather you just take your own bits from the left, 715 00:34:14,516 --> 00:34:17,026 and you include inside of the binary, 716 00:34:17,026 --> 00:34:21,566 inside of the executable, essentially the path to files 717 00:34:21,566 --> 00:34:25,426 on the local hard drive that contain Standard dot IO, 718 00:34:25,426 --> 00:34:29,966 Standard IO bits, or the CS50 library bits, in other words, 719 00:34:29,966 --> 00:34:33,986 its dynamic in that you need, in order to run this program, 720 00:34:33,986 --> 00:34:37,626 you need to have those other files installed on the computer. 721 00:34:37,936 --> 00:34:40,086 So, this is good and bad. 722 00:34:40,086 --> 00:34:42,836 What is a upside, based on that definition 723 00:34:42,836 --> 00:34:44,476 of statically linking your programs? 724 00:34:44,646 --> 00:34:46,776 What's one good thing about it that comes to mind. 725 00:34:47,166 --> 00:34:47,346 Yes? 726 00:34:47,496 --> 00:34:49,886 >>It takes up less space because you don't have repetition 727 00:34:49,886 --> 00:34:51,446 of the Standard IO in every. 728 00:34:51,596 --> 00:34:52,636 >>David: If you statically link. 729 00:34:53,386 --> 00:34:53,856 >>Right. 730 00:34:53,856 --> 00:34:55,176 >>David: If you, that's dynamic. 731 00:34:56,546 --> 00:34:58,646 Okay. So, an advantage of dynamic linking is 732 00:34:58,646 --> 00:35:00,546 that you don't have this redundancy, right? 733 00:35:00,546 --> 00:35:03,156 Because if you're dynamically linking, you just have one copy 734 00:35:03,156 --> 00:35:08,206 of Standard IO dot O or CS50 dot O, and you dynamically linked 735 00:35:08,206 --> 00:35:10,296 against them so that you don't make copies of all 736 00:35:10,296 --> 00:35:12,116 of the bits comprised in those libraries again 737 00:35:12,116 --> 00:35:12,756 and again and again. 738 00:35:13,176 --> 00:35:14,666 All right, so that's one advantage, and in fact, 739 00:35:14,666 --> 00:35:17,026 that's why Microsoft does it with so many of their products, 740 00:35:17,246 --> 00:35:19,036 because you can have these shared libraries, 741 00:35:19,036 --> 00:35:20,426 these dynamic link libraries, 742 00:35:20,596 --> 00:35:23,036 and just not waste disc space unnecessarily. 743 00:35:23,296 --> 00:35:24,356 So, what's now an upside 744 00:35:24,356 --> 00:35:26,376 of statically linking your programs together? 745 00:35:27,516 --> 00:35:28,446 Anyone at all? 746 00:35:29,066 --> 00:35:29,226 Okay. 747 00:35:29,226 --> 00:35:32,336 >>You don't have the problem that I always get 748 00:35:32,336 --> 00:35:35,856 if you're missing a DLL file and nothing [inaudible]. 749 00:35:35,976 --> 00:35:36,076 >>David: Good. 750 00:35:36,186 --> 00:35:39,066 So you don't have the problem of double-clicking that program, 751 00:35:39,066 --> 00:35:41,466 or running it at the command line and being told, cannot run, 752 00:35:41,466 --> 00:35:44,696 cannot find foo dot DLL or some other program like that. 753 00:35:45,016 --> 00:35:47,106 It's actually self-contained program, 754 00:35:47,316 --> 00:35:49,506 a program that's completely portable, you can copy it, 755 00:35:49,506 --> 00:35:52,546 move it anywhere, and it simply works anywhere else. 756 00:35:52,776 --> 00:35:54,876 So, now you, so we bring this up for two reasons. 757 00:35:54,876 --> 00:35:57,326 So, one, most everything you've learned in this course, 758 00:35:57,326 --> 00:35:59,486 you can certainly apply to Windows programming, 759 00:35:59,486 --> 00:36:02,406 so Microsoft and its compilers generally add a bunch 760 00:36:02,406 --> 00:36:05,666 of new syntax and conventions that you don't see necessarily 761 00:36:05,666 --> 00:36:08,166 in the Lennox world, for instance, there's different ways 762 00:36:08,166 --> 00:36:11,216 of writing a main function when you code on a Windows platform, 763 00:36:11,406 --> 00:36:13,276 and that's just because it's a Microsoft convention. 764 00:36:13,276 --> 00:36:15,356 But, all of the basics are still actually there, 765 00:36:15,356 --> 00:36:17,436 and MAC OS is much more similar say to Lennox, 766 00:36:17,766 --> 00:36:19,746 which is what you guys have been dabbling in thus far. 767 00:36:19,996 --> 00:36:21,196 But, what tends to happen, 768 00:36:21,196 --> 00:36:23,256 especially at final project time, or when you're just 769 00:36:23,256 --> 00:36:25,746 out in the real world, or just trying to do something for fun 770 00:36:25,746 --> 00:36:27,946 on your computer, you'll run into these kinds 771 00:36:27,946 --> 00:36:31,006 of stupid headaches, like why can't I run this program someone 772 00:36:31,006 --> 00:36:31,446 sent me? 773 00:36:31,636 --> 00:36:33,256 Well, if they dynamically linked it, 774 00:36:33,256 --> 00:36:35,136 it means they didn't send you all of the files 775 00:36:35,136 --> 00:36:35,986 that are prerequisite. 776 00:36:36,226 --> 00:36:38,026 If you are actually running, writing a program 777 00:36:38,026 --> 00:36:40,746 that you want other people to be able to use, you might need 778 00:36:40,746 --> 00:36:42,976 to statically link things, all be it at the expense 779 00:36:43,246 --> 00:36:45,726 of making things much bigger than it needs to be. 780 00:36:46,306 --> 00:36:49,226 All right, so if we now have programs that are being compiled 781 00:36:49,336 --> 00:36:52,076 down to zeros and ones, we have these things called CPU's, 782 00:36:52,076 --> 00:36:53,906 which are the brains of your computer, which know how 783 00:36:53,906 --> 00:36:55,556 to understand those zeros and ones, 784 00:36:55,906 --> 00:36:59,836 how do we actually start storing these things in the real world? 785 00:36:59,916 --> 00:37:02,106 Up until now, we've completely taken for granted 786 00:37:02,366 --> 00:37:04,856 that we have hard drives or solid state drives, 787 00:37:04,856 --> 00:37:08,546 or flash drives, or floppy's or CD's, there's just some means 788 00:37:08,546 --> 00:37:10,716 of encoding data on computers. 789 00:37:10,716 --> 00:37:11,526 So how is that done? 790 00:37:11,526 --> 00:37:13,816 If you have a hard drive, the mechanical type, 791 00:37:13,816 --> 00:37:15,936 which is in most of your laptops still these days, 792 00:37:16,156 --> 00:37:17,856 how is data stored inside that thing? 793 00:37:18,636 --> 00:37:19,176 Anyone know? 794 00:37:19,386 --> 00:37:20,746 What's inside of a hard drive? 795 00:37:20,746 --> 00:37:21,286 >>[Inaudible Speaker Comment] 796 00:37:21,286 --> 00:37:23,386 >>David: what's that? 797 00:37:23,386 --> 00:37:23,836 >>[Inaudible Speaker Comment] 798 00:37:23,836 --> 00:37:25,716 >>David: Plates, okay, so these metal plates, 799 00:37:25,716 --> 00:37:26,816 otherwise called platters, 800 00:37:26,856 --> 00:37:28,946 they're these little circular things, and in fact, 801 00:37:28,946 --> 00:37:31,506 if you put your ear to a desktop computer or a lap top, 802 00:37:31,506 --> 00:37:32,996 you'll often hear something spinning, 803 00:37:33,216 --> 00:37:34,626 and that is these platters. 804 00:37:34,626 --> 00:37:37,516 So, most of you might know, at least, what a record is, 805 00:37:37,516 --> 00:37:40,886 or a phonograph player, right, it's actually very similar idea. 806 00:37:41,236 --> 00:37:44,986 You have data encoded in circles, on that disc, 807 00:37:44,986 --> 00:37:47,196 and the thing spins so that the computer can read 808 00:37:47,196 --> 00:37:51,696 in those bits at, from start to finish, so, 809 00:37:51,956 --> 00:37:54,066 I think a little picture, or better 810 00:37:54,066 --> 00:37:57,026 yet a little video can do this more justice than my own words, 811 00:37:57,026 --> 00:37:58,186 so let me go ahead and open 812 00:37:58,186 --> 00:38:02,796 up this little demo here, for hard drives. 813 00:38:03,406 --> 00:38:04,956 And let's see if this doesn't elucidate. 814 00:38:06,256 --> 00:38:08,776 >>The hard drive is where your PC stores most 815 00:38:08,776 --> 00:38:10,166 of its permanent data. 816 00:38:10,476 --> 00:38:12,476 To do that, the data travels 817 00:38:12,546 --> 00:38:14,696 from RAM along the software signals 818 00:38:14,696 --> 00:38:17,106 that tell the hard drive how to store that data. 819 00:38:17,906 --> 00:38:20,316 The hard drive circuits translate those signals 820 00:38:20,486 --> 00:38:22,016 into voltage fluctuations. 821 00:38:22,736 --> 00:38:25,476 These, in turn, control the hard drives moving parts, 822 00:38:26,026 --> 00:38:28,976 some of the few moving parts left in the modern computer. 823 00:38:29,706 --> 00:38:31,356 Some of the signals control a motor, 824 00:38:31,466 --> 00:38:33,206 which spins metal-coated platters. 825 00:38:33,946 --> 00:38:36,626 Your data is actually stored on these platters. 826 00:38:37,266 --> 00:38:40,476 Other signals move the read-write head to read 827 00:38:40,476 --> 00:38:41,796 or write data on the platters. 828 00:38:42,536 --> 00:38:45,156 This machinery is so precise, 829 00:38:45,276 --> 00:38:47,486 that human hair couldn't even pass between the heads 830 00:38:47,486 --> 00:38:48,396 and spinning platters. 831 00:38:49,016 --> 00:38:51,546 Yet, it all works at terrific speeds. 832 00:38:52,426 --> 00:38:53,976 >>David: In fact, when it says terrific speeds, 833 00:38:53,976 --> 00:38:55,736 how fast does this particular hard drive spin? 834 00:38:55,736 --> 00:38:57,276 If you've ever noticed on your own computer 835 00:38:57,276 --> 00:38:58,516 or at Best Buy when buying one? 836 00:38:58,516 --> 00:39:00,076 >>[Inaudible Speaker Comment] 837 00:39:00,076 --> 00:39:05,326 >>David: Its 50, so 54 hundred RPM's, so rotations per minute, 838 00:39:05,326 --> 00:39:08,216 or 72 hundred RPM or if you buy really expensive discs, 839 00:39:08,256 --> 00:39:11,986 10 thousand RPM's, that means its spinning several thousand 840 00:39:11,986 --> 00:39:15,016 times per minute and on each revolution can some data 841 00:39:15,016 --> 00:39:16,666 actually be read off, and the reason 842 00:39:16,666 --> 00:39:19,386 for the multiple platters there is, as you may have guessed, 843 00:39:19,386 --> 00:39:21,586 just for efficiency, like why just have one platter, 844 00:39:21,586 --> 00:39:22,386 if you can have four. 845 00:39:22,386 --> 00:39:25,246 That means you can store four times as much data on there. 846 00:39:25,436 --> 00:39:27,916 Well, let's go into slightly more technical detail, 847 00:39:27,916 --> 00:39:30,676 still quite accessible, with this follow up version. 848 00:39:31,356 --> 00:39:34,226 >>Let's look at what we just saw in slow motion. 849 00:39:35,036 --> 00:39:40,456 When a brief pulse of electricity is sent to the read- 850 00:39:40,776 --> 00:39:45,706 write head, it flips on a tiny electro magnet 851 00:39:45,826 --> 00:39:46,786 for a fraction of a section. 852 00:39:46,786 --> 00:39:49,256 The magnet creates a field, which changes the polarity 853 00:39:49,256 --> 00:39:52,726 of a tiny tiny portion of the metal particles, 854 00:39:52,726 --> 00:39:53,436 which coat each platter surface. 855 00:39:53,466 --> 00:39:54,726 A pattern series of these tiny [inaudible] varies on the disc, 856 00:39:54,756 --> 00:39:55,686 represents a single bit of data 857 00:39:55,716 --> 00:39:56,976 in the binary number system used by computers. 858 00:39:57,046 --> 00:39:59,776 Now if the current is sent one way 859 00:39:59,776 --> 00:40:00,286 through the read-write [inaudible], 860 00:40:00,706 --> 00:40:02,606 the areas polarized in one direction. 861 00:40:02,606 --> 00:40:05,246 If the current is sent in the opposite direction, 862 00:40:05,246 --> 00:40:08,766 the polarization is reversed. 863 00:40:08,766 --> 00:40:13,496 How do you get data off the hard disc? 864 00:40:13,496 --> 00:40:14,416 Just reverse the process. 865 00:40:14,766 --> 00:40:16,366 So, if the particles on the disc that get the current 866 00:40:16,396 --> 00:40:17,086 in the read-write head moving. 867 00:40:17,116 --> 00:40:18,436 Put together millions of these magnetized segments, 868 00:40:18,466 --> 00:40:18,976 and you've got a file. 869 00:40:19,526 --> 00:40:22,806 Now, the pieces of a single file may be scattered all 870 00:40:22,806 --> 00:40:25,136 over a drive's platters, kind of like the mess 871 00:40:25,276 --> 00:40:26,696 of papers on your desk. 872 00:40:26,696 --> 00:40:30,716 So, a special extra file keeps track of where everything is. 873 00:40:30,896 --> 00:40:32,786 Don't you wish you had something like that? 874 00:40:33,386 --> 00:40:35,346 >>David: Sorry, they like to add that. 875 00:40:35,806 --> 00:40:37,606 So, but, one of the things I've actually always thought is 876 00:40:37,606 --> 00:40:40,016 really neat about Computer Science or about Engineering is 877 00:40:40,016 --> 00:40:43,216 that unlike some of the physical sciences like Biology and such, 878 00:40:43,446 --> 00:40:46,866 like we, humanity, actually understand everything that goes 879 00:40:46,906 --> 00:40:50,526 on inside of this computer, and frankly, even though I, frankly, 880 00:40:50,526 --> 00:40:52,946 would not know how to go about making a hard drive, 881 00:40:53,006 --> 00:40:55,066 like what metal to use, how to wire all of this together, 882 00:40:55,066 --> 00:40:57,706 like that's certainly not my forte, what's kind of neat, 883 00:40:57,706 --> 00:40:59,436 I think is that at the end of the day, 884 00:40:59,616 --> 00:41:03,206 I mean all of the comprehension of how this stuff works 885 00:41:03,206 --> 00:41:06,736 in your pocket and on your desk is all quite accessible, right? 886 00:41:06,736 --> 00:41:08,216 Even if some of that was over your head, 887 00:41:08,216 --> 00:41:10,716 hopefully you realize, oh, well if I just have some way 888 00:41:10,716 --> 00:41:13,016 of laying out particles, magnetic particles like this, 889 00:41:13,336 --> 00:41:15,246 let's call that a one, if its instead like this, 890 00:41:15,366 --> 00:41:16,476 let's call that a zero. 891 00:41:16,476 --> 00:41:18,846 Well, as soon as you have means of encoding two pieces 892 00:41:18,846 --> 00:41:21,806 of information, we've seen from week one and two, 893 00:41:21,956 --> 00:41:24,086 how you can actually start to represent numbers, 894 00:41:24,086 --> 00:41:25,566 how you can start to represent letters 895 00:41:25,566 --> 00:41:28,186 and then ultimately actual computer programs. 896 00:41:28,186 --> 00:41:32,206 So, let's go ahead and take a look at this one. 897 00:41:32,206 --> 00:41:32,856 Oh, all right. 898 00:41:32,856 --> 00:41:36,116 So I always offer this to, just so, if that was a little so much 899 00:41:36,116 --> 00:41:38,956 like this, we also have something for those 900 00:41:38,956 --> 00:41:41,346 who still worry that they're among those less comfortable, 901 00:41:41,386 --> 00:41:42,876 aw damn, won't work. 902 00:41:43,266 --> 00:41:45,106 All right, little fail there, never mind. 903 00:41:45,276 --> 00:41:47,986 It's going to be a, oh I won't tell you. 904 00:41:48,366 --> 00:41:51,386 I'll tell you, it was going, no I won't tell you. 905 00:41:51,386 --> 00:41:53,816 Okay, we'll leave it at that. 906 00:41:53,816 --> 00:41:54,616 Okay, well, how about this. 907 00:41:54,716 --> 00:41:55,586 So this was just for fun. 908 00:41:55,586 --> 00:41:57,656 I'm not going to try to justify this with any academics, 909 00:41:57,656 --> 00:42:00,346 it's just kind of interesting I think, because CD's work 910 00:42:00,346 --> 00:42:02,956 in very, in a very similar way, but clearly all 911 00:42:02,956 --> 00:42:04,936 of us have the means of burning CD's, or DVD's 912 00:42:04,996 --> 00:42:09,796 and sometimes you can do this multiple times, if its CD-RW's 913 00:42:09,796 --> 00:42:12,896 or DVD-RW's, so this ones, again, 914 00:42:12,896 --> 00:42:14,676 just to help you understand what you've been doing 915 00:42:14,676 --> 00:42:16,966 when you actually burn a disc or music or data. 916 00:42:17,046 --> 00:42:19,136 >>How can a CD-ROM disc hold so much more 917 00:42:19,136 --> 00:42:20,356 than a conventional disc? 918 00:42:21,046 --> 00:42:24,466 The CD drive reads data with a beam of light so narrow 919 00:42:24,466 --> 00:42:27,296 that the information can be squeezed together much tighter. 920 00:42:27,346 --> 00:42:30,456 You see, a laser [inaudible] creates this concentrated beam 921 00:42:30,956 --> 00:42:31,906 of light. 922 00:42:32,566 --> 00:42:35,956 The light travels through a prism, then through a lens 923 00:42:35,956 --> 00:42:38,736 and magnetic coil that focus the beam even more. 924 00:42:39,386 --> 00:42:42,986 On the underside of the contact disc its self, are millions 925 00:42:42,986 --> 00:42:45,076 of tiny bumps called PITS. 926 00:42:45,466 --> 00:42:46,926 That's right, the bumps are called PITS. 927 00:42:47,166 --> 00:42:51,086 The same surface has smooth areas called LANDS. 928 00:42:51,976 --> 00:42:54,396 These PITS and LANDS are translated 929 00:42:54,396 --> 00:42:58,776 into the binary language of bits and bytes used by the computer. 930 00:42:59,426 --> 00:43:02,366 >>David: And, part two of that same sequence is this. 931 00:43:04,696 --> 00:43:06,556 >>Patterns of PITS and LANDS are laid 932 00:43:06,556 --> 00:43:08,186 out along a continuous spiral. 933 00:43:08,796 --> 00:43:11,886 As the disc turns, a precise motor keeps the laser beam 934 00:43:11,886 --> 00:43:12,756 in place on the path. 935 00:43:13,276 --> 00:43:15,866 Where the laser beam hits a PIT, the light is scattered. 936 00:43:16,466 --> 00:43:17,636 But where it hits a LAND, 937 00:43:17,636 --> 00:43:22,556 the beam is reflected straight back along its original path. 938 00:43:23,076 --> 00:43:24,546 The light enters the prism again, 939 00:43:24,576 --> 00:43:26,016 but this time it's reflected at a 90 degree angle 940 00:43:26,046 --> 00:43:26,976 and strikes the device called a diode. 941 00:43:27,076 --> 00:43:30,776 The diode creates an electric pulse each time the light 942 00:43:30,896 --> 00:43:31,206 hit it. 943 00:43:31,726 --> 00:43:34,756 So, when the laser hit a PIT, no light bounces back. 944 00:43:35,226 --> 00:43:36,726 When it strikes a LAND, 945 00:43:36,726 --> 00:43:38,906 the diode sees the reflection and sends a pulse. 946 00:43:39,636 --> 00:43:42,546 These blanks and pulses are sent to the computer, 947 00:43:42,546 --> 00:43:44,656 which interprets them as a pattern of zeros and ones. 948 00:43:45,276 --> 00:43:46,976 In other words, into binary code. 949 00:43:47,646 --> 00:43:49,426 >>David: So that's how real CD's are actually made 950 00:43:49,426 --> 00:43:51,706 when you buy them from store, with a game on it, or you buy it 951 00:43:51,706 --> 00:43:53,696 from a music store with music on it. 952 00:43:53,956 --> 00:43:55,926 When you actually burn discs yourself, 953 00:43:55,926 --> 00:43:58,096 what those things really are, they're really dirt cheap, 954 00:43:58,096 --> 00:44:00,146 they're just pieces of plastic, and you can see this 955 00:44:00,146 --> 00:44:02,076 if you just run your fingernails or something over it 956 00:44:02,076 --> 00:44:04,186 and start scrap, do this on something you didn't buy, 957 00:44:04,726 --> 00:44:07,836 you scrape the label off of it, generally there's just plastic, 958 00:44:08,076 --> 00:44:09,786 there's a label for marketing purposes, 959 00:44:09,786 --> 00:44:11,986 and then there's some kind of dye on the other side, 960 00:44:11,986 --> 00:44:15,866 and that dye, which usually looks green or gold or purple, 961 00:44:16,066 --> 00:44:18,426 what happens is, when you do burn a CD, 962 00:44:18,496 --> 00:44:20,166 some laser light insider of your computer, 963 00:44:20,166 --> 00:44:23,186 essentially just distorts portions of that dye, 964 00:44:23,186 --> 00:44:24,416 here and there and there, 965 00:44:24,646 --> 00:44:27,156 so that the next time a laser light actually shines 966 00:44:27,156 --> 00:44:29,226 on that CD, if it bounces right back, 967 00:44:29,396 --> 00:44:31,576 that means it's a zero or a one, whichever. 968 00:44:31,826 --> 00:44:34,336 But if it actually hits the part where you distorted the dye 969 00:44:34,336 --> 00:44:35,856 and kind of veers off somewhere else, 970 00:44:35,996 --> 00:44:38,846 well that representing the opposite, the one or the zero, 971 00:44:38,936 --> 00:44:41,346 so its still, again, fairly, rudimentary. 972 00:44:41,346 --> 00:44:43,206 Again, not sure how I even myself would start 973 00:44:43,206 --> 00:44:46,146 to build something like this, but the comprehensions probably, 974 00:44:46,216 --> 00:44:47,276 probably quite accessible. 975 00:44:47,276 --> 00:44:49,256 In fact, one of your classmates, on the survey's, 976 00:44:49,256 --> 00:44:52,926 said a comment along the line of, when I come into lecture, 977 00:44:52,926 --> 00:44:55,726 I always exit realizing how much I don't actually know, 978 00:44:55,726 --> 00:44:58,756 and I think they actually said that somewhat out of frustration 979 00:44:58,756 --> 00:45:01,366 or just being a bit overwhelmed, which is totally fine, 980 00:45:01,366 --> 00:45:03,916 and understandable, but I mean, frankly, 981 00:45:03,916 --> 00:45:05,626 that's kind of what makes stuff like this, 982 00:45:05,716 --> 00:45:06,876 I think, a little exciting. 983 00:45:06,876 --> 00:45:09,186 I mean we could go off in so many different directions 984 00:45:09,186 --> 00:45:11,336 at this point in the semester, we're not going to, 985 00:45:11,626 --> 00:45:14,216 but even today, it's meant to just give you a teaser that, 986 00:45:14,216 --> 00:45:16,786 once you start to understand what's underneath the hood, 987 00:45:17,056 --> 00:45:18,756 just a lot more stuff starts to makes sense. 988 00:45:18,756 --> 00:45:20,866 Google is going to be your friend, and Wikipedia is going 989 00:45:20,866 --> 00:45:22,386 to be your friend, and even those of you 990 00:45:22,386 --> 00:45:24,686 who don't consider yourself Engineers, and are going to go 991 00:45:24,686 --> 00:45:27,846 through OCS and get consulting jobs or iBanking or whatever, 992 00:45:28,196 --> 00:45:30,986 what's really kind of cool about having some technical knowhow, 993 00:45:30,986 --> 00:45:33,636 whether you are or not a computer science major, 994 00:45:33,946 --> 00:45:36,526 is that you can start to tell, much more effectively, 995 00:45:36,526 --> 00:45:39,246 when people are BS'ing in the real world. 996 00:45:39,246 --> 00:45:41,346 All right, there's a lot of people who kind of talk, talk, 997 00:45:41,346 --> 00:45:44,306 talk about technology and this and that, and hopefully, 998 00:45:44,506 --> 00:45:47,066 and after a couple of more weeks of this class, you know, 999 00:45:47,066 --> 00:45:50,126 you'll start to be able to see who's quite just talking 1000 00:45:50,126 --> 00:45:53,026 and not really understanding what it is that they're saying. 1001 00:45:53,026 --> 00:45:54,516 You'd be surprised how often this happens. 1002 00:45:54,516 --> 00:45:58,066 Frankly, go into Best Buy or a technology store, and already, 1003 00:45:58,066 --> 00:45:59,686 even just after seeing videos like that, 1004 00:45:59,686 --> 00:46:01,826 might you understand what's being sold a bit better 1005 00:46:02,076 --> 00:46:04,006 than the person selling it to you sometimes. 1006 00:46:04,256 --> 00:46:06,986 All right, so you have one of these things called floppy discs 1007 00:46:06,986 --> 00:46:09,896 in your hand, might not have used, or seen these things 1008 00:46:09,896 --> 00:46:12,086 in some time, they do actually still sell them, 1009 00:46:12,336 --> 00:46:13,516 they only store how much data? 1010 00:46:13,516 --> 00:46:15,326 >>[Inaudible Speaker Comment] 1011 00:46:15,326 --> 00:46:16,746 >>David: Yeah, 1.44 megabytes, 1012 00:46:16,746 --> 00:46:19,496 so a million bytes or 8 million bits. 1013 00:46:19,496 --> 00:46:20,936 Well, let's take a look at what's inside, 1014 00:46:20,936 --> 00:46:23,386 and you'll find it quite similar to what's inside 1015 00:46:23,386 --> 00:46:26,176 of a hard drive, but much cheaper and much slower. 1016 00:46:27,076 --> 00:46:28,916 >>The floppy drive you see here works with three 1017 00:46:28,916 --> 00:46:30,306 and half inch floppy discs. 1018 00:46:31,106 --> 00:46:35,826 They're the type most often used to carry new programs, 1019 00:46:35,826 --> 00:46:40,696 save data, or to move files from one PC to another. 1020 00:46:40,856 --> 00:46:46,056 The part of the disc we see is actually just the hard 1021 00:46:46,256 --> 00:46:46,776 plastic shell. 1022 00:46:46,876 --> 00:46:51,876 The working disc, which is inside, is protected 1023 00:46:52,226 --> 00:46:52,886 by a sliding metal shutter. 1024 00:46:52,916 --> 00:46:54,176 This thin inner disc, called the cookie, is coated not 1025 00:46:54,206 --> 00:46:55,346 with chocolate chips, but with a very thin layer 1026 00:46:55,376 --> 00:46:55,976 of magnetic material. 1027 00:46:56,186 --> 00:46:59,206 When you slip the disc into your floppy drive, 1028 00:46:59,546 --> 00:47:02,396 a system of levers pushes back the metal shutter, 1029 00:47:03,066 --> 00:47:06,166 the levers also pinch two read-write head closer 1030 00:47:06,166 --> 00:47:09,626 so they almost touch the cookie. 1031 00:47:09,816 --> 00:47:11,656 A motor at the base of the drive spins the cookie based 1032 00:47:11,656 --> 00:47:13,406 on commands from your PC. 1033 00:47:13,686 --> 00:47:15,696 The PC also signals another motor 1034 00:47:15,696 --> 00:47:18,956 to move the read-write heads back and forth over the surface 1035 00:47:19,116 --> 00:47:20,976 of the disc, so they can read or write data. 1036 00:47:22,366 --> 00:47:24,106 Before your PC writes data, 1037 00:47:24,666 --> 00:47:26,636 your drive first checks the right protect tab 1038 00:47:26,926 --> 00:47:28,736 in the corner of the floppy disc. 1039 00:47:29,456 --> 00:47:33,386 If it is open, light from a tiny diode shines through 1040 00:47:33,386 --> 00:47:35,086 and strikes a diode on the other side. 1041 00:47:36,206 --> 00:47:40,666 This diode then says to your PC, "Don't write on this disc." 1042 00:47:40,916 --> 00:47:43,926 But if the tab is closed, no light gets through, 1043 00:47:44,116 --> 00:47:46,796 and the PC knows it's okay to write data. 1044 00:47:47,676 --> 00:47:49,386 >>David: So, be careful because there is, in fact, 1045 00:47:49,386 --> 00:47:51,536 little bits on this things, but you can probably see, 1046 00:47:51,536 --> 00:47:53,126 and the clicking suggests, that you know, 1047 00:47:53,236 --> 00:47:55,086 you just move this cheap little metal shutter, 1048 00:47:55,086 --> 00:47:57,856 and inside of there is, in fact, this cookie, in fact, 1049 00:47:57,856 --> 00:48:00,076 it's alright if you ruin a few bits, go ahead and just push 1050 00:48:00,076 --> 00:48:02,616 down on that, and the reason these things are called floppy 1051 00:48:02,616 --> 00:48:04,986 is not because they're actually pretty hard, because they're 1052 00:48:04,986 --> 00:48:07,296 in this plastic shell, but because that thing inside 1053 00:48:07,296 --> 00:48:10,276 of there is, in fact, itself very floppy. 1054 00:48:10,656 --> 00:48:13,036 Let's see if we can't dive a little deeper, but again, 1055 00:48:13,036 --> 00:48:14,546 to this point of things being sort 1056 00:48:14,546 --> 00:48:16,456 of simpler underneath the hood than you might think, 1057 00:48:16,536 --> 00:48:17,946 it's such a stupid thing. 1058 00:48:17,946 --> 00:48:20,396 Well, let's make a whole in the piece of plastic, 1059 00:48:20,396 --> 00:48:22,326 and if light shines through it, it's locked. 1060 00:48:22,326 --> 00:48:25,646 If light doesn't shine through it, it's not locked, so again, 1061 00:48:25,756 --> 00:48:27,196 very basic things under here. 1062 00:48:27,196 --> 00:48:28,806 Let's look at this final clip here. 1063 00:48:30,956 --> 00:48:33,216 >>To write data onto a floppy disc, your PC tells the drive 1064 00:48:33,216 --> 00:48:38,466 to send tiny pulses of electricity through the heads. 1065 00:48:38,626 --> 00:48:41,356 The pulses make the head act little electro magnets. 1066 00:48:42,116 --> 00:48:43,726 Each head creates a magnetic field 1067 00:48:43,796 --> 00:48:45,666 that reaches the surface of the disc. 1068 00:48:46,026 --> 00:48:48,126 Remember the magnetic coating on the cookie? 1069 00:48:48,756 --> 00:48:52,406 The magnetic field alters the tiny particles in this coating. 1070 00:48:52,406 --> 00:48:54,236 If current runs through the heads one way, 1071 00:48:54,376 --> 00:48:55,916 the particles are arranged with their North 1072 00:48:55,976 --> 00:48:57,496 and South Poles in one direction. 1073 00:48:58,246 --> 00:49:00,466 But if current flows through the head the opposite way, 1074 00:49:00,856 --> 00:49:01,916 the polarity reverses. 1075 00:49:02,556 --> 00:49:04,776 To read data from a disc, the read-write heads move 1076 00:49:05,356 --> 00:49:07,436 into the same position over the cookie. 1077 00:49:07,836 --> 00:49:09,776 But this time, the process is reversed. 1078 00:49:10,456 --> 00:49:13,026 The cookie particles create a magnetic field in the coils 1079 00:49:13,026 --> 00:49:16,906 of wire, and this creates a current in the read-write heads. 1080 00:49:16,906 --> 00:49:19,306 The disc drive detects this flow of electricity 1081 00:49:19,306 --> 00:49:20,976 and passes it on to the PC. 1082 00:49:21,046 --> 00:49:24,386 The PC translates the back and forth current changes 1083 00:49:24,386 --> 00:49:26,476 into a series of ones and zeros, 1084 00:49:27,346 --> 00:49:29,976 the binary language of computer data. 1085 00:49:30,456 --> 00:49:32,786 >>David: So, we're well aware that many of you would really 1086 00:49:32,786 --> 00:49:35,346 like to just break something when you're working on CS50, 1087 00:49:35,346 --> 00:49:36,636 so we thought we'd give you 1088 00:49:36,636 --> 00:49:38,716 that opportunity here toward the end of the semester. 1089 00:49:39,186 --> 00:49:42,276 Beware the little spring, that's likely to hit your seat mates 1090 00:49:42,276 --> 00:49:45,666 in the eye, but go ahead and just remove this plastic, 1091 00:49:45,666 --> 00:49:46,756 or this metal shutter, 1092 00:49:46,796 --> 00:49:49,936 and you'll actually now expose the inner cookie, 1093 00:49:49,936 --> 00:49:52,886 and this is the most gratifying part of all, insert your fingers 1094 00:49:52,886 --> 00:49:57,776 at the bottom of the plastic and wa-la, a little souvenir 1095 00:49:58,596 --> 00:50:01,326 and the entire magic that made for years, 1096 00:50:01,326 --> 00:50:03,956 software distribution possible, and the storage of millions 1097 00:50:03,956 --> 00:50:06,046 of bits, this little thing in there. 1098 00:50:06,116 --> 00:50:08,146 So whether you were among those less comfortable, 1099 00:50:08,146 --> 00:50:10,366 somewhere in between, or more comfortable, 1100 00:50:10,366 --> 00:50:13,466 a lot of the stuff we've been talking about, really boils 1101 00:50:13,466 --> 00:50:15,056 down to some fairly basics. 1102 00:50:15,486 --> 00:50:19,766 Why don't we embrace the fun that you've just had, 1103 00:50:19,766 --> 00:50:22,066 actually it doesn't sound like you're having much fun, 1104 00:50:22,206 --> 00:50:24,396 but consider this your souvenir, please take it with you 1105 00:50:24,396 --> 00:50:26,196 when you go, that's it for today. 1106 00:50:26,196 --> 00:50:27,036 No class Wednesday. 1107 00:50:27,036 --> 00:50:29,976 We will see you on Monday. 1108 00:50:30,516 --> 00:50:36,040 [Background talking]