< Return to Video

Lec 1 | MIT 6.00 Introduction to Computer Science and Programming, Fall 2008

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

Lec 1 | MIT 6.00 Introducción a la Informática y Programación, Otoño 2008

more » « less
Video Language:
English
Duration:
53:30

Spanish subtitles

Revisions