[Inaudible Background Speaker and Music] >> On January 24, Apple Computer will introduce Macintosh, and you'll see why 1984 won't be like 1984. >>David: So that commercial aired once in 1984, during the Super Bowl and this was 25 years ago now, and it was Apple first debuted the Macintosh, and at the time, they were facing Big Blue, IBM, and those IBM PC's, and most of you probably haven't even used in their original form, but it was a big deal as to what the Apple had begun do in 1984 with the industry and with computers as we now know it. And, today is focused on precisely that general world of hardware. We've spent much of the semester working our way on up, we went through C, we went through PHP, a little Java script and AJAX, and HTML, and all of that, and then today, finally, we'll come full circle and actually look underneath the hood as to how all of this magic has been happening. When you compile something with GCC, when you run something with PHP, what is, in fact, happening underneath the hood? But a few announcements first. So, one little copy paste fail, this handout is indeed about Quiz 1, not about Quiz zero, which the first sentence says, my apologies, but yes, Quiz 1 is in, on Wednesday 11/18 and do peruse the handout here for all of the available resources coming up at you, including review sessions and quiz review in sections. Also, take note that on Monday, we're going to be having a few guest lecturers from the Computer Science faculty. Each will talk a little bit about Computer Science beyond CS50 and specifically some of the courses you can take. It's actually much more exciting taking Computer Science courses here these days, than in my day, where pretty much after you took 50, you took 51 and after 51, you took 121, and after 121, you took 124, like there was a very clearly defined path, but there wasn't much digression from it. Now, there's so many more faculty and courses, that after CS50, you guys will be able to, if you so chose for reasons of majoring, minoring, or just for fun, CS51, which is about functional programming, and abstraction, which you'll hear a little more about on Monday. CS61, which is about systems programming, it's in that course where you diffuse the binary bomb, that piece that I described a while back. You can take 121 next fall, which is a theory course, and speaks to the fundamentals of what computers can and can't do. CS124, which is data structures and algorithms, which picks up essentially where we left off with hash tables, tables, and tried. CS171, which is about visualization and taking interesting large data sets and presenting it to human in ways they can understand. CS105, privacy and security, which is more of a seminar course, where you talk about the implications of various technologies on society, and its privacy and security. CS179, which is a new course, in which you will actually do iPhone development and focus on the design of good, user interfaces, so there's quite the platter of courses from which you'll be able to chose this spring, this coming fall. And realize, too, at the end of this course, CS50 is a terminal course for many students. Usually about half of the students in 50, don't take Computer Science, and that perfectly fine, because the course is meant to provide you with enough background, enough skill set to actually go off and do interesting things, even beyond the course, but realize that, if you are interested in minoring in Computer Science, the department is quite eager to entice to all the more students into it, and you have many different things to chose from these days. Majoring, all the better, but even if you just want to dabble in Computer Science, realize that this course, in particular, opens a lot of doors, within the engineering school, so do keep that in mind. We'll have a little cheat sheet, probably on the website or on paper on Monday, just to give you a more clear sense than this verbal tour, as to what awaits you. So, one pitch, before I turn things over to a couple of other folks. The first is, this one here, so the website is now up as promised, we do indeed want some TF's and CA's and graders. What does this mean? A teaching fellow for this course, as you may have inferred from the person you've been working with all term, someone who leads sections, who grades problem sets, who works with students one on one in office hours, fields questions on the bulletin boards and does all those things you're familiar with TFN. I would say that TFN50 is a fairly unique experience. It's definitely intense, perhaps as intense as taking the course, but so much fun, and dare say, so much more fun being on this side of things, than on that side of things, and it's a nice way to main, to remain part of the community that you might feel. CA's are volunteer's. CS50 alumni who offer 2 hours of office hours per week, it's largely self-scheduled, it's meant to be very flexible so that we can keep as many alumni involved in the course, and to help their successors in the course and the computer lab. And then finally graders, I'll spend a few hours a week hours a week helping out with key sets. And finally, that's enough from me for the moment, let me invite an alumnus from CS50 and a former TFN [inaudible] man, and now President of HCS, Kato Yuchiama. Oh sure, yeah. Let me get him a microphone, which is over here, okay. All yours. >> Kato Yuchiama: Hey. My name's Kato, I'm President of Harvard Computer Society. Today I'm here to invite you to an event that we are holding Friday in conjunction with the C's and CS department faculty. We're holding CS concentration cider and pie, so this is your opportunity to eat cider and pie. Well, in fact, it's actually for people interested in CS, people already concentrating in, people thinking of [inaudible] fielding in CS, you know, if you want to take any of those courses that David just mentioned, it's your opportunity to meet CS professors, and also upper classmen who are already concentrating in CS, so it's a great opportunity to ask questions, and it's not just the CS professor kind of thing because now you can ask people whether that class is, you know, is 124 actually a good class? You know, professors won't tell you the real answer, but upper classmen will. So, as it says here, it's a great opportunity to meet faculty, learn about cool classes, you can eat, not eat, meet CS undergrads, eat the food, win great prizes, we're still deciding that, but we are sure that there will be great prizes that you can win. And, also, its, you know, it's in a kind, we've never had a opportunity like this, at least in the 3 years that I've been here, so it should be great, should be great fun. So, that CS Concentration Cider and Pie, we asked that you RSVP on our Facebook event, if you're, if you want to RSVP at CS, go to HCS.Harvard.edu/cider, that's Harvard Computer Society.Harvard.edu/cider, you don't need to RSVP, so you can show up, its Friday 3 to 4:30 in Maxwell's Dworkin lobby, and if you don't know where Maxwell Dworkin is, you can use David's awesome maps.cs50.net tool to look it up on the map, so thank you, and have a great time. [Applause] >>David: Thanks very much, I'll give this back to Jennifer. All right, so one pitch, if you didn't pick up your shuttle boy card, we have some with the teaching fellows on your way out today. It was kind of funny, we were looking over, so we have this form on the courses website now, as some of you may have noticed, and we wrote a little script in PHP that inserts registrations for shuttle boy card into our database, and what was funny was to see all the interest in this card on like Thursday, and Friday, after Wednesdays lecture, when we actually handed them out in person, so this little request form began this variable list of who was not here on Wednesday. The irony is, they're probably still not here today, but that's okay, we send them our best, and, we actually some 400 plus response, so we'll start mailing those out to your friends who probably filled out that form this week. A big shout out to our own Drew Rob, who is completely, trounced everyone on the big board. I looked up the word for this, its 113 quintillion dollars that he has made atop the big board, really putting to shame the leaders from last week, so this was all just for fun, clearly there was some opportunities to take advantage of here, but congrats to Drew and all of you nonetheless. So, without further ado, coming at you now, last advertisement today is store.cs50.net. The CS department actually has a tradition of having silly T- shirts and what-not at the end of the semester, I still remember my I Survived CS51 T-shirt from many years ago, and so we've continued on in that tradition, and thanks to this fancy website, can we sell all sorts of things to ourselves and such, so feel free to take that out, but allow me to indulge us in a little display perhaps of what's been designed by our own TF's this year. [ Music and Applause ] [ Inaudible Speaker ] [ Applause & Music ] >>David: So, as you know, final projects are coming up as is the CS50 fair, and we, CS50, were particularly proud to see very recently that some of our own CS50 alumni turned teaching fellows, some of them now, have been awarded a wonderful prize from AT & T, some of you may have seen this float around the house list, some of you may have on your own iPhone and iPods, the Rover App, by Harvard Student Agencies, and this actually grew out of CS50 final project a couple of years ago, and I thought I would give them a moment, give them a little bit of CS50 shout out here by showing this few minute video that they put together with AT & T. So, if you can think of something as magical yourselves to do this year, perhaps it will be your video we show at next year's class. Here we go. [ Silence ] [Music] >>Hi, my name is Winston, I'm from Virginia and I studied Physics here at Harvard, but I just really like working with my hands and making things. >>I'm Joy. I'm from San Diego, but I'm Canadian. I'm majoring in Computer Science and minoring in Visual Environmental Studies, and I like good designs and intuitive [inaudible]. >>I'm Cameron, I'm from Colorado, and [inaudible] Computer Science concentrator here. >>Okay, my name is Drew, and [inaudible] and study Physics [inaudible] enjoyed programming. >>My name is Alex, I'm an Engineering major from New Jersey, and for a very long time I've been interested in making [inaudible] devices more useful. [Music] >>Joy: Rover is a mobile platform to connect students with the community. The [inaudible] version, we implemented a student guidebook into a mobile format that had [inaudible] as well [inaudible] platform for version [inaudible] to be able to connect to the student. >>We also helped to connect students to their peers through student-to-student interactions. For example, student groups are often interested in getting more students to come to their events, so instead of posting fliers on a bulletin board, we can post fliers on Rover. Also, for example, you can have a free [inaudible], somewhat similar to the [inaudible], where anytime there's an event on campus that has free food, students can take advantage of that. >>Joy: And this platform is also a lot of potential for administration to communicate with students in a timely fashion, almost everyone has a mobile device, and so the platform will be a quick way to reach out to student, also for student to professor communication, [inaudible] great deal. >>All of this [inaudible] social networks. So, for example, if a student, who's a friend of yours is taking advantage of lots of free food deals, or is visiting a local merchant that they like or has had a great experience with a professor, we want to broadcast that to all of their other friends who are also using Rover. >>And, lastly, at the back end of all of this is analytics for our partners and merchants so that we can know exactly who's clicking on what, and when, and this really provides business intelligence and usage statistics for us, so that we know what's mostly useful for student. >>Rover is unique because it's an application that's written for students, entirely by students, with students in mind. All of the content on Rover is produced by students, all the deals are things that students really want. What student doesn't want a free burrito, for example. [ Music ] >>[Inaudible speaker comment] and we found out about how AT & T Big Mobile on campus helped them expand from just one campus to a number of campuses nationwide, and so by entering Big Mobile on campus, it really helped us think about how can we take what we've done here, in the Harvard Square community and extended it nationwide. >>[Inaudible] fantastic experience to work with AT & T people, to really bring out, to expose our application to, perhaps, a larger audience than we ever could have pitched it to without AT & T, so it's just a tremendous opportunity for us, and the fact that we have some nice prizes too, doesn't hurt as well. >>There's hundreds of applications being built every day, and it's certainly sometimes hard to distinguish yourself from all [inaudible] applications that are being developed, so this is huge help. >>I really like making things that our friends are able to use. I like making things that I like to use, and I know this application was made with Rover is something I consult, you know four or five times a day. >>Just to connect students and like mobile business, or like to get students into your local theatres, we have local arts and it's just the community, and we think that connection can be really powerful. [Music] >>David: So, and there, if you have an iPhone or iPod touch, and congrats to our alumni and where they've taken that. It's a, it's worth noting, lest you be quite awe struck by what these guys have all pulled off, that there's this kind of unspoken rule in programming, where anything you might ever want to do, and you've probably experienced this, probably takes twice as long, three times as long as you actually expect it to, so realize that this product is actually the work now of a couple of years of ongoing development, so realize that, don't worry that the bar has been set so high for your own final projects, what these guys essentially did for their first version was a very functional, and very nice prototype, sort of version 1 of this all, and they've continued to build on that as well, so we hope you too will dive into something that interests you, if not, for just this duration of this semester, even beyond, so congrats to those guys. All right, so today's goal is to focus a bit on what's been going on underneath the hood. So, what do we mean by that? Well, we took for granted, for some time, that you can write programming code in a language called C, you can then run a compiler called GCC, and out of that comes a program, and just in English, what does it mean to compile a program from source code into object code? Anyone at all? Yeah, in the back. >>[Inaudible Speaker Comment] >> David: Okay, so take text and interpret it, or let me tweak your words, convert it to binary. So, take something that's sort of pseudo English, pseudo code, or actual code, I'll run it through this program called the compiler, and the output of that is not just ascii characters that humans can read, but its zero's and one's that actual CPU's understand. So, what does it mean when Intel says, "Intel is inside" or you see this little sticker on PC's. Well, that means that the CPU, inside of the computer, was made by this company called Intel, now what does that mean? That means that they decided, some years ago now, that every CPU, the brains of a computer, would understand certain instructions, and what's rather mind blowing is that the instructions that all of our programs, whether p-set 1 or p-set 8 reduced to, are basic things like addition and subtraction and multiplication, moving something from memory from here to here, loading something from disc or from here to here, these very basic primitives that we completely take for granted now, are really what's composed all of the programs you guys have been writing. So, just to put this into some perspective, let me go over to a terminal window here, and I'm going to open just a file called, Hello dot C, I didn't bother printing this out because it's pretty familiar by now, and that all there is to this. This is our canonical Hello World program. Well, this language C was actually an enhancement some years ago over a language called Assembly language, so, what you're about to see is a language that's much closer to the hardware, it's much more arcane, and it's certainly not nearly as much fun, if I'm even allowed to use that word in this context, than programming in C. So, what I'm going to do is run the compiler, GCC, but I'm going to use perhaps an unfamiliar flag, I'm going to say "dash capital S", and then I'm going to say "Hello dot C" and what I'm going to get as output, per LS here, is a hello dot S, so this is an intermediate file that we actually never really see, not by default, but inside of here is what the compiler is doing for this very basic program. So, this is an intermediate step between C source code, and what's called object code, zeros, and ones. Well, what do I mean by that? Well, let's see, there's really not much to this file. It might look a little cryptic, let me shrink down the font a little bit, and re-open it, there's really not much too it, 20, 30 lines here, and there's some new syntax here, and all of this is actually specific to Intel Inside. Because I'm running this program on a computer that has Intel hardware inside of it, these are literally the instructions that that CPU understands. Well, let's see if we can't make sense of some of this. So, at the top here, this seems to be somewhat uninteresting, apparently the original name of the file. Here's a dot section directive, whatever that means, dot RO. What might this mean, dot RO? So, read-only, so read-only data, apparently, comes here at the top, now why does that make sense? Well, just below this read-only data section, there's this cryptic string, but then something a little more familiar, namely the string, Hello World, which I hardcoded into my program, and is therefore itself a read-only string. I could change what, I could add strings to this program and such, but this is the one I hardcoded in here, so there we have this piece of data, dot text, what did this denote? If you can think back a few weeks? What is the text section of your program? Anyone recall? >>[Inaudible Speaker Comment] >>David: Say it a little louder. >>[Inaudible Speaker Comment] >>David: So, what you were coding, so this was the actual program, the code that you actually wrote. The review sections, remember this rectangle? We had the heap, we had the stack, we had initialized data, uninitialized data, and those last two related to global variables, but then above everything in that picture was the text section, and text just meant your program, so this actually makes sense, because below text, dot text here, here comes our program. So, this looks like, here comes a functions that's apparently called Main, all right, here is the main function, what goes on here? Well, these are these very basic primitive that I alluded to earlier, and some of them we can infer. Looks like there's a subtract operation, an and operation, a move operation to move things around in memory, add is in here as well, and L usually denotes long, so these are actually manipulating 32 bit values, in this case here, but that's it. That's all it takes to implement Hello World, and some years ago, if you wanted to write Hello World, this was the stuff that you wrote. Rewind a little further, in what you actually wrote, were punch cards, right, things with holes and what-not, that you actually fed physically into a machine and it would parse it, so we've come a long way, and certainly, if you think now to implementing in PHP, like you did this past week and will this next week, we've come a significantly far way here, but it's all the same stuff that's been around for 20, 30 years, even since Apple debuted that particular video. So, what's really going on? Well, let's take a look at some, let's come back to this picture in a moment, and consider this. So, when you compile something, we've kind of been waving our hands, or taking for granted some of the things that go on, none of them are very complicated, but we just, they all seem to happen at once. So, when you run GCC, there's five steps that happen between the time you write your code and run your code. So, the first step is called pre-processing. So pre-processing, we've actually used ourselves. Anytime you use slash include or slash define, if you say that in certain pieces of code we gave you, that's actually pre-processor directives, and GCC first does a pass from top to bottom, left to right over all of your code, and anywhere it sees, sorry, I think I might have said slash, sharp symbol, the sharp symbol and then include, or sharp define, it says "Oh, this is a pre- processor directive, let me do something with this. If its sharp define, what do I want to do? I want to do a find and replace for all of these global constants, and replace it with the actual value that's been defined. If it says sharp include, I want to go grab the foo dot H file, open it, and literally paste its contents into this location in the file, and then proceed with step 2. Its step 2 when your code is actually compiled, so we've kind of clumped all of these steps into just this one big word compiled, but compiling is really the second step. You've now got a big piece of code, all of these sharp includes and sharp defines have actually been pre-processed, so now, the compiler, GCC, takes all of that code and converts it from your source code, into assembly code, the stuff that we just saw on the board a moment ago. And, then there's another step that's happening behind the scenes, all of that assembly code is then converted or assembled into object code, so object code is ultimately the zeros and ones, so anytime you've seen, in your directory's those dot O files, some of them you didn't create yourself, right, and odds are you just wondered what they were, on first glance, make clean, usually deleted them, well what were all those dot O files? Those were object files, those were the binary files containing zeros and ones that were the result of compile speller dot C, or dictionary dot C, or any number of other dot C files that you happen to write. But, then there's one last step, and some of you tripped over this early on, if you didn't know what flags to use, sometimes you had to add that dash L flag to your make file, or dash L to the end of you GCC statement, and what did that mean or what's an example of having to use dash L on the GCC command line? It's kind of a hint up here in a big font, but. >>[Inaudible Speaker Comment] >>David: So, linking CS50, so anytime you use get [inaudible] or get float, or get string, you had to link N with dash L CS50, and it was kind of stupid, but you always had to put the dash L something at the very end of the command line, but that's actually consistent with the reality that his linking step is very much at the end of the whole process, it's sort of the last thing GCC needs to know. So, what does that mean? Well, when you compile your code, like let's take an example like Mario dot C. So when you have Mario dot C and you compile that with GCC, you ultimately get a Mario dot O file, but if you also use the get [inaudible] function from CS50's library, that means that you'd had sharp include CS50 dot H. So, the pre-processor copied and pasted all of the dot H files contents and in there were the function declarations, some global constants, stuff like that, but behind the scenes what was happening was GCC had to go compile and find CS50 dot C, and this is a bit of a white lie because we optimized away this particular need, but essentially at this point in the story, you have Mario dot C compiled to Mario dot O, you had CS50 dot C somewhere on the server compiled to CS50 dot O, so now you have these two independent files, both of which contain a bunch of zeros and ones, object code that Intel CPU's understand. You now need to literally merge these things together, link them together, so the last step that GCC does for you, is it takes this dot O file, it takes this dot O file, and it smashes them together and lays them out in an appropriate way in memory and on disc, so that what you have at the end is just one executable file, called Mario, or called Mario dot exe, or whatever the case may be, and then you, the user, can finally run that. So, just to put a picture to this, if we have the same example, Hello dot C, it's a little blurry on the screen here, but here are three of those steps. If I compile Hello dot C, here is that source code in C at the very top, that's, again, my so-called source code, I compile it, what that give me then, is this stuff called assembly language, which is much closer to the CPU's language. It's much clearer to the CPU what all this is, but it's much less clear, dare say, to the human, what all of this is. But, it's the same code converted to the basic building blocks; add, subtract, move, that the CPU itself understands, but it's still more English or pseudo code than it is actual zeros and ones, so the final step of assembling is what actually generates, during the assembly process, those zeros and ones, and these zeros and ones are literally what happens, when you compile Hello World on an X86, on an Intel computer, using GCC. Eventually, you get those zeros and ones. You actually get a lot more zeros and ones that would fit on the slide, but you get patterns of zeros and ones just like that. So, how does the CPU go about executing this program? Well, essentially it gets fed piece by piece by piece. And even though we, the humans, can't really see what's going on here, these patterns of zeros and ones here are laid out in sequences of 8 bits, and you may recall that most CPU's we've talked about in this class are 32 bits long, so, or are 32 bit architectures, although when we moved to the Cloud, it became 64 bits, but for the most part, 32 bit computers are still very much in vogue, so what does this mean? Well this means a CPU can understand 32 bits at a time, so when you run a program, when you double-click its icon, run it at the command line, 32 bits at a time are fed from your program into the CPU, inside of your computer, and some of those bits, usually the first several bits, tell the CPU what instruction to use, whether its add or subtract or move. And then the last 8 bits and the last 8 bits, after you have 8 or 16 at the beginning, the last bits usually reference these things called registers. So registers, we actually said very early on in the course, are the smallest units of memory that are use, that are actually useful to a typical computer. Inside of the CPU, are generally 32 or 64, things called registers, and these are very small chunks of memory, it's kind of like RAM, but much smaller, you have 32 bits of memory that is, ultimately, the location that your operands are stored. What do I mean by that? Well, CPU, at the end of the day, when it adds two things together, it literally adds this thing to this thing, it doesn't string 10 different values together and add them all at once, it generally operates on two inputs at a time, so usually two registers are used, two little tiny storage areas in memory, the CPU adds those values together, puts the results in another register, and the process repeats. So, in short, it's a huge leap to make, mentally, from a PHP program, or even a C program, down to this level of zeros and ones, but there's been many years of development from this low level to punch cards, to assembly code, to C, to PHP, so that everything actually has been built on top of prior work. So, if you like sort of what you're sensing is underneath the hood, the course in question, here at Harvard at least, would be CS141, this is computer hardware, and you can even get a taste of this kind of stuff in like Physics 123, which is a fun, hands-on course as well. So, there's a lot going on there, but at the end of the day, it reduces to these very basic principles. All right, so here's a more concrete example where we actually have multiple dot O files, or multiple dot C files. So, on the left here is just a picture of compiling, again, something like Hello dot C, but Hello dot C, remember, uses Print F, so that previous, this pictorial, was a bit misleading, because we didn't actually acknowledge that there was Print F and in what library is Print F defined, and what header file is it declared? >>[Inaudible Speaker Comment] >>David: Yeah, it's a standard IO dot H, so that's because someone else, the people who wrote the C compiler, wrote a file called Standard IO dot C, and Standard I dot O dot H, and inside the dot C file is the implementation of Print F, so I'm writing a program called Hello dot C, and I'm using Print F, yes, I compile it, that gives me assembly code, yes, I then assemble it, and, again, all of this happens for you with modern compilers, like GCC, and out of that comes zeros and ones, well there's actually another step here. In this first step, recall that I included Standard IO dot H, so the fact that that gets copied and pasted into my header file is a clue to the compiler that, oh, I actually need the functions that, the code that implements Print F. Well, where is that? Typically, it's going to be in a file like Standard IO dot C. This lives elsewhere on the system, you don't even know or care where it is, but what this inclusion, sharp include tells the compiler essentially is, oh, you're going to need to use this code, so let me find Standard IO dot C, let me compile it, or make sure it's already compiled, that gives me assembly code, then I need to assemble that, which gives me the zeros and ones, and then that final step, linking, is to actually merge my bits with the standard bits, merge them together and get one executable, the Hello binary, or Hello dot exe. So, why, though, have you never had to do dash L STD IO? Since it seems that that was the necessary magic to make this work for CS50's library. Why do you not need to type dash L Standard IO? Feels like there's an inconsistency here. >>[Inaudible Speaker Comment] >>David: Yeah, it's common enough that the compiler already links it in. So, what does that mean? Well, they're standard for a reason. The fact that it's Standard IO, Standard LIB, means that these are standard enough that you just don't have to provide that linker flag, it's essentially provided for you automatically. So that's all that's really been happening underneath the hood there, is this whole process, but largely unbeknownst to you, and just as an aside, there's one detail that's kind of interesting to realize, especially if you're a PC user, those of you with PC's, have you ever seen or heard of DLL files? Anyone? Kind of sort of? Okay, so what are they, if you've all seen them? >>[Inaudible Speaker Comment] >>David: Okay good, [inaudible] pedagogical answer. What are they? So, what is a DLL file, so that stands for dynamic link library, and without going into too much WIN32 or Windows detail, that's the same idea as what's going on here. There's two ways to link programs together. You can either statically link them, or you can dynamically link them. Well, what does that mean? This picture here is describing static linking, and in fact, it's kind of a white lie depiction of what you guys have been doing, because generally if you want this picture to happen, you have to pass GCC the dash static flag, and say statically compile this, but that's okay here, because the take away is that this means static compiling, which means, when you get this executable file, your Mario program, you Hello program, in theory, you can move that program from computer to computer to computer and so long as you move it to another computer that has the same CPU, you can run at the command line, or double-click it there, and it will simply work. By contrast, if you dynamically link a program, it's not necessarily going to work if you move it to another computer. Any of you who have ever tried to copy programs you've installed on your computer, Microsoft Word or Photoshop or AOL instant messenger, its generally not sufficient to click and drag the dot exe file, and put it on your other computer, or put it on our friends computer, because there's usually a lot more files that comprise that actual program, many of them these dot DLL files. So, the other way to link programs together is not to create one binary that is the result of combining bits from the left with bits from the right, but rather you just take your own bits from the left, and you include inside of the binary, inside of the executable, essentially the path to files on the local hard drive that contain Standard dot IO, Standard IO bits, or the CS50 library bits, in other words, its dynamic in that you need, in order to run this program, you need to have those other files installed on the computer. So, this is good and bad. What is a upside, based on that definition of statically linking your programs? What's one good thing about it that comes to mind. Yes? >>It takes up less space because you don't have repetition of the Standard IO in every. >>David: If you statically link. >>Right. >>David: If you, that's dynamic. Okay. So, an advantage of dynamic linking is that you don't have this redundancy, right? Because if you're dynamically linking, you just have one copy of Standard IO dot O or CS50 dot O, and you dynamically linked against them so that you don't make copies of all of the bits comprised in those libraries again and again and again. All right, so that's one advantage, and in fact, that's why Microsoft does it with so many of their products, because you can have these shared libraries, these dynamic link libraries, and just not waste disc space unnecessarily. So, what's now an upside of statically linking your programs together? Anyone at all? Okay. >>You don't have the problem that I always get if you're missing a DLL file and nothing [inaudible]. >>David: Good. So you don't have the problem of double-clicking that program, or running it at the command line and being told, cannot run, cannot find foo dot DLL or some other program like that. It's actually self-contained program, a program that's completely portable, you can copy it, move it anywhere, and it simply works anywhere else. So, now you, so we bring this up for two reasons. So, one, most everything you've learned in this course, you can certainly apply to Windows programming, so Microsoft and its compilers generally add a bunch of new syntax and conventions that you don't see necessarily in the Lennox world, for instance, there's different ways of writing a main function when you code on a Windows platform, and that's just because it's a Microsoft convention. But, all of the basics are still actually there, and MAC OS is much more similar say to Lennox, which is what you guys have been dabbling in thus far. But, what tends to happen, especially at final project time, or when you're just out in the real world, or just trying to do something for fun on your computer, you'll run into these kinds of stupid headaches, like why can't I run this program someone sent me? Well, if they dynamically linked it, it means they didn't send you all of the files that are prerequisite. If you are actually running, writing a program that you want other people to be able to use, you might need to statically link things, all be it at the expense of making things much bigger than it needs to be. All right, so if we now have programs that are being compiled down to zeros and ones, we have these things called CPU's, which are the brains of your computer, which know how to understand those zeros and ones, how do we actually start storing these things in the real world? Up until now, we've completely taken for granted that we have hard drives or solid state drives, or flash drives, or floppy's or CD's, there's just some means of encoding data on computers. So how is that done? If you have a hard drive, the mechanical type, which is in most of your laptops still these days, how is data stored inside that thing? Anyone know? What's inside of a hard drive? >>[Inaudible Speaker Comment] >>David: what's that? >>[Inaudible Speaker Comment] >>David: Plates, okay, so these metal plates, otherwise called platters, they're these little circular things, and in fact, if you put your ear to a desktop computer or a lap top, you'll often hear something spinning, and that is these platters. So, most of you might know, at least, what a record is, or a phonograph player, right, it's actually very similar idea. You have data encoded in circles, on that disc, and the thing spins so that the computer can read in those bits at, from start to finish, so, I think a little picture, or better yet a little video can do this more justice than my own words, so let me go ahead and open up this little demo here, for hard drives. And let's see if this doesn't elucidate. >>The hard drive is where your PC stores most of its permanent data. To do that, the data travels from RAM along the software signals that tell the hard drive how to store that data. The hard drive circuits translate those signals into voltage fluctuations. These, in turn, control the hard drives moving parts, some of the few moving parts left in the modern computer. Some of the signals control a motor, which spins metal-coated platters. Your data is actually stored on these platters. Other signals move the read-write head to read or write data on the platters. This machinery is so precise, that human hair couldn't even pass between the heads and spinning platters. Yet, it all works at terrific speeds. >>David: In fact, when it says terrific speeds, how fast does this particular hard drive spin? If you've ever noticed on your own computer or at Best Buy when buying one? >>[Inaudible Speaker Comment] >>David: Its 50, so 54 hundred RPM's, so rotations per minute, or 72 hundred RPM or if you buy really expensive discs, 10 thousand RPM's, that means its spinning several thousand times per minute and on each revolution can some data actually be read off, and the reason for the multiple platters there is, as you may have guessed, just for efficiency, like why just have one platter, if you can have four. That means you can store four times as much data on there. Well, let's go into slightly more technical detail, still quite accessible, with this follow up version. >>Let's look at what we just saw in slow motion. When a brief pulse of electricity is sent to the read- write head, it flips on a tiny electro magnet for a fraction of a section. The magnet creates a field, which changes the polarity of a tiny tiny portion of the metal particles, which coat each platter surface. A pattern series of these tiny [inaudible] varies on the disc, represents a single bit of data in the binary number system used by computers. Now if the current is sent one way through the read-write [inaudible], the areas polarized in one direction. If the current is sent in the opposite direction, the polarization is reversed. How do you get data off the hard disc? Just reverse the process. So, if the particles on the disc that get the current in the read-write head moving. Put together millions of these magnetized segments, and you've got a file. Now, the pieces of a single file may be scattered all over a drive's platters, kind of like the mess of papers on your desk. So, a special extra file keeps track of where everything is. Don't you wish you had something like that? >>David: Sorry, they like to add that. So, but, one of the things I've actually always thought is really neat about Computer Science or about Engineering is that unlike some of the physical sciences like Biology and such, like we, humanity, actually understand everything that goes on inside of this computer, and frankly, even though I, frankly, would not know how to go about making a hard drive, like what metal to use, how to wire all of this together, like that's certainly not my forte, what's kind of neat, I think is that at the end of the day, I mean all of the comprehension of how this stuff works in your pocket and on your desk is all quite accessible, right? Even if some of that was over your head, hopefully you realize, oh, well if I just have some way of laying out particles, magnetic particles like this, let's call that a one, if its instead like this, let's call that a zero. Well, as soon as you have means of encoding two pieces of information, we've seen from week one and two, how you can actually start to represent numbers, how you can start to represent letters and then ultimately actual computer programs. So, let's go ahead and take a look at this one. Oh, all right. So I always offer this to, just so, if that was a little so much like this, we also have something for those who still worry that they're among those less comfortable, aw damn, won't work. All right, little fail there, never mind. It's going to be a, oh I won't tell you. I'll tell you, it was going, no I won't tell you. Okay, we'll leave it at that. Okay, well, how about this. So this was just for fun. I'm not going to try to justify this with any academics, it's just kind of interesting I think, because CD's work in very, in a very similar way, but clearly all of us have the means of burning CD's, or DVD's and sometimes you can do this multiple times, if its CD-RW's or DVD-RW's, so this ones, again, just to help you understand what you've been doing when you actually burn a disc or music or data. >>How can a CD-ROM disc hold so much more than a conventional disc? The CD drive reads data with a beam of light so narrow that the information can be squeezed together much tighter. You see, a laser [inaudible] creates this concentrated beam of light. The light travels through a prism, then through a lens and magnetic coil that focus the beam even more. On the underside of the contact disc its self, are millions of tiny bumps called PITS. That's right, the bumps are called PITS. The same surface has smooth areas called LANDS. These PITS and LANDS are translated into the binary language of bits and bytes used by the computer. >>David: And, part two of that same sequence is this. >>Patterns of PITS and LANDS are laid out along a continuous spiral. As the disc turns, a precise motor keeps the laser beam in place on the path. Where the laser beam hits a PIT, the light is scattered. But where it hits a LAND, the beam is reflected straight back along its original path. The light enters the prism again, but this time it's reflected at a 90 degree angle and strikes the device called a diode. The diode creates an electric pulse each time the light hit it. So, when the laser hit a PIT, no light bounces back. When it strikes a LAND, the diode sees the reflection and sends a pulse. These blanks and pulses are sent to the computer, which interprets them as a pattern of zeros and ones. In other words, into binary code. >>David: So that's how real CD's are actually made when you buy them from store, with a game on it, or you buy it from a music store with music on it. When you actually burn discs yourself, what those things really are, they're really dirt cheap, they're just pieces of plastic, and you can see this if you just run your fingernails or something over it and start scrap, do this on something you didn't buy, you scrape the label off of it, generally there's just plastic, there's a label for marketing purposes, and then there's some kind of dye on the other side, and that dye, which usually looks green or gold or purple, what happens is, when you do burn a CD, some laser light insider of your computer, essentially just distorts portions of that dye, here and there and there, so that the next time a laser light actually shines on that CD, if it bounces right back, that means it's a zero or a one, whichever. But if it actually hits the part where you distorted the dye and kind of veers off somewhere else, well that representing the opposite, the one or the zero, so its still, again, fairly, rudimentary. Again, not sure how I even myself would start to build something like this, but the comprehensions probably, probably quite accessible. In fact, one of your classmates, on the survey's, said a comment along the line of, when I come into lecture, I always exit realizing how much I don't actually know, and I think they actually said that somewhat out of frustration or just being a bit overwhelmed, which is totally fine, and understandable, but I mean, frankly, that's kind of what makes stuff like this, I think, a little exciting. I mean we could go off in so many different directions at this point in the semester, we're not going to, but even today, it's meant to just give you a teaser that, once you start to understand what's underneath the hood, just a lot more stuff starts to makes sense. Google is going to be your friend, and Wikipedia is going to be your friend, and even those of you who don't consider yourself Engineers, and are going to go through OCS and get consulting jobs or iBanking or whatever, what's really kind of cool about having some technical knowhow, whether you are or not a computer science major, is that you can start to tell, much more effectively, when people are BS'ing in the real world. All right, there's a lot of people who kind of talk, talk, talk about technology and this and that, and hopefully, and after a couple of more weeks of this class, you know, you'll start to be able to see who's quite just talking and not really understanding what it is that they're saying. You'd be surprised how often this happens. Frankly, go into Best Buy or a technology store, and already, even just after seeing videos like that, might you understand what's being sold a bit better than the person selling it to you sometimes. All right, so you have one of these things called floppy discs in your hand, might not have used, or seen these things in some time, they do actually still sell them, they only store how much data? >>[Inaudible Speaker Comment] >>David: Yeah, 1.44 megabytes, so a million bytes or 8 million bits. Well, let's take a look at what's inside, and you'll find it quite similar to what's inside of a hard drive, but much cheaper and much slower. >>The floppy drive you see here works with three and half inch floppy discs. They're the type most often used to carry new programs, save data, or to move files from one PC to another. The part of the disc we see is actually just the hard plastic shell. The working disc, which is inside, is protected by a sliding metal shutter. This thin inner disc, called the cookie, is coated not with chocolate chips, but with a very thin layer of magnetic material. When you slip the disc into your floppy drive, a system of levers pushes back the metal shutter, the levers also pinch two read-write head closer so they almost touch the cookie. A motor at the base of the drive spins the cookie based on commands from your PC. The PC also signals another motor to move the read-write heads back and forth over the surface of the disc, so they can read or write data. Before your PC writes data, your drive first checks the right protect tab in the corner of the floppy disc. If it is open, light from a tiny diode shines through and strikes a diode on the other side. This diode then says to your PC, "Don't write on this disc." But if the tab is closed, no light gets through, and the PC knows it's okay to write data. >>David: So, be careful because there is, in fact, little bits on this things, but you can probably see, and the clicking suggests, that you know, you just move this cheap little metal shutter, and inside of there is, in fact, this cookie, in fact, it's alright if you ruin a few bits, go ahead and just push down on that, and the reason these things are called floppy is not because they're actually pretty hard, because they're in this plastic shell, but because that thing inside of there is, in fact, itself very floppy. Let's see if we can't dive a little deeper, but again, to this point of things being sort of simpler underneath the hood than you might think, it's such a stupid thing. Well, let's make a whole in the piece of plastic, and if light shines through it, it's locked. If light doesn't shine through it, it's not locked, so again, very basic things under here. Let's look at this final clip here. >>To write data onto a floppy disc, your PC tells the drive to send tiny pulses of electricity through the heads. The pulses make the head act little electro magnets. Each head creates a magnetic field that reaches the surface of the disc. Remember the magnetic coating on the cookie? The magnetic field alters the tiny particles in this coating. If current runs through the heads one way, the particles are arranged with their North and South Poles in one direction. But if current flows through the head the opposite way, the polarity reverses. To read data from a disc, the read-write heads move into the same position over the cookie. But this time, the process is reversed. The cookie particles create a magnetic field in the coils of wire, and this creates a current in the read-write heads. The disc drive detects this flow of electricity and passes it on to the PC. The PC translates the back and forth current changes into a series of ones and zeros, the binary language of computer data. >>David: So, we're well aware that many of you would really like to just break something when you're working on CS50, so we thought we'd give you that opportunity here toward the end of the semester. Beware the little spring, that's likely to hit your seat mates in the eye, but go ahead and just remove this plastic, or this metal shutter, and you'll actually now expose the inner cookie, and this is the most gratifying part of all, insert your fingers at the bottom of the plastic and wa-la, a little souvenir and the entire magic that made for years, software distribution possible, and the storage of millions of bits, this little thing in there. So whether you were among those less comfortable, somewhere in between, or more comfortable, a lot of the stuff we've been talking about, really boils down to some fairly basics. Why don't we embrace the fun that you've just had, actually it doesn't sound like you're having much fun, but consider this your souvenir, please take it with you when you go, that's it for today. No class Wednesday. We will see you on Monday. [Background talking] ==== Transcribed by Automatic Sync Technologies ====