Lec 1 | MIT 6.00 Introduction to Computer Science and Programming, Fall 2008 — Transcript
Full transcript
- 0:00The following content is provided under a Creative
- 0:02Commons license.
- 0:03Your support will help MIT OpenCourseware continue to
- 0:06offer high-quality educational resources for free.
- 0:10To make a donation, or view additional materials from
- 0:13hundreds of MIT courses, visit MIT OpenCourseware, at
- 0:17ocw.mit.edu .
- 0:17PROFESSOR: Good morning.
- 0:18Try it again.
- 0:19Good morning.
- 0:22STUDENTS: Good morning.
- 0:25PROFESSOR: Thank you.
- 0:27This is 6.00, also known as Introduction to Computer
- 0:31Science and Programming.
- 0:32My name is Eric Grimson, I have together Professor John
- 0:35Guttag over here, we're going to be lecturing
- 0:37the course this term.
- 0:39I want to give you a heads up; you're getting some serious
- 0:41firepower this term.
- 0:43John was department head for ten years, felt like a
- 0:47century, and in course six, I'm the current department
- 0:50head in course six.
- 0:51John's been lecturing for thirty years, roughly.
- 0:55All right, I'm the young guy, I've only been lecturing for
- 0:58twenty-five years.
- 0:59You can tell, I have less grey hair than he does.
- 1:03What I'm trying to say to you is, we take this
- 1:05course really seriously.
- 1:07We hope you do as well.
- 1:08But we think it's really important for the department
- 1:10to help everybody learn about computation, and that's what
- 1:14this course is about.
- 1:16What I want to do today is three things: I'm going to
- 1:19start-- actually, I shouldn't say start, I'm going to do a
- 1:22little bit of administrivia, the kinds of things you need
- 1:24to know about how we're going to run the course.
- 1:26I want to talk about the goal of the course, what it is
- 1:30you'll be able to do at the end of this course when you
- 1:32get through it, and then I want to begin talking about
- 1:35the concepts and tools of computational thinking, which
- 1:39is what we're primarily going to focus on here.
- 1:41We're going to try and help you learn how to think like a
- 1:43computer scientist, and we're going to begin talking about
- 1:45that towards the end of this lecture and of course
- 1:47throughout the rest of the lectures that carry on.
- 1:50Right, let's start with the goals.
- 1:52I'm going to give you goals in two levels.
- 1:55The strategic goals are the following: we want to help
- 1:58prepare freshmen and sophomores who are interested
- 2:02in majoring in course six to get an easy entry into the
- 2:05department, especially for those students who don't have
- 2:07a lot of prior programming experience.
- 2:09If you're in that category, don't panic, you're
- 2:11going to get it.
- 2:12We're going to help you ramp in and you'll certainly be
- 2:14able to start the course six curriculum and do just fine
- 2:17and still finish on target.
- 2:20We don't expect everybody to be a course six major,
- 2:22contrary to popular opinion, so for those are you not in
- 2:25that category, the second thing we want to do is we want
- 2:27to help students who don't plan to major in course six to
- 2:30feel justifiably confident in their ability to write and
- 2:34read small pieces of code.
- 2:37For all students, what we want to do is we want to give you
- 2:40an understanding of the role computation can and cannot
- 2:43play in tackling technical problems. So that you will
- 2:47come away with a sense of what you can do, what you can't do,
- 2:50and what kinds of things you should use to tackle complex
- 2:53problems.
- 2:54And finally, we want to position all students so that
- 2:56you can easily, if you like, compete for things like your
- 3:00office and summer jobs.
- 3:02Because you'll have an appropriate level of
- 3:04confidence and competence in your ability to do
- 3:06computational problem solving.
- 3:08Those are the strategic goals.
- 3:10Now, this course is primarily aimed at students who have
- 3:15little or no prior programming experience.
- 3:19As a consequence, we believe that no student here is
- 3:21under-qualified for this course: you're all MIT
- 3:24students, you're all qualified to be here.
- 3:26But we also hope that there aren't any students here who
- 3:29are over-qualified for this course.
- 3:31And what do I mean by that?
- 3:32If you've done a lot prior programming, this is probably
- 3:37not the best course for you, and if you're in that
- 3:39category, I would please encourage you to talk to John
- 3:42or I after class about what your goals are, what kind of
- 3:45experience you have, and how we might find you a course
- 3:48that better meets your goals.
- 3:51Second reason we don't want over-qualified students in the
- 3:54class, it sounds a little nasty, but the second reason
- 3:56is, an over-qualified student, somebody who's, I don't know,
- 3:59programmed for Google for the last five years, is going to
- 4:03have an easy time in this course, but we don't want such
- 4:05a student accidentally intimidating the rest of you.
- 4:08We don't want you to feel inadequate when you're simply
- 4:12inexperienced.
- 4:13And so, it really is a course aimed at students with little
- 4:16or no prior programming experience.
- 4:18And again, if you're not in that category, talk to John or
- 4:20I after class, and we'll help you figure out where you might
- 4:22want to go.
- 4:24OK.
- 4:24Those are the top-level goals of the course.
- 4:26Let's talk sort of at a more tactical level, about what do
- 4:29we want you to know in this course.
- 4:31What we want you to be able to do by the time
- 4:33you leave this course?
- 4:34So here are the skills that we would like you to acquire.
- 4:41Right, the first skill we want you to acquire, is we want you
- 4:44to be able to use the basic tools of computational
- 4:46thinking to write small scale programs. I'm going to keep
- 4:50coming back to that idea, but I'm going to call it
- 4:52computational thinking.
- 4:57And that's so you can write small pieces of code.
- 5:00And small is not derogatory here, by the way, it just says
- 5:02the size of things you're going to be able to do.
- 5:05Second skill we want you to have at the end of this course
- 5:08is the ability to use a vocabulary of computational
- 5:10tools in order to be able to understand
- 5:13programs written by others.
- 5:15So you're going to be able to write, you're going
- 5:16to be able to read.
- 5:19This latter skill, by the way, is incredibly valuable.
- 5:24Because you won't want to do everything from scratch
- 5:26yourself, you want to be able to look at what is being
- 5:28created by somebody else and understand what is inside of
- 5:31there, whether it works correctly and how you can
- 5:33build on it.
- 5:34This is one of the few places where
- 5:35plagiarism is an OK thing.
- 5:37It's not bad to, if you like, learn from the skills of
- 5:40others in order to create something you want to write.
- 5:42Although we'll come back to plagiarism as a
- 5:44bad thing later on.
- 5:46Third thing we want you to do, is to understand the
- 5:48fundamental both capabilities and limitations of
- 5:52computations, and the costs associated with them.
- 5:55And that latter statement sounds funny, you don't think
- 5:57of computations having limits, but they do.
- 5:59There're some things that cannot be computed.
- 6:01We want you to understand where those limits are.
- 6:03So you're going to be able to understand
- 6:05abilities and limits.
- 6:15And then, finally, the last tactical skill that you're
- 6:18going to get out of this course is you're going to have
- 6:19the ability to map scientific problems into a
- 6:22computational frame.
- 6:24So you're going to be able to take a description of a
- 6:26problem and map it into something computational.
- 6:37Now if you think about it, boy, it sounds
- 6:39like grammar school.
- 6:41We're going to teach you to read, we're going to teach you
- 6:43to write, we're going to teach you to understand what you can
- 6:46and cannot do, and most importantly, we're going to
- 6:49try and give you the start of an ability to take a
- 6:52description of a problem from some other domain, and figure
- 6:55out how to map it into that domain of computation so you
- 6:57can do the reading and writing that you want to do.
- 7:01OK, in a few minutes we're going to start talking then
- 7:03about what is computation, how are we going to start building
- 7:05those tools, but that's what you should take away, that's
- 7:07what you're going to gain out of this course by the time
- 7:09you're done.
- 7:11Now, let me take a sidebar for about five minutes to talk
- 7:14about course administration, the administrivia, things that
- 7:17we're going to do in the course, just so you know what
- 7:19the rules are.
- 7:20Right, so, class is two hours of lecture a week.
- 7:24You obviously know where and you know when,
- 7:26because you're here.
- 7:27Tuesdays and Thursdays at 11:00.
- 7:29One hour of recitation a week, on Fridays, and we'll come
- 7:32back in a second to how you're going to get set up for that.
- 7:34And nine hours a week of outside-the-class work.
- 7:38Those nine hours are going to be primarily working on
- 7:40problem sets, and all the problems sets are going to
- 7:42involve programming in Python, which is the language we're
- 7:45going to be using this term.
- 7:48Now, one of the things you're going to see is the first
- 7:50problem sets are pretty easy.
- 7:51Actually, that's probably wrong, John, right?
- 7:52They're very easy.
- 7:54And we're going to ramp up.
- 7:55By the time you get to the end of the term, you're going to
- 7:57be dealing with some fairly complex things, so one of the
- 7:59things you're going to see is, we're going to make heavy use
- 8:01of libraries, or code written by others.
- 8:04It'll allow you to tackle interesting problems I'll have
- 8:06you to write from scratch, but it does mean that this skill
- 8:11here is going to be really valuable.
- 8:13You need to be able to read that code and understand it,
- 8:15as well as write your own.
- 8:18OK.
- 8:19Two quizzes.
- 8:20During the term, the dates have already been scheduled.
- 8:23John, I forgot to look them up, I think it's October 2nd
- 8:25and November 4th, it'll be on the course website.
- 8:29My point is, go check the course website, which by the
- 8:31way is right there.
- 8:34If you have, if you know you have a conflict with one of
- 8:37those quiz dates now, please see John or I right away.
- 8:40We'll arrange something ahead of time.
- 8:42But if you--
- 8:44The reason I'm saying that is, you know, you know that you're
- 8:45getting married that day for example, we will excuse you
- 8:47from the quiz to get married.
- 8:49We'll expect you come right back to do the quiz by the
- 8:51way, but the--
- 8:53Boy, tough crowd.
- 8:54All right.
- 8:57If you have a conflict, please let us know.
- 8:59Second thing is, if you have an MIT documented special need
- 9:03for taking quizzes, please see John or I well in advance.
- 9:07At least two weeks before the quiz.
- 9:08Again, we'll arrange for this, but you need to give us enough
- 9:10warning so that we can deal with that.
- 9:13OK, the quizzes are open book.
- 9:16This course is not about memory.
- 9:20It's not how well you can memorize facts: in fact, I
- 9:22think both John and I are a little sensitive to memory
- 9:24tests, given our age, right John?
- 9:26This is not about how you memorize things, it's about
- 9:28how you think.
- 9:29So they're open note, open book.
- 9:30It's really going to test your ability to think.
- 9:34The grades for the course will be assigned roughly, and I use
- 9:38the word roughly because we reserve the right to move
- 9:40these numbers around a little bit, but basically in the
- 9:42following percentages: 55% of your grade comes from the
- 9:44problem sets, the other 45% come from the quizzes.
- 9:48And I should've said there's two quizzes and a final exam.
- 9:50I forgot, that final exam during final period.
- 9:52So the quiz percentages are 10%, 15%, and 20%.
- 9:55Which makes up the other 45%.
- 9:59OK.
- 10:00Other administrivia.
- 10:02Let me just look through my list here.
- 10:05First problem set, problem set zero, has already been posted.
- 10:07This is a really easy one.
- 10:09We intend it to be a really easy problem set.
- 10:11It's basically to get you to load up Python on your machine
- 10:14and make sure you understand how to interact with it.
- 10:17The first problem set will be posted shortly, it's also
- 10:19pretty boring-- somewhat like my lectures but not John's--
- 10:23and that means, you know, we want you just to
- 10:25get going on things.
- 10:26Don't worry, we're going to make them more interesting as
- 10:27you go along.
- 10:28Nonetheless, I want to stress that none of these problems
- 10:31sets are intended to be lethal.
- 10:33We're not using them to weed you out, we're using them to
- 10:36help you learn.
- 10:36So if you run into a problem set that just, you
- 10:39don't get, all right?
- 10:41Seek help.
- 10:43Could be psychiatric help, could be a TA.
- 10:46I recommend the TA.
- 10:47My point being, please come and talk to somebody.
- 10:50The problems are set up so that, if you start down the
- 10:53right path, it should be pretty straight-forward to
- 10:55work it through.
- 10:56If you start down a plausible but incorrect path, you can
- 11:00sometimes find yourself stuck in the weeds somewhere, and we
- 11:02want to bring you back in.
- 11:03So part of the goal here is, this should not be a grueling,
- 11:08exhausting kind of task, it's really something that should
- 11:10be helping you learn the material.
- 11:12If you need help, ask John, myself, or the TAs.
- 11:15That's what we're here for.
- 11:17OK.
- 11:18We're going to run primarily a paperless subject, that's why
- 11:22the website is there.
- 11:23Please check it, that's where everything's going to be
- 11:24posted in terms of things you need to know.
- 11:27In particular, please go to it today, you will find a form
- 11:30there that you need to fill out to register for, or sign
- 11:33up for rather, a recitation.
- 11:35Recitations are on Friday.
- 11:37Right now, we have them scheduled at 9:00, 10:00,
- 11:3911:00, 12:00, 1:00, and 2:00.
- 11:41We may drop one of the recitations, just depending on
- 11:45course size, all right?
- 11:46So we reserve the right, unfortunately, to have to move
- 11:48you around.
- 11:49My guess is that 9:00 is not going to be a tremendously
- 11:52popular time, but maybe you'll surprise me.
- 11:54Nonetheless, please go in and sign up.
- 11:56We will let you sign up for whichever recitation makes
- 11:58sense for you.
- 11:59Again, we reserve the right to move people around if we have
- 12:02to, just to balance load, but we want you to find something
- 12:04that fits your schedule rather than ours.
- 12:08OK.
- 12:09Other things.
- 12:10There is no required text.
- 12:12If you feel exposed without a text book, you really have to
- 12:17have a textbook, you'll find one recommended-- actually I'm
- 12:20going to reuse that word, John, at least suggest it, on
- 12:23the course website.
- 12:24I don't think either of us are thrilled with the text, it's
- 12:26the best we've probably found for Python, it's OK.
- 12:28If you need it, it's there.
- 12:29But we're going to basically not rely on any specific text.
- 12:33Right.
- 12:34Related to that: attendance here is
- 12:36obviously not mandatory.
- 12:38You ain't in high school anymore.
- 12:40I think both of us would love to see your smiling faces, or
- 12:42at least your faces, even if you're not
- 12:44smiling at us every day.
- 12:46Point I want to make about this, though, is that we are
- 12:49going to cover a lot of material that is not in the
- 12:52assigned readings, and we do have assigned readings
- 12:53associated with each one of these lectures.
- 12:57If you choose not to show up today-- or sorry, you did
- 13:00choose to show up today, if you choose not to show up in
- 13:03future days-- we'll understand, but please also
- 13:05understand that the TAs won't have a lot of patience with
- 13:08you if you're asking a question about something that
- 13:10was either covered in the readings, or covered in the
- 13:12lecture and is pretty straight forward.
- 13:14All right?
- 13:14We expect you to behave responsibly
- 13:16and we will as well.
- 13:18All right.
- 13:20I think the last thing I want to say is, we will not be
- 13:22handing out class notes.
- 13:26Now this sounds like a draconian measure;
- 13:27let me tell you why.
- 13:29Every study I know of, and I suspect every one John knows,
- 13:31about learning, stresses that students learn best when they
- 13:35take notes.
- 13:36Ironically, even if they never look at them.
- 13:40OK.
- 13:40The process of writing is exercising both halves of your
- 13:44brain, and it's actually helping you learn, and so
- 13:46taking notes is really valuable thing.
- 13:48Therefore we're not going to distribute notes.
- 13:50What we will distribute for most lectures is a handout
- 13:53that's mostly code examples that we're going to do.
- 13:55I don't happen to have one today because we're not going
- 13:57to do a lot of code.
- 13:58We will in future.
- 13:59Those notes are going to make no sense, I'm guessing,
- 14:02outside of the lecture, all right?
- 14:04So it's not just, you can swing by 11:04 and grab a copy
- 14:08and go off and catch some more sleep.
- 14:10What we recommend is you use those notes to take your own
- 14:13annotations to help you understand what's going on,
- 14:15but we're not going to provide class notes.
- 14:17We want you to take your own notes to help you, if you
- 14:20like, spur your own learning process.
- 14:23All right.
- 14:24And then finally, I want to stress that John, myself, all
- 14:28of the staff, our job is to help you learn.
- 14:32That's what we're here for.
- 14:32It's what we get excited about.
- 14:35If you're stuck, if you're struggling, if you're not
- 14:38certain about something, please ask.
- 14:40We're not mind readers, we can't tell when you're
- 14:42struggling, other than sort of seeing the expression on your
- 14:44face, we need your help in identifying that.
- 14:48But all of the TAs, many of whom are sitting down in the
- 14:50front row over here, are here to help, so come and ask.
- 14:53At the same time, remember that they're students too.
- 14:56And if you come and ask a question that you could have
- 14:59easily answered by doing the reading, coming to lecture, or
- 15:02using Google, they're going to have less patience.
- 15:05But helping you understand things that really are a
- 15:07conceptual difficulty is what they're here for and what
- 15:10we're here for, so please come and talk to us.
- 15:14OK.
- 15:15That takes care of the administrivia preamble.
- 15:17John, things we add?
- 15:18PROFESSOR GUTTAG: Two more quick things.
- 15:34This semester, your class is being videotaped for
- 15:35OpenCourseware.
- 15:35If any of you don't want your image recorded and posted on
- 15:36the web, you're supposed to sit in the back three rows.
- 15:38PROFESSOR GRIMSON: Ah, thank you.
- 15:39I forgot.
- 15:39PROFESSOR GUTTAG: --Because the camera may pan.
- 15:40I think you're all very good-looking and give MIT a
- 15:40good image, so please, feel free to be filmed.
- 15:40PROFESSOR GRIMSON: I'll turn around, so if you want to, you
- 15:45know, move to the back, I won't see who moves.
- 15:48Right.
- 15:48Great.
- 15:48Thank you, John.
- 15:49PROFESSOR GUTTAG: So that, the other thing I want to mention
- 15:57is, recitations are also very important.
- 16:00We will be covering material in recitations that're not in
- 16:00the lectures, not in the reading, and we do expect you
- 16:03to attend recitations.
- 16:03PROFESSOR GRIMSON: Great.
- 16:04Thanks, John.
- 16:06Any questions about the administrivia?
- 16:08I know it's boring, but we need to do it so you know what
- 16:10the ground rules are.
- 16:12Good.
- 16:13OK.
- 16:14Let's talk about computation.
- 16:16As I said, our strategic goal, our tactical goals, are to
- 16:19help you think like a computer scientist. Another way of
- 16:23saying it is, we want to give you the skill so that you can
- 16:25make the computer do what you want it to do.
- 16:28And we hope that at the end of the class, every time you're
- 16:30confronted with some technical problem, one of your first
- 16:32instincts is going to be, "How do I write the piece of code
- 16:35that's going to help me solve that?"
- 16:37So we want to help you think like a computer
- 16:39scientist. All right.
- 16:41And that, is an interesting statement.
- 16:45What does it mean, to think like a computer scientist?
- 16:55Well, let's see.
- 16:59The primary knowledge you're going to take away from this
- 17:00course is this notion of computational problem solving,
- 17:02this ability to think in
- 17:04computational modes of thought.
- 17:07And unlike in a lot of introductory courses, as a
- 17:10consequence, having the ability to memorize is not
- 17:12going to help you.
- 17:13It's really learning those notions of the tools that you
- 17:16want to use.
- 17:18What in the world does it mean to say
- 17:19computational mode of thought?
- 17:20It sounds like a hifalutin phrase you use when you're
- 17:22trying to persuade a VC to fund you.
- 17:24Right.
- 17:25So to answer this, we really have to ask a different
- 17:27question, a related question; so, what's computation?
- 17:31It's like a strange statement, right?
- 17:32What is computation?
- 17:35And part of the reason for putting it up is that I want
- 17:38to, as much as possible, answer that question by
- 17:41separating out the mechanism, which is the computer, from
- 17:45computational thinking.
- 17:47Right.
- 17:47The artifact should not be what's driving this.
- 17:49It should be the notion of, "What does it mean to do
- 17:51computation?"
- 17:53Now, to answer that, I'm going to back up one more level.
- 17:56And I'm going to pose what sounds like a philosophy
- 17:57question, which is, "What is knowledge?" And you'll see in
- 18:01about two minutes why I'm going to do this.
- 18:02But I'm going to suggest that I can divide knowledge into at
- 18:04least two categories.
- 18:07OK, and what is knowledge?
- 18:08And the two categories I'm going to divide them into are
- 18:12declarative and imperative knowledge.
- 18:19Right.
- 18:20What in the world is declarative knowledge?
- 18:22Think of it as statements of fact.
- 18:25It's assertions of truth.
- 18:27Boy, in this political season, that's a really dangerous
- 18:29phrase to use, right?
- 18:30But it's a statement of fact.
- 18:32I'll stay away from the political comments.
- 18:34Let me give you an example of this.
- 18:35Right.
- 18:36Here's a declarative statement.
- 18:37The square root of x is that y such that y squared equals x,
- 18:46y's positive.
- 18:48You all know that.
- 18:50But what I want you to see here, is that's a
- 18:52statement of fact.
- 18:54It's a definition.
- 18:55It's an axiom.
- 18:55It doesn't help you find square roots.
- 19:00If I say x is 2, I want to know, what's the square root
- 19:02of 2, well if you're enough of a geek, you'll say 1.41529 or
- 19:06whatever the heck it is, but in general, this doesn't help
- 19:10you find the square root.
- 19:12The closest it does is it would let you test. You know,
- 19:15if you're wandering through Harvard Square and you see an
- 19:17out-of-work Harvard grad, they're handing out examples
- 19:19of square roots, they'll give you an example and you can
- 19:21test it to see, is the square root of
- 19:232, 1.41529 or whatever.
- 19:26I don't even get laughs at Harvard jokes, John, I'm going
- 19:29to stop in a second here, all right?
- 19:31All right, so what am I trying to say here?
- 19:33It doesn't -- yeah, exactly.
- 19:36We're staying away from that, really quickly, especially
- 19:38with the cameras rolling.
- 19:39All right.
- 19:40What am I trying to say?
- 19:41It tells you how you might test something but it doesn't
- 19:44tell you how to.
- 19:46And that's what imperative knowledge is.
- 19:48Imperative knowledge is a description of
- 19:51how to deduce something.
- 19:52So let me give you an example of a piece
- 19:54of imperative knowledge.
- 19:56All right, this is actually a very old piece of imperative
- 19:58knowledge for computing square roots, it's attributed to
- 20:00Heron of Alexandria, although I believe that the Babylonians
- 20:04are suspected of knowing it beforehand.
- 20:07But here is a piece of imperative knowledge.
- 20:09All right?
- 20:10I'm going to start with a guess, I'm going to call it g.
- 20:17And then I'm going to say, if g squared is close to x, stop.
- 20:26And return g.
- 20:28It's a good enough answer.
- 20:30Otherwise, I'm going to get a new guess by taking g, x over
- 20:38g, adding them, and dividing by two.
- 20:42Then you take the average of g and x over g.
- 20:44Don't worry about how came about, Heron found this out.
- 20:47But that gives me a new guess, and I'm going to repeat.
- 20:56That's a recipe.
- 20:58That's a description of a set of steps.
- 21:01Notice what it has, it has a bunch of nice things that we
- 21:04want to use, right?
- 21:05It's a sequence of specific instructions
- 21:08that I do in order.
- 21:10Along the way I have some tests, and depending on the
- 21:13value of that test, I may change where I am in that
- 21:17sequence of instructions.
- 21:18And it has an end test, something that tells me when
- 21:20I'm done and what the answer is.
- 21:22This tells you how to find square roots.
- 21:24it's how-to knowledge.
- 21:25It's imperative knowledge.
- 21:27All right.
- 21:27That's what computation basically is about.
- 21:31We want to have ways of capturing this process.
- 21:35OK, and that leads now to an interesting question, which
- 21:37would be, "How do I build a mechanical process to capture
- 21:43that set of computations?" So I'm going to suggest that
- 21:46there's an easy way to do it--
- 21:50I realized I did the boards in the wrong order here-- one of
- 21:53the ways I could do it is, you could imagine building a
- 21:55little circuit to do this.
- 21:57If I had a couple of elements of stored values in it, I had
- 22:00some wires to move things around, I had a little thing
- 22:02to do addition, little thing to do division, and a
- 22:05something to do the testing, I could build a little circuit
- 22:07that would actually do this computation.
- 22:09OK.
- 22:11That, strange as it sounds, is actually an example of the
- 22:15earliest computers, because the earliest computers were
- 22:18what we call fixed-program computers, meaning that they
- 22:31had a piece of circuitry designed to do a specific
- 22:34computation.
- 22:35And that's what they would do: they would do that specific
- 22:38computation.
- 22:40You've seen these a lot, right?
- 22:41A good example of this: calculator.
- 22:47It's basically an example of a fixed-program computer.
- 22:51It does arithmetic.
- 22:53If you want play video games on it, good luck.
- 22:55If you want to do word processing on it, good luck.
- 22:58It's designed to do a specific thing.
- 23:00It's a fixed-program computer.
- 23:03In fact, a lot of the other really interesting early ones
- 23:05similarly have this flavor, to give an example: I never know
- 23:09how to pronounce this, Atanasoff, 1941.
- 23:14One of the earliest computational things was a
- 23:16thing designed by a guy named Atanasoff, and it basically
- 23:18solved linear equations.
- 23:22Handy thing to do if you're doing 1801, all right, or
- 23:261806, or whatever you want to do those things in.
- 23:29All it could do, though, was solve those equations.
- 23:31One of my favorite examples of an early computer was done by
- 23:36Alan Turing, one of the great computer scientists of all
- 23:39time, called the bombe, which was designed to break codes.
- 23:43It was actually used during WWII to break
- 23:45German Enigma codes.
- 23:46And what it was designed to do, was to solve
- 23:48that specific problem.
- 23:49The point I'm trying to make is, fixed-program computers is
- 23:53where we started, but it doesn't really get us to where
- 23:55we'd like to be.
- 23:55We want to capture this idea of problem solving.
- 23:58So let's see how we'd get there.
- 24:01So even within this framework of, given a description of a
- 24:05computation as a set of steps, in the idea that I could build
- 24:08a circuit to do it, let me suggest for you what would be
- 24:10a wonderful circuit to build.
- 24:13Suppose you could build a circuit with the following
- 24:15property: the input to this circuit would be any other
- 24:18circuit diagram.
- 24:20Give it a circuit diagram for some computation, you give it
- 24:22to the circuit, and that circuit would wonderfully
- 24:26reconfigure itself to act like the circuits diagram.
- 24:30Which would mean, it could act like a calculator.
- 24:33Or, it could act like Turing's bombe.
- 24:35Or, it could act like a square root machine.
- 24:38So what would that circuit look like?
- 24:39You can imagine these tiny little robots wandering
- 24:42around, right?
- 24:42Pulling wires and pulling out components and
- 24:44stacking them together.
- 24:45How would you build a circuit that could take a circuit
- 24:47diagram in and make a machine act like that circuit?
- 24:53Sounds like a neat challenge.
- 24:55Let me change the game slightly.
- 24:59Suppose instead, I want a machine that can take a
- 25:02recipe, the description of a sequence of steps, take that
- 25:07as its input, and then that machine will now act like what
- 25:12is described in that recipe.
- 25:15Reconfigure itself, emulate it, however you want to use
- 25:17the words, it's going to change how it does the
- 25:19computation.
- 25:21That would be cool.
- 25:23And that exists.
- 25:24It's called an interpreter.
- 25:26It is the basic heart of every computer.
- 25:29What it is doing, is saying, change the game.
- 25:33This is now an example of a stored-program computer.
- 25:40What that means, in a stored-program computer, is
- 25:48that I can provide to the computer a sequence of
- 25:51instructions describing the process I want it to execute.
- 25:55And inside of the machine, and things we'll talk about, there
- 25:58is a process that will allow that sequence to be executed
- 26:02as described in that recipe, so it can behave like any
- 26:06thing that I can describe in one of those recipes.
- 26:09All right.
- 26:10That actually seems like a really nice thing to have, and
- 26:14so let me show you what that would basically look like.
- 26:19Inside of a stored-program computer, we would have the
- 26:22following: we have a memory, it's connected to two things;
- 26:31control unit, in what's called an ALU, an arithmetic logic
- 26:37unit, and this can take in input, and spit out output,
- 26:46and inside this stored-program computer, excuse me, you have
- 26:50the following: you have a sequence of instructions.
- 26:55And these all get stored in there.
- 27:03Notice the difference.
- 27:05The recipe, the sequence of instructions, is actually
- 27:07getting read in, and it's treated just like data.
- 27:10It's inside the memory of the machine, which means we have
- 27:12access to it, we can change it, we can use it to build new
- 27:15pieces of code, as well as we can interpret it.
- 27:19One other piece that goes into this computer--
- 27:21I never remember where to put the PC, John, control?
- 27:23ALU?
- 27:25Separate?
- 27:26I'll put it separate-- you have a thing
- 27:29called a program counter.
- 27:31And here's the basis of the computation.
- 27:34That program counter points to some location in memory,
- 27:38typically to the first instruction in the sequence.
- 27:43And those instructions, by the way, are very simple: they're
- 27:45things like, take the value out of two places in memory,
- 27:48and run them through the multiplier in here, a little
- 27:51piece of circuitry, and stick them back into
- 27:53someplace in memory.
- 27:54Or take this value out of memory, run it through some
- 27:57other simple operation, stick it back in memory.
- 28:00Having executed this instruction, that counter goes
- 28:03up by one and we move to the next one.
- 28:05We execute that instruction, we move to the next one.
- 28:08Oh yeah, it looks a whole lot like that.
- 28:13Some of those instructions will involve tests: they'll
- 28:16say, is something true?
- 28:18And if the test is true, it will change the value of this
- 28:22program counter to point to some other place in the
- 28:25memory, some other point in that sequence of instructions,
- 28:28and you'll keep processing.
- 28:30Eventually you'll hopefully stop, and a value gets spit
- 28:32out, and you're done.
- 28:34That's the heart of a computer.
- 28:35Now that's a slight misstatement.
- 28:37The process to control it is intriguing and interesting,
- 28:39but the heart of the computer is simply this notion that we
- 28:42build our descriptions, our recipes, on a sequence of
- 28:46primitive instructions.
- 28:47And then we have a flow of control.
- 28:50And that flow of control is what I just described.
- 28:51It's moving through a sequence of instructions, occasionally
- 28:53changing where we are as we move around.
- 28:57OK.
- 28:58The thing I want you to take away from this, then, is to
- 29:02think of this as, this is, if you like, a recipe.
- 29:06And that's really what a program is.
- 29:19It's a sequence of instructions.
- 29:21Now, one of things I left hanging is, I said, OK, you
- 29:23build it out of primitives.
- 29:24So one of the questions is, well, what are the right
- 29:25primitives to use?
- 29:28And one of the things that was useful here is, that we
- 29:31actually know that the set of primitives that you want to
- 29:33use is very straight-forward.
- 29:37OK, but before I do that, let me drive home this idea of why
- 29:39this is a recipe.
- 29:42Assuming I have a set of primitive instructions that I
- 29:44can describe everything on, I want to know what can I build.
- 29:47Well, I'm going to do the same analogy to a real recipe.
- 29:49So, real recipe.
- 29:51I don't know.
- 29:51Separate six eggs.
- 29:54Do something.
- 29:55Beat until the-- sorry, beat the whites
- 29:57until they're stiff.
- 29:59Do something until an end test is true.
- 30:02Take the yolks and mix them in with the sugar and water--
- 30:04No.
- 30:05Sugar and flour I guess is probably what I want, sugar
- 30:06and water is not going to do anything interesting for me
- 30:08here-- mix them into something else.
- 30:11Do a sequence of things.
- 30:13A traditional recipe actually is based on a small set of
- 30:17primitives, and a good chef with, or good cook, I should
- 30:21say, with that set of primitives, can create an
- 30:23unbounded number of great dishes.
- 30:26Same thing holds true in programming.
- 30:28Right.
- 30:29Given a fixed set of primitives, all right, a good
- 30:37programmer can program anything.
- 30:43And by that, I mean anything that can be described in one
- 30:45of these process, you can capture in that set of
- 30:47primitives.
- 30:49All right, the question is, as I started to say, is, "What
- 30:51are the right primitives?" So there's a little bit of, a
- 30:54little piece of history here, if you like.
- 30:55In 1936, that same guy, Alan Turing, showed that with six
- 31:01simple primitives, anything that could be described in a
- 31:05mechanical process, it's actually algorithmically,
- 31:08could be programmed just using those six primitives.
- 31:12Think about that for a second.
- 31:14That's an incredible statement.
- 31:16It says, with six primitives, I can rule the world.
- 31:20With six primitives, I can program anything.
- 31:23A couple of really interesting consequences of that, by the
- 31:25way, one of them is, it says, anything you can do in one
- 31:29programming language, you can do in
- 31:31another programming language.
- 31:33And there is no programming language that is better-- well
- 31:36actually, that's not quite true, there are some better at
- 31:37doing certain kinds of things-- but there's nothing
- 31:39that you can do in C that you can't do in Fortran.
- 31:43It's called Turing compatibility.
- 31:45Anything you can do with one, you can do with another, it's
- 31:46based on that fundamental result.
- 31:49OK.
- 31:50Now, fortunately we're not going to start with Turing's
- 31:53six primitives, this would be really painful programming,
- 31:56because they're down at the level of, "take this value and
- 31:59write it onto this tape." First of all, we don't have
- 32:01tapes anymore in computers, and even if we did, you don't
- 32:04want to be programming at that level.
- 32:05What we're going to see with programming language is that
- 32:07we're going to use higher-level abstracts.
- 32:09A broader set of primitives, but nonetheless the same
- 32:12fundamental thing holds.
- 32:13With those six primitives, you can do it.
- 32:16OK.
- 32:18So where are we here?
- 32:19What we're saying is, in order to do computation, we want to
- 32:22describe recipes, we want to describe this sequence of
- 32:24steps built on some primitives, and we want to
- 32:28describe the flow of control that goes through those
- 32:30sequence of steps as we carry on.
- 32:33So the last thing we need before we can start talking
- 32:35about real programming is, we need to
- 32:36describe those recipes.
- 32:39All right, And to describe the recipes, we're
- 32:41going to want a language.
- 32:54We need to know not only what are the primitives, but how do
- 32:57we make things meaningful in that language.
- 33:01Language.
- 33:03There we go.
- 33:05All right.
- 33:07Now, it turns out there are--
- 33:08I don't know, John, hundreds?
- 33:09Thousands?
- 33:10Of programming languages?
- 33:11At least hundreds-- of programming languages around.
- 33:13PROFESSOR JOHN GUTTAG: [UNINTELLIGIBLE]
- 33:16PROFESSOR ERIC GRIMSON: True.
- 33:16Thank you.
- 33:18You know, they all have, you know,
- 33:20their pluses and minuses.
- 33:21I have to admit, in my career here, I think I've taught in
- 33:23at least three languages, I suspect you've taught more,
- 33:26five or six, John?
- 33:27Both of us have probably programmed in more than those
- 33:29number of languages, at least programmed that many, since we
- 33:31taught in those languages.
- 33:33One of the things you want to realize is,
- 33:35there is no best language.
- 33:36At least I would argue that, I think John would agree.
- 33:38We might both agree we have our own nominees for worst
- 33:40language, there are some of those.
- 33:43There is no best language.
- 33:44All right?
- 33:44They all are describing different things.
- 33:46Having said that, some of them are better suited for some
- 33:48things than others.
- 33:51Anybody here heard of MATLAB Maybe programmed in MATLAB?
- 33:55It's great for doing things with vectors and matrices and
- 33:58things that are easily captured in that framework.
- 34:01But there's some things that are a real
- 34:02pain to do in MATLAB.
- 34:03So MATLAB's great for that kind of thing.
- 34:05C is a great language for programming things that
- 34:07control data networks, for example.
- 34:10I happen to be, and John teases me about this
- 34:12regularly, I'm an old-time Lisp programmer, and that's
- 34:14how I was trained.
- 34:16And I happen to like Lisp and Scheme, it's a great language
- 34:19when you're trying to deal with problems where you have
- 34:20arbitrarily structured data sets.
- 34:23It's particularly good at that.
- 34:25So the point I want to make here is that there's no
- 34:27particularly best language.
- 34:30What we're going to do is simply use a language that
- 34:32helps us understand.
- 34:33So in this course, the language we're
- 34:34going to use is Python.
- 34:38Which is a pretty new language, it's growing in
- 34:39popularity, it has a lot of the elements of some other
- 34:42languages because it's more recent, it inherits things
- 34:44from it's pregenitors, if you like.
- 34:48But one of the things I want to stress is, this course is
- 34:50not about Python.
- 34:54Strange statement.
- 34:55You do need to know how to use it, but it's not about the
- 34:58details of, where do the semi-colons go in Python.
- 35:00All right?
- 35:02It's about using it to think.
- 35:04And what you should take away from this course is having
- 35:06learned how to design recipes, how to structure recipes, how
- 35:10to do things in modes in Python.
- 35:13Those same tools easily transfer
- 35:15to any other language.
- 35:16You can pick up another language in a week, couple of
- 35:18weeks at most, once you know how to do Python.
- 35:22OK.
- 35:23In order to talk about Python and languages, I want to do
- 35:25one last thing to set the stage for what we're going to
- 35:28do here, and that's to talk about the different dimensions
- 35:30of a language.
- 35:31And there're three I want to deal with.
- 35:33The first one is, whether this is a high-level
- 35:35or low-level language.
- 35:41That basically says, how close are you
- 35:42the guts of the machine?
- 35:43A low-level language, we used to call this assembly
- 35:45programming, you're down at the level of, your primitives
- 35:48are literally moving pieces of data from one location of
- 35:51memory to another, through a very simple operation.
- 35:54A high-level language, the designer has created a much
- 35:57richer set of primitive things.
- 35:59In a high-level language, square root might simply be a
- 36:02primitive that you can use, rather than you having to go
- 36:04over and code it.
- 36:06And there're trade-offs between both.
- 36:08Second dimension is, whether this is a general versus a
- 36:12targeted language.
- 36:15And by that I mean, do the set of primitives support a broad
- 36:18range of applications, or is it really aimed at a very
- 36:22specific set of applications?
- 36:23I'd argue that MATLAB is basically a targeted language,
- 36:25it's targeted at matrices and vectors and things like that.
- 36:29And the third one I want to point out is, whether this is
- 36:31an interpreted versus a compiled language.
- 36:41What that basically says is the following: in an
- 36:44interpreted language, you take what's called the source code,
- 36:46the thing you write, it may go through a simple checker but
- 36:49it basically goes to the interpreter, that thing inside
- 36:52the machine that's going to control the flow of going
- 36:54through each one of the instructions,
- 36:55and give you an output.
- 36:57So the interpreter is simply operating directly on your
- 37:00code at run time.
- 37:02In a compiled language, you have an intermediate step, in
- 37:05which you take the source code, it runs through what's
- 37:07called a checker or a compiler or both, and it creates what's
- 37:10called object code.
- 37:11And that does two things: one, it helps catch bugs in your
- 37:16code, and secondly it often converts it into a more
- 37:19efficient sequence of instructions before you
- 37:21actually go off and run it.
- 37:24All right?
- 37:24And there's trade-offs between both.
- 37:25I mean, an interpreted language is often easier to
- 37:27debug, because you can still see your raw code there, but
- 37:30it's not always as fast. A compiled language is usually
- 37:32much faster in terms of its execution.
- 37:34And it's one of the things you may want to trade off.
- 37:37Right.
- 37:38In the case of Python, it's a high-level language.
- 37:43I would argue, I think John would agree with me, it's
- 37:45basically a general-purpose language.
- 37:47It happens to be better suited for manipulating strings than
- 37:50numbers, for example, but it's really a
- 37:51general-purpose language.
- 37:53And it's primarily--
- 37:55I shouldn't say primarily, it is an interpreted language.
- 37:58OK?
- 37:59As a consequence, it's not as good as helping debug, but it
- 38:03does let you-- sorry, that's the wrong way of saying-- it's
- 38:04not as good at catching some things before you run them, it
- 38:07is easier at some times in debugging as you go
- 38:09along on the fly.
- 38:11OK.
- 38:11So what does Python look like?
- 38:13In order to talk about Python-- actually, I'm going
- 38:15to do it this way-- we need to talk about how to
- 38:22write things in Python.
- 38:22Again, you have to let me back up slightly and set the stage.
- 38:26Our goal is to build recipes.
- 38:28You're all going to be great chefs by the
- 38:29time you're done here.
- 38:30All right?
- 38:32Our goal is to take problems and break them down into these
- 38:35computational steps, these sequence of instructions
- 38:37that'll allow us to capture that process.
- 38:40To do that, we need to describe: not only, what are
- 38:42the primitives, but how do we capture things legally in that
- 38:45language, and interact with the computer?
- 38:47And so for that, we need a language.
- 38:49We're about to start talking about the elements of the
- 38:51language, but to do that, we also need to separate out one
- 38:54last piece of distinction.
- 38:58Just like with a natural language, we're going to
- 38:59separate out syntax versus semantics.
- 39:02So what's syntax?
- 39:03Syntax basically says, what are the legal expressions in
- 39:09this language?
- 39:16Boy, my handwriting is atrocious, isn't it?
- 39:22There's a English sequence of words.
- 39:25It's not since syntactically correct, right?
- 39:27It's not a sentence.
- 39:28There's no verb in there anywhere, it's just
- 39:30a sequence of nouns.
- 39:31Same thing in our languages.
- 39:32We have to describe how do you put together legally formed
- 39:36expressions.
- 39:38OK?
- 39:39And as we add constructs to the language, we're going to
- 39:41talk about.
- 39:42Second thing we want to talk about very briefly as we go
- 39:45along is the semantics of the language.
- 39:48And here we're going to break out two pieces; static
- 39:50semantics and full semantics.
- 39:53Static semantics basically says which programs are
- 40:01meaningful.
- 40:05Which expressions make sense.
- 40:09Here's an English sentence.
- 40:17It's syntactically correct.
- 40:20Right?
- 40:20Noun phrase, verb, noun phrase.
- 40:23I'm not certain it's meaningful, unless you are in
- 40:25the habit of giving your furniture personal names.
- 40:29What's the point?
- 40:30Again, you can have things that are syntactically legal
- 40:32but not semantically meaningful, and static
- 40:35semantics is going to be a way of helping us decide what
- 40:38expressions, what pieces of code, actually have real
- 40:41meaning to it.
- 40:41All right?
- 40:43The last piece of it is, in addition to having static
- 40:47semantics, we have sort of full semantics.
- 40:53Which is, what does the program mean?
- 40:58Or, said a different way, what's going to
- 40:59happen when I run it?
- 41:08That's the meaning of the expression.
- 41:09That's what you want.
- 41:10All right?
- 41:10You want to know, what's the meaning of this piece of code?
- 41:13When I run it, what's going to happen?
- 41:14That's what I want to build.
- 41:16The reason for pulling this out is, what you're going to
- 41:18see is, that in most languages, and certainly in
- 41:21Python-- we got lots of help here-- all right, Python comes
- 41:29built-in with something that will check your static, sorry,
- 41:31your syntax for you.
- 41:33And in fact, as a sidebar, if you turn in a problem set that
- 41:37is not syntactically correct, there's a simple button that
- 41:40you push that will check your syntax.
- 41:42If you've turned in a program that's not syntactically
- 41:44correct, the TAs give you a zero.
- 41:46Because it said you didn't even take the time to make
- 41:48sure the syntax is correct.
- 41:49The system will help you find it.
- 41:50In Python, it'll find it, I think one bug at
- 41:53a time, right John?
- 41:53It finds one syntax error at a time, so you have to be a
- 41:55little patient to do it, but you can check that
- 41:57the syntax is right.
- 41:59You're going to see that we get some help here on the
- 42:06static semantics, and I'm going to do an example in a
- 42:08second, meaning that the system, some languages are
- 42:11better than others on it, but it will try and help you catch
- 42:15some things that are not semantically correct
- 42:20statically.
- 42:21In the case of Python, it does that I think all at run time.
- 42:23I'm looking to you again, John, I think there's no
- 42:26pre-time checks.
- 42:27Its-- sorry?
- 42:27PROFESSOR JOHN GUTTAG: [UNINTELLIGIBLE]
- 42:28PROFESSOR ERIC GRIMSON: There is some.
- 42:31OK.
- 42:32Most of them, I think though, are primarily caught at run
- 42:35time, and that's a little bit of a pain because you don't
- 42:36see it until you go and run the code, and there are some,
- 42:38actually we're going to see an example I think in a second
- 42:40where you find it, but you do get some help there.
- 42:43The problem is, things that you catch here are actually
- 42:47the least worrisome bugs.
- 42:49They're easy to spot, you can't run the program with
- 42:52them there, so you're not going to get weird answers.
- 42:55Not everything is going to get caught in
- 42:58static semantics checking.
- 42:59Some things are going to slide through, and
- 43:00that's actually a bother.
- 43:03It's a problem.
- 43:04Because it says, your program will still give you a value,
- 43:07but it may not be what you intended, and you can't always
- 43:10tell, and that may propagate it's way down through a whole
- 43:12bunch of other computations before it causes some
- 43:14catastrophic failure.
- 43:16So actually, the problem with static semantics is you'd like
- 43:19it to catch everything, you don't always get it.
- 43:21Sadly we don't get much help here.
- 43:23Which is where we'd like it.
- 43:25But that's part of your job.
- 43:27OK.
- 43:27What happens if you actually have something that's both
- 43:30syntactically correct, and appears to have correct static
- 43:32semantics, and you run it?
- 43:33It could run and give you the right answer, it could crash,
- 43:37it could loop forever, it could run and apparently give
- 43:43you the right answer.
- 43:45And you're not always going to be able to tell.
- 43:47Well, you'll know when it crashes, that doesn't help you
- 43:49very much, but you can't always tell whether
- 43:51something's stuck in an infinite loop or whether it's
- 43:52simply taking a long time to compute.
- 43:54You'd love to have a system that spots that for you, but
- 43:57it's not possible.
- 43:58And so to deal with this last one, you
- 44:00need to develop style.
- 44:02All right?
- 44:06Meaning, we're going to try to help you with how to develop
- 44:09good programming style, but you need to write in a way in
- 44:12which it is going to be easy for you to spot the places
- 44:15that cause those semantic bugs to occur.
- 44:19All right.
- 44:20If that sounds like a really long preamble, it is.
- 44:23Let's start with Python.
- 44:24But again, my goal here is to let you see what computation's
- 44:28about, why we need to do it, I'm going to remind you one
- 44:30last time, our goal is to be able to have a set of
- 44:32primitives that we combine into complex expressions,
- 44:35which we can then abstract to treat as primitives, and we
- 44:38want to use that sequence of instructions in this flow of
- 44:43control computing, in order to deduce new information.
- 44:47That imperative knowledge that we talked about right there.
- 44:50So I'm going to start today, we have about five or ten
- 44:52minutes left, I think, in order-- sorry, five minutes
- 44:54left-- in order to do this with some beginnings of
- 44:56Python, and we're going to pick this up obviously, next
- 44:58time, so; simple parts of Python.
- 45:02In order to create any kinds of expressions, we're going to
- 45:04need values.
- 45:06Primitive data elements.
- 45:07And in Python, we have two to start with; we have numbers,
- 45:13and we have strings.
- 45:16Numbers is what you'd expect.
- 45:18There's a number.
- 45:21There's another number.
- 45:21All right?
- 45:24Strings are captured in Python with an open quote and some
- 45:28sequence of characters followed by a closed quote.
- 45:33Associated with every data type in Python is a type,
- 45:37which identifies the kind of thing it is.
- 45:40Some of these are obvious.
- 45:41Strings are just a type on their own.
- 45:44But for numbers, for example, we can have
- 45:46a variety of types.
- 45:47So this is something that we would call an
- 45:49integer, or an INT.
- 45:50And this is something we would call a
- 45:54floating point, or a float.
- 45:57Or if you want to think of it as a real number.
- 45:59And there's some others that we can see.
- 46:01We're going to build up this taxonomy if you like, but the
- 46:04reason it's relevant is, associated with each one of
- 46:07those types is a set of operators that expect certain
- 46:11types of input in order to do their job.
- 46:13And given those types of input, will get back output.
- 46:16All right.
- 46:17In order to deal with this, let me show you an example,
- 46:19and I hope that comes up, great.
- 46:21What I have here is a Python shell, and I'm going to just
- 46:25show you some simple examples of how we start building
- 46:27expressions.
- 46:28And this'll lead into what you're going to see next time
- 46:30as well as what you're going to do tomorrow.
- 46:32So.
- 46:33Starting with the shell, I can type in expressions.
- 46:37Actually, let me back up and do this in video.
- 46:38I can type in a number, I get back a number, I can type in a
- 46:42string, I get back the string.
- 46:46Strings, by the way, can have spaces in them, they can have
- 46:49other characters, it's simply a sequence of things, and
- 46:52notice, by the way, that the string five-- sorry, the
- 46:59string's digit five digit two is different
- 47:02than the number 52.
- 47:03The quotes are around them to make that distinction.
- 47:05We're going to see why in a second.
- 47:07What I'm doing, by the way, here is I'm simply typing in
- 47:09expressions to that interpreter.
- 47:11It's using its set of rules to deduce the value and print
- 47:13them back out.
- 47:15Things I might like to do in here is, I might like to do
- 47:17combinations of things with these.
- 47:19So we have associated with simple things, a set of
- 47:23operations.
- 47:27So for numbers, we have the things you'd expect, the
- 47:32arithmetics.
- 47:33And let me show you some examples of that.
- 47:35And actually, I'm going to do one other distinction here.
- 47:38What I typed in, things like-- well, let me start this way--
- 47:42there's an expression.
- 47:44And in Python the expression is, operand, operator,
- 47:48operand, when we're doing simple expressions like this,
- 47:51and if I give it to the interpreter, it gives me back
- 47:53exactly what you'd expect, which is that value.
- 47:56OK?
- 47:57The distinction I'm going to make is, that's an expression.
- 47:59The interpreter is going to get a value for it.
- 48:01When we start building up code, we're
- 48:03going to use commands.
- 48:04Or statements.
- 48:05Which are actually things that take in a value and ask the
- 48:08computer to do something with it.
- 48:09So I can similarly do this, which is going to look strange
- 48:13because it's going to give me the same value back out, but
- 48:16it actually did a slightly different thing.
- 48:17And notice, by the way, when I typed it how print showed up
- 48:19in a different color?
- 48:21That's the Python saying, that is a command, that is a
- 48:24specific command to get the value of the expression and
- 48:26print it back out.
- 48:27When we start writing code, you're going to see that
- 48:29difference, but for now, don't worry about it, I just want to
- 48:31plant that idea.
- 48:33OK.
- 48:33Once we've got that, we can certainly, though,
- 48:35do things like this.
- 48:39Notice the quotes around it.
- 48:42And it treats it as a string, it's simply getting me back
- 48:44the value of that string, 52 times 7, rather than
- 48:47the value of it.
- 48:49Now, once we've got that, we can start doing things.
- 48:52And I'm going to use print here-- if I could type, in
- 48:53order to just to get into that, I can't type, here we
- 48:55go-- in order to get into the habit.
- 48:57I can print out a string.
- 49:00I can print out--
- 49:07Ah!--
- 49:09Here's a first example of something that
- 49:10caught one of my things.
- 49:11This is a static semantic error.
- 49:15So what went on here?
- 49:16I gave it an expression that had an operand in there.
- 49:18It expected arithmetic types.
- 49:21But I gave two strings.
- 49:23And so it's complaining at me, saying, you can't do this.
- 49:26I don't know how to take two strings and
- 49:27multiply them together.
- 49:30Unfortunately-- now John you may disagree with me on this
- 49:32one-- unfortunately in Python you can, however,
- 49:34do things like this.
- 49:37What do you figure that's going to do?
- 49:39Look legal?
- 49:41The string three times the number three?
- 49:45Well it happens to give me three threes in a row.
- 49:49I hate this.
- 49:50I'm sorry, John, I hate this.
- 49:51Because this is overloading that multiplication operator
- 49:55with two different tasks.
- 49:56It's saying, if you give me two numbers, I'll
- 49:57do the right thing.
- 49:58If you give me a number and a string, I'm going to
- 50:00concatenate them together, it's really different
- 50:02operations, but nonetheless, it's what it's going to do.
- 50:05STUDENT: [UNINTELLIGIBLE]
- 50:11PROFESSOR ERIC GRIMSON: There you go.
- 50:12You know, there will be a rebuttal phase a little later
- 50:14on, just like with the political debates, and he
- 50:16likes it as a feature, I don't like it, you can tell he's not
- 50:18a Lisp programmer and I am.
- 50:20All right.
- 50:21I want to do just a couple more quick examples.
- 50:22Here's another one.
- 50:23Ah-ha!
- 50:24Give you an example of a syntax error.
- 50:28Because 52A doesn't make sense.
- 50:31And you might say, wait a minute, isn't that a string,
- 50:32and the answer's no, I didn't say it's a string by putting
- 50:34quotes around it.
- 50:35And notice how the machine responds differently to it.
- 50:38In this case it says, this is a syntax error, and it's
- 50:41actually highlighting where it came from so I can go
- 50:43back and fix it.
- 50:44All right.
- 50:45Let's do a couple of other simple examples.
- 50:48All right?
- 50:49I can do multiplication.
- 50:50I've already seen that.
- 50:51I can do addition.
- 50:52Three plus five.
- 50:54I can take something to a power, double star, just take
- 50:58three to the fifth power.
- 50:59I can do division, right?
- 51:03Whoa.
- 51:04Right?
- 51:05Three divided by five is zero?
- 51:08Maybe in Bush econom-- no, I'm not going to do any political
- 51:10comments today, I will not say that, all right?
- 51:12What happened?
- 51:14Well, this is one of the places where
- 51:15you have to be careful.
- 51:16It's doing integer division.
- 51:19So, three divided by five is zero, with a
- 51:22remainder of three.
- 51:23So this is the correct answer.
- 51:24If I wanted to get full, real division, I should make one of
- 51:28them a float.
- 51:30And yes, you can look at that and say, well is that right?
- 51:32Well, up to some level of accuracy, yeah, that's .6 is
- 51:35what I'd like to get out.
- 51:36All right.
- 51:38I can do other things.
- 51:40In a particular, I have similar operations on strings.
- 51:46OK, I can certainly print out strings, but I can actually
- 51:48add strings together, and just as you saw, I can multiply
- 51:51strings, you can kind of guess what this is going to do.
- 51:53It is going to merge them together into one thing.
- 51:58I want--
- 51:59I know I'm running you slightly over, I want to do
- 52:00one last example, it's, I also want to be able to do, have
- 52:03variables to store things.
- 52:05And to do that, in this it says, if I have a value, I
- 52:11want to keep it around, to do that, I can
- 52:12do things like this.
- 52:20What does that statement do?
- 52:21It says, create a name for a variable-- which I just did
- 52:24there, in fact, let me type it in-- mystring, with an equal
- 52:28sign, which is saying, assign or bind to that name the value
- 52:32of the following expression.
- 52:35As a consequence, I can now refer to
- 52:37that just by its name.
- 52:39If I get the value of mystring, there it is, or if I
- 52:43say, take mystring and add to it the string, mylastname, and
- 52:49print it back out.
- 52:51So this is the first start of this.
- 52:53What have we done?
- 52:54We've got values, numbers and strings.
- 52:57We have operations to associate with them.
- 52:59I just threw a couple up here.
- 53:00You're going to get a chance to explore them, and you'll
- 53:02see not only are there the standard numerics for strings,
- 53:04there are things like length or plus or other things you
- 53:06can do with them.
- 53:08And once I have values, I want to get a hold of them so I can
- 53:10give them names.
- 53:11And that's what I just did when I bound that.
- 53:12I said, use the name mystring to be bound to or have the
- 53:16value of Eric, so I can refer to it anywhere else that I
- 53:19want to use it.
- 53:20And I apologize for taking you over, we'll come back to this
- 53:23next time, please go to the website to sign up for
- 53:25recitation for tomorrow.
About this transcript
This page contains the full transcript of Lec 1 | MIT 6.00 Introduction to Computer Science and Programming, Fall 2008 by MIT OpenCourseWare, generated from the public captions YouTube serves with the video. The transcript has 9,783 words across 1,271 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.