{"id":958,"date":"2010-10-18T18:12:15","date_gmt":"2010-10-18T18:12:15","guid":{"rendered":"http:\/\/pchero21.com\/?p=958"},"modified":"2010-10-18T18:12:15","modified_gmt":"2010-10-18T18:12:15","slug":"lec-1-mit-6-00-introduction-to-computer-science-and-programming-fall-2008","status":"publish","type":"post","link":"http:\/\/pchero21.com\/?p=958","title":{"rendered":"Lec 1 | MIT 6.00 Introduction to Computer Science and Programming, Fall 2008"},"content":{"rendered":"<p><object width=\"480\" height=\"385\"><param name=\"movie\" value=\"http:\/\/www.youtube.com\/v\/k6U-i4gXkLM?fs=1&amp;hl=ko_KR\"><\/param><param name=\"allowFullScreen\" value=\"true\"><\/param><param name=\"allowscriptaccess\" value=\"always\"><\/param><embed src=\"http:\/\/www.youtube.com\/v\/k6U-i4gXkLM?fs=1&amp;hl=ko_KR\" type=\"application\/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"480\" height=\"385\"><\/embed><\/object><\/p>\n<p>&nbsp;\uccab \uc2dc\uac04. \uc218\uc5c5\uc758 \ub0b4\uc6a9\uacfc \uc55e\uc73c\ub85c \uc5b4\ub5a4 \uacf5\ubd80\ub4e4\uc744 \ud558\uac8c \ub420 \uac83\uc778\uc9c0\uc5d0 \ub300\ud55c \uc124\uba85\uc744 \ud558\uace0 \uc788\ub2e4.<\/p>\n<p>&nbsp;\ud30c\uc774\uc36c\uc744 \ud504\ub85c\uadf8\ub798\ubc0d \uc5b8\uc5b4\ub85c \uc0ac\uc6a9\ud560 \uac83\uc774\uba70, \uadf8\uc678 \uae30\ud0c0 \ub4f1\ub4f1\uc5d0 \ub300\ud55c \uc774\uc57c\uae30\ub97c \ud558\uace0 \uc788\ub2e4.<\/p>\n<p><\/p>\n<div class=\"ui-tabs-panel ui-widget-content ui-corner-bottom\" id=\"fragment-3\">\n<p>The<br \/>\n following content is provided under a Creative Commons license. Your<br \/>\nsupport will help MIT OpenCourseware continue to offer high-quality<br \/>\neducational resources for free. To make a donation, or view additional<br \/>\nmaterials from hundreds of MIT courses, visit MIT OpenCourseware, at<br \/>\nocw.mit.edu.<\/p>\n<p>PROFESSOR: Good morning. Try it again. Good morning.<\/p>\n<p>STUDENTS: Good morning.<\/p>\n<p>PROFESSOR:<br \/>\n Thank you. This is 6.00, also known as Introduction to Computer Science<br \/>\n and Programming. My name is Eric Grimson, I have together Professor<br \/>\nJohn Guttag over here, we&#8217;re going to be lecturing the course this term.<br \/>\n I want to give you a heads up; you&#8217;re getting some serious firepower<br \/>\nthis term. John was department head for ten years, felt like a century,<br \/>\nand in course six, I&#8217;m the current department head in course six. John&#8217;s<br \/>\n been lecturing for thirty years, roughly. All right, I&#8217;m the young guy,<br \/>\n I&#8217;ve only been lecturing for twenty-five years. You can tell, I have<br \/>\nless grey hair than he does. What I&#8217;m trying to say to you is, we take<br \/>\nthis course really seriously. We hope you do as well. But we think it&#8217;s<br \/>\nreally important for the department to help everybody learn about<br \/>\ncomputation, and that&#8217;s what this course is about.<\/p>\n<p>What I want<br \/>\nto do today is three things: I&#8217;m going to start&#8211; actually, I shouldn&#8217;t<br \/>\nsay start, I&#8217;m going to do a little bit of administrivia, the kinds of<br \/>\nthings you need to know about how we&#8217;re going to run the course. I want<br \/>\nto talk about the goal of the course, what it is you&#8217;ll be able to do at<br \/>\n the end of this course when you get through it, and then I want to<br \/>\nbegin talking about the concepts and tools of computational thinking,<br \/>\nwhich is what we&#8217;re primarily going to focus on here. We&#8217;re going to try<br \/>\n and help you learn how to think like a computer scientist, and we&#8217;re<br \/>\ngoing to begin talking about that towards the end of this lecture and of<br \/>\n course throughout the rest of the lectures that carry on.<\/p>\n<p>Right,<br \/>\n let&#8217;s start with the goals. I&#8217;m going to give you goals in two levels.<br \/>\nThe strategic goals are the following: we want to help prepare freshmen<br \/>\nand sophomores who are interested in majoring in course six to get an<br \/>\neasy entry into the department, especially for those students who don&#8217;t<br \/>\nhave a lot of prior programming experience. If you&#8217;re in that category,<br \/>\ndon&#8217;t panic, you&#8217;re going to get it. We&#8217;re going to help you ramp in and<br \/>\n you&#8217;ll certainly be able to start the course six curriculum and do just<br \/>\n fine and still finish on target. We don&#8217;t expect everybody to be a<br \/>\ncourse six major, contrary to popular opinion, so for those are you not<br \/>\nin that category, the second thing we want to do is we want to help<br \/>\nstudents who don&#8217;t plan to major in course six to feel justifiably<br \/>\nconfident in their ability to write and read small pieces of code.<\/p>\n<p>For<br \/>\n all students, what we want to do is we want to give you an<br \/>\nunderstanding of the role computation can and cannot play in tackling<br \/>\ntechnical problems. So that you will come away with a sense of what you<br \/>\ncan do, what you can&#8217;t do, and what kinds of things you should use to<br \/>\ntackle complex problems.<\/p>\n<p>And finally, we want to position all<br \/>\nstudents so that you can easily, if you like, compete for things like<br \/>\nyour office and summer jobs. Because you&#8217;ll have an appropriate level of<br \/>\n confidence and competence in your ability to do computational problem<br \/>\nsolving. Those are the strategic goals.<\/p>\n<p>Now, this course is<br \/>\nprimarily aimed at students who have little or no prior programming<br \/>\nexperience. As a consequence, we believe that no student here is<br \/>\nunder-qualified for this course: you&#8217;re all MIT students, you&#8217;re all<br \/>\nqualified to be here. But we also hope that there aren&#8217;t any students<br \/>\nhere who are over-qualified for this course. And what do I mean by that?<br \/>\n If you&#8217;ve done a lot prior programming, this is probably not the best<br \/>\ncourse for you, and if you&#8217;re in that category, I would please encourage<br \/>\n you to talk to John or I after class about what your goals are, what<br \/>\nkind of experience you have, and how we might find you a course that<br \/>\nbetter meets your goals.<\/p>\n<p>Second reason we don&#8217;t want<br \/>\nover-qualified students in the class, it sounds a little nasty, but the<br \/>\nsecond reason is, an over-qualified student, somebody who&#8217;s, I don&#8217;t<br \/>\nknow, programmed for Google for the last five years, is going to have an<br \/>\n easy time in this course, but we don&#8217;t want such a student accidentally<br \/>\n intimidating the rest of you. We don&#8217;t want you to feel inadequate when<br \/>\n you&#8217;re simply inexperienced. And so, it really is a course aimed at<br \/>\nstudents with little or no prior programming experience. And again, if<br \/>\nyou&#8217;re not in that category, talk to John or I after class, and we&#8217;ll<br \/>\nhelp you figure out where you might want to go.<\/p>\n<p>OK. Those are<br \/>\nthe top-level goals of the course. Let&#8217;s talk sort of at a more tactical<br \/>\n level, about what do we want you to know in this course. What we want<br \/>\nyou to be able to do by the time you leave this course? So here are the<br \/>\nskills that we would like you to acquire. Right, the first skill we want<br \/>\n you to acquire, is we want you to be able to use the basic tools of<br \/>\ncomputational thinking to write small scale programs. I&#8217;m going to keep<br \/>\ncoming back to that idea, but I&#8217;m going to call it computational<br \/>\nthinking. And that&#8217;s so you can write small pieces of code. And small is<br \/>\n not derogatory here, by the way, it just says the size of things you&#8217;re<br \/>\n going to be able to do.<\/p>\n<p>Second skill we want you to have at the<br \/>\n end of this course is the ability to use a vocabulary of computational<br \/>\ntools in order to be able to understand programs written by others. So<br \/>\nyou&#8217;re going to be able to write, you&#8217;re going to be able to read.<\/p>\n<p>This<br \/>\n latter skill, by the way, is incredibly valuable. Because you won&#8217;t<br \/>\nwant to do everything from scratch yourself, you want to be able to look<br \/>\n at what is being created by somebody else and understand what is inside<br \/>\n of there, whether it works correctly and how you can build on it. This<br \/>\nis one of the few places where plagiarism is an OK thing. It&#8217;s not bad<br \/>\nto, if you like, learn from the skills of others in order to create<br \/>\nsomething you want to write. Although we&#8217;ll come back to plagiarism as a<br \/>\n bad thing later on.<\/p>\n<p>Third thing we want you to do, is to<br \/>\nunderstand the fundamental both capabilities and limitations of<br \/>\ncomputations, and the costs associated with them. And that latter<br \/>\nstatement sounds funny, you don&#8217;t think of computations having limits,<br \/>\nbut they do. There&#8217;re some things that cannot be computed. We want you<br \/>\nto understand where those limits are. So you&#8217;re going to be able to<br \/>\nunderstand abilities and limits.<\/p>\n<p>And then, finally, the last<br \/>\ntactical skill that you&#8217;re going to get out of this course is you&#8217;re<br \/>\ngoing to have the ability to map scientific problems into a<br \/>\ncomputational frame. So you&#8217;re going to be able to take a description of<br \/>\n a problem and map it into something computational.<\/p>\n<p>Now if you<br \/>\nthink about it, boy, it sounds like grammar school. We&#8217;re going to teach<br \/>\n you to read, we&#8217;re going to teach you to write, we&#8217;re going to teach<br \/>\nyou to understand what you can and cannot do, and most importantly,<br \/>\nwe&#8217;re going to try and give you the start of an ability to take a<br \/>\ndescription of a problem from some other domain, and figure out how to<br \/>\nmap it into that domain of computation so you can do the reading and<br \/>\nwriting that you want to do.<\/p>\n<p>OK, in a few minutes we&#8217;re going to<br \/>\n start talking then about what is computation, how are we going to start<br \/>\n building those tools, but that&#8217;s what you should take away, that&#8217;s what<br \/>\n you&#8217;re going to gain out of this course by the time you&#8217;re done.<\/p>\n<p>Now,<br \/>\n let me take a sidebar for about five minutes to talk about course<br \/>\nadministration, the administrivia, things that we&#8217;re going to do in the<br \/>\ncourse, just so you know what the rules are. Right, so, class is two<br \/>\nhours of lecture a week. You obviously know where and you know when,<br \/>\nbecause you&#8217;re here. Tuesdays and Thursdays at 11:00. One hour of<br \/>\nrecitation a week, on Fridays, and we&#8217;ll come back in a second to how<br \/>\nyou&#8217;re going to get set up for that. And nine hours a week of<br \/>\noutside-the-class work. Those nine hours are going to be primarily<br \/>\nworking on problem sets, and all the problems sets are going to involve<br \/>\nprogramming in Python, which is the language we&#8217;re going to be using<br \/>\nthis term.<\/p>\n<p>Now, one of the things you&#8217;re going to see is the<br \/>\nfirst problem sets are pretty easy. Actually, that&#8217;s probably wrong,<br \/>\nJohn, right? They&#8217;re very easy. And we&#8217;re going to ramp up. By the time<br \/>\nyou get to the end of the term, you&#8217;re going to be dealing with some<br \/>\nfairly complex things, so one of the things you&#8217;re going to see is,<br \/>\nwe&#8217;re going to make heavy use of libraries, or code written by others.<br \/>\nIt&#8217;ll allow you to tackle interesting problems I&#8217;ll have you to write<br \/>\nfrom scratch, but it does mean that this skill here is going to be<br \/>\nreally valuable. You need to be able to read that code and understand<br \/>\nit, as well as write your own.<\/p>\n<p>OK. Two quizzes. During the term,<br \/>\n the dates have already been scheduled. John, I forgot to look them up, I<br \/>\n think it&#8217;s October 2nd and November 4th, it&#8217;ll be on the course<br \/>\nwebsite. My point is, go check the course website, which by the way is<br \/>\nright there. If you have, if you know you have a conflict with one of<br \/>\nthose quiz dates now, please see John or I right away. We&#8217;ll arrange<br \/>\nsomething ahead of time. But if you&#8211; The reason I&#8217;m saying that is, you<br \/>\n know, you know that you&#8217;re getting married that day for example, we<br \/>\nwill excuse you from the quiz to get married. We&#8217;ll expect you come<br \/>\nright back to do the quiz by the way, but the&#8211; Boy, tough crowd. All<br \/>\nright. If you have a conflict, please let us know.<\/p>\n<p>Second thing<br \/>\nis, if you have an MIT documented special need for taking quizzes,<br \/>\nplease see John or I well in advance. At least two weeks before the<br \/>\nquiz. Again, we&#8217;ll arrange for this, but you need to give us enough<br \/>\nwarning so that we can deal with that.<\/p>\n<p>OK, the quizzes are open<br \/>\nbook. This course is not about memory. It&#8217;s not how well you can<br \/>\nmemorize facts: in fact, I think both John and I are a little sensitive<br \/>\nto memory tests, given our age, right John? This is not about how you<br \/>\nmemorize things, it&#8217;s about how you think. So they&#8217;re open note, open<br \/>\nbook. It&#8217;s really going to test your ability to think.<\/p>\n<p>The<br \/>\ngrades for the course will be assigned roughly, and I use the word<br \/>\nroughly because we reserve the right to move these numbers around a<br \/>\nlittle bit, but basically in the following percentages: 55% of your<br \/>\ngrade comes from the problem sets, the other 45% come from the quizzes.<br \/>\nAnd I should&#8217;ve said there&#8217;s two quizzes and a final exam. I forgot,<br \/>\nthat final exam during final period. So the quiz percentages are 10%,<br \/>\n15%, and 20%. Which makes up the other 45%.<\/p>\n<p>OK. Other<br \/>\nadministrivia. Let me just look through my list here. First problem set,<br \/>\n problem set zero, has already been posted. This is a really easy one.<br \/>\nWe intend it to be a really easy problem set. It&#8217;s basically to get you<br \/>\nto load up Python on your machine and make sure you understand how to<br \/>\ninteract with it.<\/p>\n<p>The first problem set will be posted shortly,<br \/>\nit&#8217;s also pretty boring&#8211; somewhat like my lectures but not John&#8217;s&#8211; and<br \/>\n that means, you know, we want you just to get going on things. Don&#8217;t<br \/>\nworry, we&#8217;re going to make them more interesting as you go along.<\/p>\n<p>Nonetheless,<br \/>\n I want to stress that none of these problems sets are intended to be<br \/>\nlethal. We&#8217;re not using them to weed you out, we&#8217;re using them to help<br \/>\nyou learn. So if you run into a problem set that just, you don&#8217;t get,<br \/>\nall right? Seek help. Could be psychiatric help, could be a TA. I<br \/>\nrecommend the TA. My point being, please come and talk to somebody. The<br \/>\nproblems are set up so that, if you start down the right path, it should<br \/>\n be pretty straight-forward to work it through. If you start down a<br \/>\nplausible but incorrect path, you can sometimes find yourself stuck in<br \/>\nthe weeds somewhere, and we want to bring you back in. So part of the<br \/>\ngoal here is, this should not be a grueling, exhausting kind of task,<br \/>\nit&#8217;s really something that should be helping you learn the material. If<br \/>\nyou need help, ask John, myself, or the TAs. That&#8217;s what we&#8217;re here for.<\/p>\n<p>OK.<br \/>\n We&#8217;re going to run primarily a paperless subject, that&#8217;s why the<br \/>\nwebsite is there. Please check it, that&#8217;s where everything&#8217;s going to be<br \/>\n posted in terms of things you need to know. In particular, please go to<br \/>\n it today, you will find a form there that you need to fill out to<br \/>\nregister for, or sign up for rather, a recitation.<\/p>\n<p>Recitations<br \/>\nare on Friday. Right now, we have them scheduled at 9:00, 10:00, 11:00,<br \/>\n12:00, 1:00, and 2:00. We may drop one of the recitations, just<br \/>\ndepending on course size, all right? So we reserve the right,<br \/>\nunfortunately, to have to move you around. My guess is that 9:00 is not<br \/>\ngoing to be a tremendously popular time, but maybe you&#8217;ll surprise me.<br \/>\nNonetheless, please go in and sign up. We will let you sign up for<br \/>\nwhichever recitation makes sense for you. Again, we reserve the right to<br \/>\n move people around if we have to, just to balance load, but we want you<br \/>\n to find something that fits your schedule rather than ours.<\/p>\n<p>OK.<br \/>\n Other things. There is no required text. If you feel exposed without a<br \/>\ntext book, you really have to have a textbook, you&#8217;ll find one<br \/>\nrecommended&#8211; actually I&#8217;m going to reuse that word, John, at least<br \/>\nsuggest it, on the course website. I don&#8217;t think either of us are<br \/>\nthrilled with the text, it&#8217;s the best we&#8217;ve probably found for Python,<br \/>\nit&#8217;s OK. If you need it, it&#8217;s there. But we&#8217;re going to basically not<br \/>\nrely on any specific text.<\/p>\n<p>Right. Related to that: attendance<br \/>\nhere is obviously not mandatory. You ain&#8217;t in high school anymore. I<br \/>\nthink both of us would love to see your smiling faces, or at least your<br \/>\nfaces, even if you&#8217;re not smiling at us every day. Point I want to make<br \/>\nabout this, though, is that we are going to cover a lot of material that<br \/>\n is not in the assigned readings, and we do have assigned readings<br \/>\nassociated with each one of these lectures. If you choose not to show up<br \/>\n today&#8211; or sorry, you did choose to show up today, if you choose not to<br \/>\n show up in future days&#8211; we&#8217;ll understand, but please also understand<br \/>\nthat the TAs won&#8217;t have a lot of patience with you if you&#8217;re asking a<br \/>\nquestion about something that was either covered in the readings, or<br \/>\ncovered in the lecture and is pretty straight forward. All right? We<br \/>\nexpect you to behave responsibly and we will as well. All right.<\/p>\n<p>I<br \/>\n think the last thing I want to say is, we will not be handing out class<br \/>\n notes. Now this sounds like a draconian measure; let me tell you why.<br \/>\nEvery study I know of, and I suspect every one John knows, about<br \/>\nlearning, stresses that students learn best when they take notes.<br \/>\nIronically, even if they never look at them. OK. The process of writing<br \/>\nis exercising both halves of your brain, and it&#8217;s actually helping you<br \/>\nlearn, and so taking notes is really valuable thing. Therefore we&#8217;re not<br \/>\n going to distribute notes. What we will distribute for most lectures is<br \/>\n a handout that&#8217;s mostly code examples that we&#8217;re going to do. I don&#8217;t<br \/>\nhappen to have one today because we&#8217;re not going to do a lot of code. We<br \/>\n will in future. Those notes are going to make no sense, I&#8217;m guessing,<br \/>\noutside of the lecture, all right? So it&#8217;s not just, you can swing by<br \/>\n11:04 and grab a copy and go off and catch some more sleep. What we<br \/>\nrecommend is you use those notes to take your own annotations to help<br \/>\nyou understand what&#8217;s going on, but we&#8217;re not going to provide class<br \/>\nnotes. We want you to take your own notes to help you, if you like, spur<br \/>\n your own learning process.<\/p>\n<p>All right. And then finally, I want<br \/>\nto stress that John, myself, all of the staff, our job is to help you<br \/>\nlearn. That&#8217;s what we&#8217;re here for. It&#8217;s what we get excited about. If<br \/>\nyou&#8217;re stuck, if you&#8217;re struggling, if you&#8217;re not certain about<br \/>\nsomething, please ask. We&#8217;re not mind readers, we can&#8217;t tell when you&#8217;re<br \/>\n struggling, other than sort of seeing the expression on your face, we<br \/>\nneed your help in identifying that. But all of the TAs, many of whom are<br \/>\n sitting down in the front row over here, are here to help, so come and<br \/>\nask. At the same time, remember that they&#8217;re students too. And if you<br \/>\ncome and ask a question that you could have easily answered by doing the<br \/>\n reading, coming to lecture, or using Google, they&#8217;re going to have less<br \/>\n patience. But helping you understand things that really are a<br \/>\nconceptual difficulty is what they&#8217;re here for and what we&#8217;re here for,<br \/>\nso please come and talk to us.<\/p>\n<p>OK. That takes care of the administrivia preamble. John, things we add?<\/p>\n<p>PROFESSOR<br \/>\n GUTTAG: Two more quick things. This semester, your class is being<br \/>\nvideotaped for OpenCourseware. If any of you don&#8217;t want your image<br \/>\nrecorded and posted on the web, you&#8217;re supposed to sit in the back three<br \/>\n rows.<\/p>\n<p>PROFESSOR GRIMSON: Ah, thank you. I forgot.<\/p>\n<p>PROFESSOR<br \/>\n GUTTAG: &#8211;Because the camera may pan. I think you&#8217;re all very<br \/>\ngood-looking and give MIT a good image, so please, feel free to be<br \/>\nfilmed.<\/p>\n<p>PROFESSOR GRIMSON: I&#8217;ll turn around, so if you want to,<br \/>\nyou know, move to the back, I won&#8217;t see who moves. Right. Great. Thank<br \/>\nyou, John.<\/p>\n<p>PROFESSOR GUTTAG: So that, the other thing I want to<br \/>\nmention is, recitations are also very important. We will be covering<br \/>\nmaterial in recitations that&#8217;re not in the lectures, not in the reading,<br \/>\n and we do expect you to attend recitations.<\/p>\n<p>PROFESSOR GRIMSON:<br \/>\nGreat. Thanks, John. Any questions about the administrivia? I know it&#8217;s<br \/>\nboring, but we need to do it so you know what the ground rules are.<\/p>\n<p>Good.<br \/>\n OK. Let&#8217;s talk about computation. As I said, our strategic goal, our<br \/>\ntactical goals, are to help you think like a computer scientist. Another<br \/>\n way of saying it is, we want to give you the skill so that you can make<br \/>\n the computer do what you want it to do. And we hope that at the end of<br \/>\nthe class, every time you&#8217;re confronted with some technical problem, one<br \/>\n of your first instincts is going to be, &#8220;How do I write the piece of<br \/>\ncode that&#8217;s going to help me solve that?&#8221;<\/p>\n<p>So we want to help you<br \/>\n think like a computer scientist. All right. And that, is an interesting<br \/>\n statement. What does it mean, to think like a computer scientist? Well,<br \/>\n let&#8217;s see. The primary knowledge you&#8217;re going to take away from this<br \/>\ncourse is this notion of computational problem solving, this ability to<br \/>\nthink in computational modes of thought. And unlike in a lot of<br \/>\nintroductory courses, as a consequence, having the ability to memorize<br \/>\nis not going to help you. It&#8217;s really learning those notions of the<br \/>\ntools that you want to use. What in the world does it mean to say<br \/>\ncomputational mode of thought? It sounds like a hifalutin phrase you use<br \/>\n when you&#8217;re trying to persuade a VC to fund you. Right. So to answer<br \/>\nthis, we really have to ask a different question, a related question;<br \/>\nso, what&#8217;s computation?<\/p>\n<p>It&#8217;s like a strange statement, right?<br \/>\nWhat is computation? And part of the reason for putting it up is that I<br \/>\nwant to, as much as possible, answer that question by separating out the<br \/>\n mechanism, which is the computer, from computational thinking. Right.<br \/>\nThe artifact should not be what&#8217;s driving this. It should be the notion<br \/>\nof, &#8220;What does it mean to do computation?&#8221;<\/p>\n<p>Now, to answer that,<br \/>\nI&#8217;m going to back up one more level. And I&#8217;m going to pose what sounds<br \/>\nlike a philosophy question, which is, &#8220;What is knowledge?&#8221; And you&#8217;ll<br \/>\nsee in about two minutes why I&#8217;m going to do this. But I&#8217;m going to<br \/>\nsuggest that I can divide knowledge into at least two categories. OK,<br \/>\nand what is knowledge? And the two categories I&#8217;m going to divide them<br \/>\ninto are declarative and imperative knowledge.<\/p>\n<p>Right. What in<br \/>\nthe world is declarative knowledge? Think of it as statements of fact.<br \/>\nIt&#8217;s assertions of truth. Boy, in this political season, that&#8217;s a really<br \/>\n dangerous phrase to use, right? But it&#8217;s a statement of fact. I&#8217;ll stay<br \/>\n away from the political comments. Let me give you an example of this.<br \/>\nRight. Here&#8217;s a declarative statement. The square root of x is that y<br \/>\nsuch that y squared equals x, y&#8217;s positive. You all know that. But what I<br \/>\n want you to see here, is that&#8217;s a statement of fact. It&#8217;s a definition.<br \/>\n It&#8217;s an axiom. It doesn&#8217;t help you find square roots. If I say x is 2, I<br \/>\n want to know, what&#8217;s the square root of 2, well if you&#8217;re enough of a<br \/>\ngeek, you&#8217;ll say 1.41529 or whatever the heck it is, but in general,<br \/>\nthis doesn&#8217;t help you find the square root. The closest it does is it<br \/>\nwould let you test. You know, if you&#8217;re wandering through Harvard Square<br \/>\n and you see an out-of-work Harvard grad, they&#8217;re handing out examples<br \/>\nof square roots, they&#8217;ll give you an example and you can test it to see,<br \/>\n is the square root of 2, 1.41529 or whatever. I don&#8217;t even get laughs<br \/>\nat Harvard jokes, John, I&#8217;m going to stop in a second here, all right?<br \/>\nAll right, so what am I trying to say here? It doesn&#8217;t &#8212; yeah, exactly.<br \/>\n We&#8217;re staying away from that, really quickly, especially with the<br \/>\ncameras rolling.<\/p>\n<p>All right. What am I trying to say? It tells you how you might test something but it doesn&#8217;t tell you how to.<\/p>\n<p>And<br \/>\n that&#8217;s what imperative knowledge is. Imperative knowledge is a<br \/>\ndescription of how to deduce something. So let me give you an example of<br \/>\n a piece of imperative knowledge. All right, this is actually a very old<br \/>\n piece of imperative knowledge for computing square roots, it&#8217;s<br \/>\nattributed to Heron of Alexandria, although I believe that the<br \/>\nBabylonians are suspected of knowing it beforehand. But here is a piece<br \/>\nof imperative knowledge. All right? I&#8217;m going to start with a guess, I&#8217;m<br \/>\n going to call it g. And then I&#8217;m going to say, if g squared is close to<br \/>\n x, stop. And return g. It&#8217;s a good enough answer. Otherwise, I&#8217;m going<br \/>\nto get a new guess by taking g, x over g, adding them, and dividing by<br \/>\ntwo. Then you take the average of g and x over g. Don&#8217;t worry about how<br \/>\ncame about, Heron found this out. But that gives me a new guess, and I&#8217;m<br \/>\n going to repeat.<\/p>\n<p>That&#8217;s a recipe. That&#8217;s a description of a set<br \/>\n of steps. Notice what it has, it has a bunch of nice things that we<br \/>\nwant to use, right? It&#8217;s a sequence of specific instructions that I do<br \/>\nin order. Along the way I have some tests, and depending on the value of<br \/>\n that test, I may change where I am in that sequence of instructions.<br \/>\nAnd it has an end test, something that tells me when I&#8217;m done and what<br \/>\nthe answer is. This tells you how to find square roots. it&#8217;s how-to<br \/>\nknowledge. It&#8217;s imperative knowledge.<\/p>\n<p>All right. That&#8217;s what<br \/>\ncomputation basically is about. We want to have ways of capturing this<br \/>\nprocess. OK, and that leads now to an interesting question, which would<br \/>\nbe, &#8220;How do I build a mechanical process to capture that set of<br \/>\ncomputations?&#8221; So I&#8217;m going to suggest that there&#8217;s an easy way to do<br \/>\nit&#8211; I realized I did the boards in the wrong order here&#8211; one of the<br \/>\nways I could do it is, you could imagine building a little circuit to do<br \/>\n this. If I had a couple of elements of stored values in it, I had some<br \/>\nwires to move things around, I had a little thing to do addition, little<br \/>\n thing to do division, and a something to do the testing, I could build a<br \/>\n little circuit that would actually do this computation.<\/p>\n<p>OK.<br \/>\nThat, strange as it sounds, is actually an example of the earliest<br \/>\ncomputers, because the earliest computers were what we call<br \/>\nfixed-program computers, meaning that they had a piece of circuitry<br \/>\ndesigned to do a specific computation. And that&#8217;s what they would do:<br \/>\nthey would do that specific computation. You&#8217;ve seen these a lot, right?<br \/>\n A good example of this: calculator. It&#8217;s basically an example of a<br \/>\nfixed-program computer. It does arithmetic. If you want play video games<br \/>\n on it, good luck. If you want to do word processing on it, good luck.<br \/>\nIt&#8217;s designed to do a specific thing. It&#8217;s a fixed-program computer.<\/p>\n<p>In<br \/>\n fact, a lot of the other really interesting early ones similarly have<br \/>\nthis flavor, to give an example: I never know how to pronounce this,<br \/>\nAtanasoff, 1941. One of the earliest computational things was a thing<br \/>\ndesigned by a guy named Atanasoff, and it basically solved linear<br \/>\nequations. Handy thing to do if you&#8217;re doing 1801, all right, or 1806,<br \/>\nor whatever you want to do those things in. All it could do, though, was<br \/>\n solve those equations.<\/p>\n<p>One of my favorite examples of an early<br \/>\ncomputer was done by Alan Turing, one of the great computer scientists<br \/>\nof all time, called the bombe, which was designed to break codes. It was<br \/>\n actually used during WWII to break German Enigma codes. And what it was<br \/>\n designed to do, was to solve that specific problem.<\/p>\n<p>The point<br \/>\nI&#8217;m trying to make is, fixed-program computers is where we started, but<br \/>\nit doesn&#8217;t really get us to where we&#8217;d like to be. We want to capture<br \/>\nthis idea of problem solving. So let&#8217;s see how we&#8217;d get there. So even<br \/>\nwithin this framework of, given a description of a computation as a set<br \/>\nof steps, in the idea that I could build a circuit to do it, let me<br \/>\nsuggest for you what would be a wonderful circuit to build.<\/p>\n<p>Suppose<br \/>\n you could build a circuit with the following property: the input to<br \/>\nthis circuit would be any other circuit diagram. Give it a circuit<br \/>\ndiagram for some computation, you give it to the circuit, and that<br \/>\ncircuit would wonderfully reconfigure itself to act like the circuits<br \/>\ndiagram. Which would mean, it could act like a calculator. Or, it could<br \/>\nact like Turing&#8217;s bombe. Or, it could act like a square root machine.<\/p>\n<p>So<br \/>\n what would that circuit look like? You can imagine these tiny little<br \/>\nrobots wandering around, right? Pulling wires and pulling out components<br \/>\n and stacking them together. How would you build a circuit that could<br \/>\ntake a circuit diagram in and make a machine act like that circuit?<br \/>\nSounds like a neat challenge.<\/p>\n<p>Let me change the game slightly.<br \/>\nSuppose instead, I want a machine that can take a recipe, the<br \/>\ndescription of a sequence of steps, take that as its input, and then<br \/>\nthat machine will now act like what is described in that recipe.<br \/>\nReconfigure itself, emulate it, however you want to use the words, it&#8217;s<br \/>\ngoing to change how it does the computation.<\/p>\n<p>That would be cool.<br \/>\n And that exists. It&#8217;s called an interpreter. It is the basic heart of<br \/>\nevery computer. What it is doing, is saying, change the game. This is<br \/>\nnow an example of a stored-program computer. What that means, in a<br \/>\nstored-program computer, is that I can provide to the computer a<br \/>\nsequence of instructions describing the process I want it to execute.<br \/>\nAnd inside of the machine, and things we&#8217;ll talk about, there is a<br \/>\nprocess that will allow that sequence to be executed as described in<br \/>\nthat recipe, so it can behave like any thing that I can describe in one<br \/>\nof those recipes.<\/p>\n<p>All right. That actually seems like a really<br \/>\nnice thing to have, and so let me show you what that would basically<br \/>\nlook like. Inside of a stored-program computer, we would have the<br \/>\nfollowing: we have a memory, it&#8217;s connected to two things; control unit,<br \/>\n in what&#8217;s called an ALU, an arithmetic logic unit, and this can take in<br \/>\n input, and spit out output, and inside this stored-program computer,<br \/>\nexcuse me, you have the following: you have a sequence of instructions.<br \/>\nAnd these all get stored in there. Notice the difference. The recipe,<br \/>\nthe sequence of instructions, is actually getting read in, and it&#8217;s<br \/>\ntreated just like data. It&#8217;s inside the memory of the machine, which<br \/>\nmeans we have access to it, we can change it, we can use it to build new<br \/>\n pieces of code, as well as we can interpret it. One other piece that<br \/>\ngoes into this computer&#8211; I never remember where to put the PC, John,<br \/>\ncontrol? ALU? Separate? I&#8217;ll put it separate&#8211; you have a thing called a<br \/>\n program counter.<\/p>\n<p>And here&#8217;s the basis of the computation. That<br \/>\nprogram counter points to some location in memory, typically to the<br \/>\nfirst instruction in the sequence. And those instructions, by the way,<br \/>\nare very simple: they&#8217;re things like, take the value out of two places<br \/>\nin memory, and run them through the multiplier in here, a little piece<br \/>\nof circuitry, and stick them back into someplace in memory. Or take this<br \/>\n value out of memory, run it through some other simple operation, stick<br \/>\nit back in memory. Having executed this instruction, that counter goes<br \/>\nup by one and we move to the next one. We execute that instruction, we<br \/>\nmove to the next one. Oh yeah, it looks a whole lot like that.<\/p>\n<p>Some<br \/>\n of those instructions will involve tests: they&#8217;ll say, is something<br \/>\ntrue? And if the test is true, it will change the value of this program<br \/>\ncounter to point to some other place in the memory, some other point in<br \/>\nthat sequence of instructions, and you&#8217;ll keep processing. Eventually<br \/>\nyou&#8217;ll hopefully stop, and a value gets spit out, and you&#8217;re done.<\/p>\n<p>That&#8217;s<br \/>\n the heart of a computer. Now that&#8217;s a slight misstatement. The process<br \/>\nto control it is intriguing and interesting, but the heart of the<br \/>\ncomputer is simply this notion that we build our descriptions, our<br \/>\nrecipes, on a sequence of primitive instructions. And then we have a<br \/>\nflow of control. And that flow of control is what I just described. It&#8217;s<br \/>\n moving through a sequence of instructions, occasionally changing where<br \/>\nwe are as we move around.<\/p>\n<p>OK. The thing I want you to take away<br \/>\nfrom this, then, is to think of this as, this is, if you like, a recipe.<br \/>\n And that&#8217;s really what a program is. It&#8217;s a sequence of instructions.<br \/>\nNow, one of things I left hanging is, I said, OK, you build it out of<br \/>\nprimitives. So one of the questions is, well, what are the right<br \/>\nprimitives to use? And one of the things that was useful here is, that<br \/>\nwe actually know that the set of primitives that you want to use is very<br \/>\n straight-forward.<\/p>\n<p>OK, but before I do that, let me drive home<br \/>\nthis idea of why this is a recipe. Assuming I have a set of primitive<br \/>\ninstructions that I can describe everything on, I want to know what can I<br \/>\n build. Well, I&#8217;m going to do the same analogy to a real recipe. So,<br \/>\nreal recipe. I don&#8217;t know. Separate six eggs. Do something. Beat until<br \/>\nthe&#8211; sorry, beat the whites until they&#8217;re stiff. Do something until an<br \/>\nend test is true. Take the yolks and mix them in with the sugar and<br \/>\nwater&#8211; No. Sugar and flour I guess is probably what I want, sugar and<br \/>\nwater is not going to do anything interesting for me here&#8211; mix them<br \/>\ninto something else. Do a sequence of things.<\/p>\n<p>A traditional<br \/>\nrecipe actually is based on a small set of primitives, and a good chef<br \/>\nwith, or good cook, I should say, with that set of primitives, can<br \/>\ncreate an unbounded number of great dishes. Same thing holds true in<br \/>\nprogramming. Right. Given a fixed set of primitives, all right, a good<br \/>\nprogrammer can program anything. And by that, I mean anything that can<br \/>\nbe described in one of these process, you can capture in that set of<br \/>\nprimitives.<\/p>\n<p>All right, the question is, as I started to say, is,<br \/>\n &#8220;What are the right primitives?&#8221; So there&#8217;s a little bit of, a little<br \/>\npiece of history here, if you like. In 1936, that same guy, Alan Turing,<br \/>\n showed that with six simple primitives, anything that could be<br \/>\ndescribed in a mechanical process, it&#8217;s actually algorithmically, could<br \/>\nbe programmed just using those six primitives.<\/p>\n<p>Think about that<br \/>\nfor a second. That&#8217;s an incredible statement. It says, with six<br \/>\nprimitives, I can rule the world. With six primitives, I can program<br \/>\nanything. A couple of really interesting consequences of that, by the<br \/>\nway, one of them is, it says, anything you can do in one programming<br \/>\nlanguage, you can do in another programming language. And there is no<br \/>\nprogramming language that is better&#8211; well actually, that&#8217;s not quite<br \/>\ntrue, there are some better at doing certain kinds of things&#8211; but<br \/>\nthere&#8217;s nothing that you can do in C that you can&#8217;t do in Fortran. It&#8217;s<br \/>\ncalled Turing compatibility. Anything you can do with one, you can do<br \/>\nwith another, it&#8217;s based on that fundamental result.<\/p>\n<p>OK. Now,<br \/>\nfortunately we&#8217;re not going to start with Turing&#8217;s six primitives, this<br \/>\nwould be really painful programming, because they&#8217;re down at the level<br \/>\nof, &#8220;take this value and write it onto this tape.&#8221; First of all, we<br \/>\ndon&#8217;t have tapes anymore in computers, and even if we did, you don&#8217;t<br \/>\nwant to be programming at that level. What we&#8217;re going to see with<br \/>\nprogramming language is that we&#8217;re going to use higher-level abstracts. A<br \/>\n broader set of primitives, but nonetheless the same fundamental thing<br \/>\nholds. With those six primitives, you can do it.<\/p>\n<p>OK. So where<br \/>\nare we here? What we&#8217;re saying is, in order to do computation, we want<br \/>\nto describe recipes, we want to describe this sequence of steps built on<br \/>\n some primitives, and we want to describe the flow of control that goes<br \/>\nthrough those sequence of steps as we carry on.<\/p>\n<p>So the last<br \/>\nthing we need before we can start talking about real programming is, we<br \/>\nneed to describe those recipes. All right, And to describe the recipes,<br \/>\nwe&#8217;re going to want a language. We need to know not only what are the<br \/>\nprimitives, but how do we make things meaningful in that language.<br \/>\nLanguage. There we go. All right. Now, it turns out there are&#8211; I don&#8217;t<br \/>\nknow, John, hundreds? Thousands? Of programming languages? At least<br \/>\nhundreds&#8211; of programming languages around.<\/p>\n<p>PROFESSOR JOHN GUTTAG: [UNINTELLIGIBLE]<\/p>\n<p>PROFESSOR<br \/>\n ERIC GRIMSON: True. Thank you. You know, they all have, you know, their<br \/>\n pluses and minuses. I have to admit, in my career here, I think I&#8217;ve<br \/>\ntaught in at least three languages, I suspect you&#8217;ve taught more, five<br \/>\nor six, John? Both of us have probably programmed in more than those<br \/>\nnumber of languages, at least programmed that many, since we taught in<br \/>\nthose languages.<\/p>\n<p>One of the things you want to realize is, there<br \/>\n is no best language. At least I would argue that, I think John would<br \/>\nagree. We might both agree we have our own nominees for worst language,<br \/>\nthere are some of those. There is no best language. All right? They all<br \/>\nare describing different things. Having said that, some of them are<br \/>\nbetter suited for some things than others.<\/p>\n<p>Anybody here heard of<br \/>\n MATLAB Maybe programmed in MATLAB? It&#8217;s great for doing things with<br \/>\nvectors and matrices and things that are easily captured in that<br \/>\nframework. But there&#8217;s some things that are a real pain to do in MATLAB.<br \/>\n So MATLAB&#8217;s great for that kind of thing.<\/p>\n<p>C is a great language for programming things that control data networks, for example.<\/p>\n<p>I<br \/>\n happen to be, and John teases me about this regularly, I&#8217;m an old-time<br \/>\nLisp programmer, and that&#8217;s how I was trained. And I happen to like Lisp<br \/>\n and Scheme, it&#8217;s a great language when you&#8217;re trying to deal with<br \/>\nproblems where you have arbitrarily structured data sets. It&#8217;s<br \/>\nparticularly good at that.<\/p>\n<p>So the point I want to make here is<br \/>\nthat there&#8217;s no particularly best language. What we&#8217;re going to do is<br \/>\nsimply use a language that helps us understand. So in this course, the<br \/>\nlanguage we&#8217;re going to use is Python. Which is a pretty new language,<br \/>\nit&#8217;s growing in popularity, it has a lot of the elements of some other<br \/>\nlanguages because it&#8217;s more recent, it inherits things from it&#8217;s<br \/>\npregenitors, if you like.<\/p>\n<p>But one of the things I want to stress<br \/>\n is, this course is not about Python. Strange statement. You do need to<br \/>\nknow how to use it, but it&#8217;s not about the details of, where do the<br \/>\nsemi-colons go in Python. All right? It&#8217;s about using it to think.<\/p>\n<p>And<br \/>\n what you should take away from this course is having learned how to<br \/>\ndesign recipes, how to structure recipes, how to do things in modes in<br \/>\nPython. Those same tools easily transfer to any other language. You can<br \/>\npick up another language in a week, couple of weeks at most, once you<br \/>\nknow how to do Python.<\/p>\n<p>OK. In order to talk about Python and<br \/>\nlanguages, I want to do one last thing to set the stage for what we&#8217;re<br \/>\ngoing to do here, and that&#8217;s to talk about the different dimensions of a<br \/>\n language. And there&#8217;re three I want to deal with.<\/p>\n<p>The first one<br \/>\n is, whether this is a high-level or low-level language. That basically<br \/>\nsays, how close are you the guts of the machine? A low-level language,<br \/>\nwe used to call this assembly programming, you&#8217;re down at the level of,<br \/>\nyour primitives are literally moving pieces of data from one location of<br \/>\n memory to another, through a very simple operation. A high-level<br \/>\nlanguage, the designer has created a much richer set of primitive<br \/>\nthings. In a high-level language, square root might simply be a<br \/>\nprimitive that you can use, rather than you having to go over and code<br \/>\nit. And there&#8217;re trade-offs between both.<\/p>\n<p>Second dimension is,<br \/>\nwhether this is a general versus a targeted language. And by that I<br \/>\nmean, do the set of primitives support a broad range of applications, or<br \/>\n is it really aimed at a very specific set of applications? I&#8217;d argue<br \/>\nthat MATLAB is basically a targeted language, it&#8217;s targeted at matrices<br \/>\nand vectors and things like that.<\/p>\n<p>And the third one I want to<br \/>\npoint out is, whether this is an interpreted versus a compiled language.<br \/>\n What that basically says is the following: in an interpreted language,<br \/>\nyou take what&#8217;s called the source code, the thing you write, it may go<br \/>\nthrough a simple checker but it basically goes to the interpreter, that<br \/>\nthing inside the machine that&#8217;s going to control the flow of going<br \/>\nthrough each one of the instructions, and give you an output. So the<br \/>\ninterpreter is simply operating directly on your code at run time.<\/p>\n<p>In<br \/>\n a compiled language, you have an intermediate step, in which you take<br \/>\nthe source code, it runs through what&#8217;s called a checker or a compiler<br \/>\nor both, and it creates what&#8217;s called object code. And that does two<br \/>\nthings: one, it helps catch bugs in your code, and secondly it often<br \/>\nconverts it into a more efficient sequence of instructions before you<br \/>\nactually go off and run it. All right?<\/p>\n<p>And there&#8217;s trade-offs<br \/>\nbetween both. I mean, an interpreted language is often easier to debug,<br \/>\nbecause you can still see your raw code there, but it&#8217;s not always as<br \/>\nfast. A compiled language is usually much faster in terms of its<br \/>\nexecution. And it&#8217;s one of the things you may want to trade off.<\/p>\n<p>Right.<br \/>\n In the case of Python, it&#8217;s a high-level language. I would argue, I<br \/>\nthink John would agree with me, it&#8217;s basically a general-purpose<br \/>\nlanguage. It happens to be better suited for manipulating strings than<br \/>\nnumbers, for example, but it&#8217;s really a general-purpose language. And<br \/>\nit&#8217;s primarily&#8211; I shouldn&#8217;t say primarily, it is an interpreted<br \/>\nlanguage. OK?<\/p>\n<p>As a consequence, it&#8217;s not as good as helping<br \/>\ndebug, but it does let you&#8211; sorry, that&#8217;s the wrong way of saying&#8211;<br \/>\nit&#8217;s not as good at catching some things before you run them, it is<br \/>\neasier at some times in debugging as you go along on the fly.<\/p>\n<p>OK.<br \/>\n So what does Python look like? In order to talk about Python&#8211;<br \/>\nactually, I&#8217;m going to do it this way&#8211; we need to talk about how to<br \/>\nwrite things in Python. Again, you have to let me back up slightly and<br \/>\nset the stage.<\/p>\n<p>Our goal is to build recipes. You&#8217;re all going to<br \/>\n be great chefs by the time you&#8217;re done here. All right? Our goal is to<br \/>\ntake problems and break them down into these computational steps, these<br \/>\nsequence of instructions that&#8217;ll allow us to capture that process.<\/p>\n<p>To<br \/>\n do that, we need to describe: not only, what are the primitives, but<br \/>\nhow do we capture things legally in that language, and interact with the<br \/>\n computer? And so for that, we need a language. We&#8217;re about to start<br \/>\ntalking about the elements of the language, but to do that, we also need<br \/>\n to separate out one last piece of distinction. Just like with a natural<br \/>\n language, we&#8217;re going to separate out syntax versus semantics.<\/p>\n<p>So<br \/>\n what&#8217;s syntax? Syntax basically says, what are the legal expressions in<br \/>\n this language? Boy, my handwriting is atrocious, isn&#8217;t it? There&#8217;s a<br \/>\nEnglish sequence of words. It&#8217;s not since syntactically correct, right?<br \/>\nIt&#8217;s not a sentence. There&#8217;s no verb in there anywhere, it&#8217;s just a<br \/>\nsequence of nouns. Same thing in our languages. We have to describe how<br \/>\ndo you put together legally formed expressions. OK? And as we add<br \/>\nconstructs to the language, we&#8217;re going to talk about.<\/p>\n<p>Second<br \/>\nthing we want to talk about very briefly as we go along is the semantics<br \/>\n of the language. And here we&#8217;re going to break out two pieces; static<br \/>\nsemantics and full semantics. Static semantics basically says which<br \/>\nprograms are meaningful. Which expressions make sense. Here&#8217;s an English<br \/>\n sentence. It&#8217;s syntactically correct. Right? Noun phrase, verb, noun<br \/>\nphrase. I&#8217;m not certain it&#8217;s meaningful, unless you are in the habit of<br \/>\ngiving your furniture personal names.<\/p>\n<p>What&#8217;s the point? Again,<br \/>\nyou can have things that are syntactically legal but not semantically<br \/>\nmeaningful, and static semantics is going to be a way of helping us<br \/>\ndecide what expressions, what pieces of code, actually have real meaning<br \/>\n to it. All right?<\/p>\n<p>The last piece of it is, in addition to<br \/>\nhaving static semantics, we have sort of full semantics. Which is, what<br \/>\ndoes the program mean? Or, said a different way, what&#8217;s going to happen<br \/>\nwhen I run it? That&#8217;s the meaning of the expression. That&#8217;s what you<br \/>\nwant. All right? You want to know, what&#8217;s the meaning of this piece of<br \/>\ncode? When I run it, what&#8217;s going to happen? That&#8217;s what I want to<br \/>\nbuild.<\/p>\n<p>The reason for pulling this out is, what you&#8217;re going to<br \/>\nsee is, that in most languages, and certainly in Python&#8211; we got lots of<br \/>\n help here&#8211; all right, Python comes built-in with something that will<br \/>\ncheck your static, sorry, your syntax for you. And in fact, as a<br \/>\nsidebar, if you turn in a problem set that is not syntactically correct,<br \/>\n there&#8217;s a simple button that you push that will check your syntax. If<br \/>\nyou&#8217;ve turned in a program that&#8217;s not syntactically correct, the TAs<br \/>\ngive you a zero. Because it said you didn&#8217;t even take the time to make<br \/>\nsure the syntax is correct. The system will help you find it. In Python,<br \/>\n it&#8217;ll find it, I think one bug at a time, right John? It finds one<br \/>\nsyntax error at a time, so you have to be a little patient to do it, but<br \/>\n you can check that the syntax is right.<\/p>\n<p>You&#8217;re going to see<br \/>\nthat we get some help here on the static semantics, and I&#8217;m going to do<br \/>\nan example in a second, meaning that the system, some languages are<br \/>\nbetter than others on it, but it will try and help you catch some things<br \/>\n that are not semantically correct statically. In the case of Python, it<br \/>\n does that I think all at run time. I&#8217;m looking to you again, John, I<br \/>\nthink there&#8217;s no pre-time checks. Its&#8211; sorry?<\/p>\n<p>PROFESSOR JOHN GUTTAG: [UNINTELLIGIBLE]<\/p>\n<p>PROFESSOR<br \/>\n ERIC GRIMSON: There is some. OK. Most of them, I think though, are<br \/>\nprimarily caught at run time, and that&#8217;s a little bit of a pain because<br \/>\nyou don&#8217;t see it until you go and run the code, and there are some,<br \/>\nactually we&#8217;re going to see an example I think in a second where you<br \/>\nfind it, but you do get some help there.<\/p>\n<p>The problem is, things<br \/>\nthat you catch here are actually the least worrisome bugs. They&#8217;re easy<br \/>\nto spot, you can&#8217;t run the program with them there, so you&#8217;re not going<br \/>\nto get weird answers. Not everything is going to get caught in static<br \/>\nsemantics checking. Some things are going to slide through, and that&#8217;s<br \/>\nactually a bother. It&#8217;s a problem. Because it says, your program will<br \/>\nstill give you a value, but it may not be what you intended, and you<br \/>\ncan&#8217;t always tell, and that may propagate it&#8217;s way down through a whole<br \/>\nbunch of other computations before it causes some catastrophic failure.<br \/>\nSo actually, the problem with static semantics is you&#8217;d like it to catch<br \/>\n everything, you don&#8217;t always get it. Sadly we don&#8217;t get much help here.<br \/>\n Which is where we&#8217;d like it. But that&#8217;s part of your job.<\/p>\n<p>OK.<br \/>\nWhat happens if you actually have something that&#8217;s both syntactically<br \/>\ncorrect, and appears to have correct static semantics, and you run it?<br \/>\nIt could run and give you the right answer, it could crash, it could<br \/>\nloop forever, it could run and apparently give you the right answer. And<br \/>\n you&#8217;re not always going to be able to tell. Well, you&#8217;ll know when it<br \/>\ncrashes, that doesn&#8217;t help you very much, but you can&#8217;t always tell<br \/>\nwhether something&#8217;s stuck in an infinite loop or whether it&#8217;s simply<br \/>\ntaking a long time to compute. You&#8217;d love to have a system that spots<br \/>\nthat for you, but it&#8217;s not possible.<\/p>\n<p>And so to deal with this<br \/>\nlast one, you need to develop style. All right? Meaning, we&#8217;re going to<br \/>\ntry to help you with how to develop good programming style, but you need<br \/>\n to write in a way in which it is going to be easy for you to spot the<br \/>\nplaces that cause those semantic bugs to occur.<\/p>\n<p>All right. If<br \/>\nthat sounds like a really long preamble, it is. Let&#8217;s start with Python.<br \/>\n But again, my goal here is to let you see what computation&#8217;s about, why<br \/>\n we need to do it, I&#8217;m going to remind you one last time, our goal is to<br \/>\n be able to have a set of primitives that we combine into complex<br \/>\nexpressions, which we can then abstract to treat as primitives, and we<br \/>\nwant to use that sequence of instructions in this flow of control<br \/>\ncomputing, in order to deduce new information. That imperative knowledge<br \/>\n that we talked about right there. So I&#8217;m going to start today, we have<br \/>\nabout five or ten minutes left, I think, in order&#8211; sorry, five minutes<br \/>\nleft&#8211; in order to do this with some beginnings of Python, and we&#8217;re<br \/>\ngoing to pick this up obviously, next time, so; simple parts of Python.<\/p>\n<p>In<br \/>\n order to create any kinds of expressions, we&#8217;re going to need values.<br \/>\nPrimitive data elements. And in Python, we have two to start with; we<br \/>\nhave numbers, and we have strings. Numbers is what you&#8217;d expect. There&#8217;s<br \/>\n a number. There&#8217;s another number. All right? Strings are captured in<br \/>\nPython with an open quote and some sequence of characters followed by a<br \/>\nclosed quote.<\/p>\n<p>Associated with every data type in Python is a<br \/>\ntype, which identifies the kind of thing it is. Some of these are<br \/>\nobvious. Strings are just a type on their own. But for numbers, for<br \/>\nexample, we can have a variety of types. So this is something that we<br \/>\nwould call an integer, or an INT. And this is something we would call a<br \/>\nfloating point, or a float. Or if you want to think of it as a real<br \/>\nnumber. And there&#8217;s some others that we can see.<\/p>\n<p>We&#8217;re going to<br \/>\nbuild up this taxonomy if you like, but the reason it&#8217;s relevant is,<br \/>\nassociated with each one of those types is a set of operators that<br \/>\nexpect certain types of input in order to do their job. And given those<br \/>\ntypes of input, will get back output.<\/p>\n<p>All right. In order to<br \/>\ndeal with this, let me show you an example, and I hope that comes up,<br \/>\ngreat. What I have here is a Python shell, and I&#8217;m going to just show<br \/>\nyou some simple examples of how we start building expressions. And<br \/>\nthis&#8217;ll lead into what you&#8217;re going to see next time as well as what<br \/>\nyou&#8217;re going to do tomorrow. So. Starting with the shell, I can type in<br \/>\nexpressions.<\/p>\n<p>Actually, let me back up and do this in video. I<br \/>\ncan type in a number, I get back a number, I can type in a string, I get<br \/>\n back the string. Strings, by the way, can have spaces in them, they can<br \/>\n have other characters, it&#8217;s simply a sequence of things, and notice, by<br \/>\n the way, that the string five&#8211; sorry, the string&#8217;s digit five digit<br \/>\ntwo is different than the number 52. The quotes are around them to make<br \/>\nthat distinction. We&#8217;re going to see why in a second.<\/p>\n<p>What I&#8217;m<br \/>\ndoing, by the way, here is I&#8217;m simply typing in expressions to that<br \/>\ninterpreter. It&#8217;s using its set of rules to deduce the value and print<br \/>\nthem back out. Things I might like to do in here is, I might like to do<br \/>\ncombinations of things with these. So we have associated with simple<br \/>\nthings, a set of operations. So for numbers, we have the things you&#8217;d<br \/>\nexpect, the arithmetics. And let me show you some examples of that.<\/p>\n<p>And<br \/>\n actually, I&#8217;m going to do one other distinction here. What I typed in,<br \/>\nthings like&#8211; well, let me start this way&#8211; there&#8217;s an expression. And<br \/>\nin Python the expression is, operand, operator, operand, when we&#8217;re<br \/>\ndoing simple expressions like this, and if I give it to the interpreter,<br \/>\n it gives me back exactly what you&#8217;d expect, which is that value. OK?<\/p>\n<p>The<br \/>\n distinction I&#8217;m going to make is, that&#8217;s an expression. The interpreter<br \/>\n is going to get a value for it. When we start building up code, we&#8217;re<br \/>\ngoing to use commands. Or statements. Which are actually things that<br \/>\ntake in a value and ask the computer to do something with it. So I can<br \/>\nsimilarly do this, which is going to look strange because it&#8217;s going to<br \/>\ngive me the same value back out, but it actually did a slightly<br \/>\ndifferent thing.<\/p>\n<p>And notice, by the way, when I typed it how<br \/>\nprint showed up in a different color? That&#8217;s the Python saying, that is a<br \/>\n command, that is a specific command to get the value of the expression<br \/>\nand print it back out. When we start writing code, you&#8217;re going to see<br \/>\nthat difference, but for now, don&#8217;t worry about it, I just want to plant<br \/>\n that idea.<\/p>\n<p>OK. Once we&#8217;ve got that, we can certainly, though,<br \/>\ndo things like this. Notice the quotes around it. And it treats it as a<br \/>\nstring, it&#8217;s simply getting me back the value of that string, 52 times<br \/>\n7, rather than the value of it. Now, once we&#8217;ve got that, we can start<br \/>\ndoing things. And I&#8217;m going to use print here&#8211; if I could type, in<br \/>\norder to just to get into that, I can&#8217;t type, here we go&#8211; in order to<br \/>\nget into the habit. I can print out a string. I can print out&#8211; Ah!&#8211;<br \/>\nHere&#8217;s a first example of something that caught one of my things. This<br \/>\nis a static semantic error.<\/p>\n<p>So what went on here? I gave it an<br \/>\nexpression that had an operand in there. It expected arithmetic types.<br \/>\nBut I gave two strings. And so it&#8217;s complaining at me, saying, you can&#8217;t<br \/>\n do this. I don&#8217;t know how to take two strings and multiply them<br \/>\ntogether. Unfortunately&#8211; now John you may disagree with me on this<br \/>\none&#8211; unfortunately in Python you can, however, do things like this.<br \/>\nWhat do you figure that&#8217;s going to do? Look legal? The string three<br \/>\ntimes the number three? Well it happens to give me three threes in a<br \/>\nrow.<\/p>\n<p>I hate this. I&#8217;m sorry, John, I hate this. Because this is<br \/>\noverloading that multiplication operator with two different tasks. It&#8217;s<br \/>\nsaying, if you give me two numbers, I&#8217;ll do the right thing. If you give<br \/>\n me a number and a string, I&#8217;m going to concatenate them together, it&#8217;s<br \/>\nreally different operations, but nonetheless, it&#8217;s what it&#8217;s going to<br \/>\ndo.<\/p>\n<p>STUDENT: [UNINTELLIGIBLE]<\/p>\n<p>PROFESSOR ERIC GRIMSON:<br \/>\nThere you go. You know, there will be a rebuttal phase a little later<br \/>\non, just like with the political debates, and he likes it as a feature, I<br \/>\n don&#8217;t like it, you can tell he&#8217;s not a Lisp programmer and I am.<\/p>\n<p>All<br \/>\n right. I want to do just a couple more quick examples. Here&#8217;s another<br \/>\none. Ah-ha! Give you an example of a syntax error. Because 52A doesn&#8217;t<br \/>\nmake sense. And you might say, wait a minute, isn&#8217;t that a string, and<br \/>\nthe answer&#8217;s no, I didn&#8217;t say it&#8217;s a string by putting quotes around it.<br \/>\n And notice how the machine responds differently to it. In this case it<br \/>\nsays, this is a syntax error, and it&#8217;s actually highlighting where it<br \/>\ncame from so I can go back and fix it.<\/p>\n<p>All right. Let&#8217;s do a<br \/>\ncouple of other simple examples. All right? I can do multiplication.<br \/>\nI&#8217;ve already seen that. I can do addition. Three plus five. I can take<br \/>\nsomething to a power, double star, just take three to the fifth power. I<br \/>\n can do division, right? Whoa. Right? Three divided by five is zero?<br \/>\nMaybe in Bush econom&#8211; no, I&#8217;m not going to do any political comments<br \/>\ntoday, I will not say that, all right?<\/p>\n<p>What happened? Well, this<br \/>\n is one of the places where you have to be careful. It&#8217;s doing integer<br \/>\ndivision. So, three divided by five is zero, with a remainder of three.<br \/>\nSo this is the correct answer. If I wanted to get full, real division, I<br \/>\n should make one of them a float. And yes, you can look at that and say,<br \/>\n well is that right? Well, up to some level of accuracy, yeah, that&#8217;s .6<br \/>\n is what I&#8217;d like to get out.<\/p>\n<p>All right. I can do other things.<br \/>\nIn a particular, I have similar operations on strings. OK, I can<br \/>\ncertainly print out strings, but I can actually add strings together,<br \/>\nand just as you saw, I can multiply strings, you can kind of guess what<br \/>\nthis is going to do. It is going to merge them together into one thing. I<br \/>\n want&#8211; I know I&#8217;m running you slightly over, I want to do one last<br \/>\nexample, it&#8217;s, I also want to be able to do, have variables to store<br \/>\nthings. And to do that, in this it says, if I have a value, I want to<br \/>\nkeep it around, to do that, I can do things like this.<\/p>\n<p>What does<br \/>\n that statement do? It says, create a name for a variable&#8211; which I just<br \/>\n did there, in fact, let me type it in&#8211; mystring, with an equal sign,<br \/>\nwhich is saying, assign or bind to that name the value of the following<br \/>\nexpression. As a consequence, I can now refer to that just by its name.<br \/>\nIf I get the value of mystring, there it is, or if I say, take mystring<br \/>\nand add to it the string, mylastname, and print it back out.<\/p>\n<p>So<br \/>\nthis is the first start of this. What have we done? We&#8217;ve got values,<br \/>\nnumbers and strings. We have operations to associate with them. I just<br \/>\nthrew a couple up here. You&#8217;re going to get a chance to explore them,<br \/>\nand you&#8217;ll see not only are there the standard numerics for strings,<br \/>\nthere are things like length or plus or other things you can do with<br \/>\nthem. And once I have values, I want to get a hold of them so I can give<br \/>\n them names. And that&#8217;s what I just did when I bound that. I said, use<br \/>\nthe name mystring to be bound to or have the value of Eric, so I can<br \/>\nrefer to it anywhere else that I want to use it.<\/p>\n<p>And I apologize<br \/>\n for taking you over, we&#8217;ll come back to this next time, please go to<br \/>\nthe website to sign up for recitation for tomorrow.<\/p>\n<\/div>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp;\uccab \uc2dc\uac04. \uc218\uc5c5\uc758 \ub0b4\uc6a9\uacfc \uc55e\uc73c\ub85c \uc5b4\ub5a4 \uacf5\ubd80\ub4e4\uc744 \ud558\uac8c \ub420 \uac83\uc778\uc9c0\uc5d0 \ub300\ud55c \uc124\uba85\uc744 \ud558\uace0 \uc788\ub2e4. &nbsp;\ud30c\uc774\uc36c\uc744 \ud504\ub85c\uadf8\ub798\ubc0d \uc5b8\uc5b4\ub85c \uc0ac\uc6a9\ud560 \uac83\uc774\uba70, \uadf8\uc678 \uae30\ud0c0 \ub4f1\ub4f1\uc5d0 \ub300\ud55c \uc774\uc57c\uae30\ub97c \ud558\uace0 \uc788\ub2e4. The following content is provided under a Creative Commons license. Your support will help &hellip; <a href=\"http:\/\/pchero21.com\/?p=958\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[27],"tags":[259,260],"_links":{"self":[{"href":"http:\/\/pchero21.com\/index.php?rest_route=\/wp\/v2\/posts\/958"}],"collection":[{"href":"http:\/\/pchero21.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/pchero21.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/pchero21.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/pchero21.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=958"}],"version-history":[{"count":0,"href":"http:\/\/pchero21.com\/index.php?rest_route=\/wp\/v2\/posts\/958\/revisions"}],"wp:attachment":[{"href":"http:\/\/pchero21.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=958"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/pchero21.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=958"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/pchero21.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=958"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}