< Return to Video

Introduction to Computing Principles (19 mins)

  • 0:00 - 0:06
    Hi there, my name is Nick Parlante, and
    this is the class that explores the basic
  • 0:06 - 0:11
    qualities of computers. How they work,
    what they can and cannot do. And it
  • 0:11 - 0:17
    requires no computer background at all.
    It's just geared for anyone. So before I
  • 0:17 - 0:22
    get started, I'd like to, take a moment
    to, thank Google for supporting my early
  • 0:22 - 0:26
    research, into this topic, which
    ultimately helped make this class. Also a
  • 0:26 - 0:31
    quick format note, This class is not just
    made of videos. For each video section,
  • 0:31 - 0:36
    there's sorta this written document which
    I'm, I'm scrolling through here, that,
  • 0:36 - 0:40
    parallels the explanations and has
    diagrams, and code examples, and stuff in
  • 0:40 - 0:45
    it. So, really at any time, you can switch
    between the video and the document if
  • 0:45 - 0:50
    you'd like to reread an explanation or try
    one of the examples or something. There's
  • 0:50 - 0:56
    a big difference between watching me do
    something and then trying it yourself. So
  • 0:56 - 1:00
    my advice would be. A lot of times, at the
    end of a section, we'll have some
  • 1:00 - 1:03
    exercises. And so, at that time, before
    you try the exercises, you could decide,
  • 1:03 - 1:07
    well, are you ready to just jump into the
    exercises, or would you like to go back to
  • 1:07 - 1:10
    the document and try some
    of the experiments yourself to sort of
  • 1:10 - 1:14
    cement the knowledge? So, you should at
    least know that that's available, for each
  • 1:14 - 1:21
    one of these sections. So I will say that
    the, the fundamental equation of computers
  • 1:21 - 1:27
    is computer equals powerful plus stupid.
    Powerful in the sense that computers can
  • 1:27 - 1:32
    do just billions of operations. They work
    just inconceivable fast. But, the
  • 1:32 - 1:38
    operations are stupid in the sense that
    the operations that the computer can do
  • 1:38 - 1:43
    are just very simple, they're totally
    mechanical. They don't have anything that
  • 1:43 - 1:48
    you would describe as human insight about
    what they're working on. So this weird
  • 1:48 - 1:52
    combination of, sort of, great power
    combined with sort of a mechanical
  • 1:52 - 1:57
    stupidity. That pattern will come through
    very clearly, as we work on these little,
  • 1:57 - 2:02
    code examples, to sort of play around in
    the, in the computer world. Now, I'm being
  • 2:02 - 2:07
    a little provocative, sort of making fun
    of the computer. Oh, they're so stupid,
  • 2:07 - 2:11
    and, but on the other hand, we see that
    computers are, they're very useful. So, in
  • 2:11 - 2:16
    a way, that's what this class is
    about. On the one hand visiting this kind
  • 2:16 - 2:21
    of funny computer world that's sort of
    mechanical, and then connecting it to the
  • 2:21 - 2:26
    way, you know things like email, and MP3
    audio. Things that in the real world that
  • 2:26 - 2:31
    are very useful. Trying to sort of connect
    those two worlds, and show you how the
  • 2:31 - 2:35
    computer works, and how it fits into the
    world. My goal is that, coming out of the
  • 2:35 - 2:40
    class, you understand how computers work
    and how they fit into the world. And
  • 2:40 - 2:44
    in a way, you're not intimidated by the
    computer. You don't think of it as some
  • 2:44 - 2:50
    magic, inconceivable box. Also I have a
    hidden agenda. There are too few computer
  • 2:50 - 2:55
    science people in the world. There are
    many problems that we would like to be
  • 2:55 - 3:00
    solved, but there just aren't enough
    people out there to program them all. So
  • 3:00 - 3:05
    my hidden agenda is that by opening your
    eyes to the computer world and how it
  • 3:05 - 3:10
    works for some of you, you may find that
    you're interested in pursuing computer
  • 3:10 - 3:15
    science in the future. So, first
    approximation I'm gonna look at; How does
  • 3:15 - 3:19
    a computer work? So inside the computer is
    really driven by code. And we're, we'll
  • 3:19 - 3:24
    get into a lot more detail on this later.
    This will just be our first look. So here
  • 3:24 - 3:29
    I've made a little picture of a
    computer. And code inside the computer is
  • 3:29 - 3:34
    made of these simple instructions. So one
    instruction might be to add two numbers,
  • 3:34 - 3:39
    you know, compute what one plus one is or
    check if two is less than ten. So what the
  • 3:39 - 3:44
    computer does, for this first look, is it
    just runs down this list of
  • 3:44 - 3:49
    instructions. Each instruction is very
    simple and the computer is just running
  • 3:49 - 3:54
    down the list doing them, albeit it's
    doing them very quickly. But each
  • 3:54 - 3:59
    instruction has this very mechanical kind
    of fixed feeling. So, I'm gonna say this,
  • 3:59 - 4:04
    I think this leads to a natural question.
    Which is, well; If the, if the computer is
  • 4:04 - 4:09
    so mechanical just running through the
    instructions, how is it that there are so
  • 4:09 - 4:14
    many useful features in the world? So,
    I've got this diagram for that case. So,
  • 4:14 - 4:19
    on the right hand side I'm going to
    imagine some useful features. Like,
  • 4:19 - 4:24
    red-eye reduction, or instant messaging. And,
    I'm gonna say for this discussion, you
  • 4:24 - 4:29
    know, your phone, your digital camera,
    those are all computers. So on the right
  • 4:29 - 4:33
    hand side, I've got the useful feature,
    red-eye reduction. And on the left hand
  • 4:33 - 4:38
    side, I've got the computer, which is just
    going through its, you know, simple
  • 4:38 - 4:42
    mechanical instructions. So what
    connects these two views? And the answer
  • 4:42 - 4:47
    is that really, that's what computer
    programming is. There's a person, a
  • 4:47 - 4:51
    computer programmer, who at first they
    have an idea. Oh, we should have red-eye
  • 4:51 - 4:56
    reduction, that would be really useful.
    And so they use their creativity and their
  • 4:56 - 5:00
    imagination to think of what would be
    something useful to have the computer
  • 5:00 - 5:05
    could do. And then what the computer
    programmer does, is really they structure
  • 5:05 - 5:09
    and break down that problem, so that the
    computer can do it. They really instruct,
  • 5:09 - 5:14
    and you know, structure things so
    the computer can actually, do this
  • 5:14 - 5:19
    useful thing. That is what computer
    programming is. And in fact, any useful
  • 5:19 - 5:24
    thing that you've done with your digital
    camera, or your cell phone, or your
  • 5:24 - 5:30
    computer, really behind the scenes, there
    was a person that was making that happen.
  • 5:30 - 5:35
    And I kinda like this combination. In a
    way, the programmer, the person,
  • 5:35 - 5:41
    brings their creativity and insight about
    the world and thinking of stuff that would
  • 5:41 - 5:46
    be useful to have done, and that's
    their half of the problem. And the computer
  • 5:46 - 5:50
    brings what the computer's good at. And I
    would say the computer is good at being
  • 5:50 - 5:55
    ultimately pretty inexpensive. And the
    computer is able to do these instructions
  • 5:55 - 5:59
    very, very quickly and so, we get, you
    know, ultimately we get this nice
  • 5:59 - 6:03
    combination. And in a way that's why there are so many computers in
  • 6:03 - 6:08
    the world doing so many useful things. It
    shows this is this is a good partnership
  • 6:10 - 6:12
    between people and computers. In a way
    this diagram also is a little bit of a
  • 6:12 - 6:17
    summary of this class. We're going to
    visit on the left hand side to see sort of
  • 6:17 - 6:21
    see what the computer world looks like.
    And look at the connection between that
  • 6:21 - 6:26
    and actual features that you've used and sort
    of understand how the computer fits into
  • 6:26 - 6:33
    the world and gets stuff done. So, in the
    second half of this section, I'm gonna
  • 6:33 - 6:37
    start doing little, little coding
    examples. And I should mention, this is
  • 6:37 - 6:42
    gonna require a little bit of patience.
    I'm gonna start doing coding. And our
  • 6:42 - 6:47
    first code examples are going be very
    simple. They are not going to do anything
  • 6:47 - 6:52
    flashy. I'll say it's a little bit like
    LEGO bricks. Each bit of code that we
  • 6:52 - 6:56
    learn is one more brick, and eventually we
    are going to be able to put these things
  • 6:56 - 7:00
    together and make stuff that's pretty
    neat. But these first couple of sections,
  • 7:00 - 7:05
    the things, we got to start somewhere, and
    these first examples are very simple. So I
  • 7:05 - 7:09
    ask you to be patient, I promise we will
    get somewhere neat with this material. Oh,
  • 7:09 - 7:13
    and actually here, I put in a little bit
    of foreshadowing, so actually within a
  • 7:13 - 7:18
    couple of hours of lecturing. We'll start
    doing, visual special effects. And so
  • 7:18 - 7:23
    we'll play around with the famous, shown
    here Monkey Moon Banana problem. So that's
  • 7:23 - 7:28
    just a little foreshadowing of where we're
    gonna get. But for today we're just doing
  • 7:28 - 7:33
    simple bits of coding. So for these code
    exercises, we're gonna be using a computer
  • 7:33 - 7:37
    language called JavaScript. JavaScript is
    a really popular language. It works in
  • 7:37 - 7:41
    web browsers, so that's why it's
    extremely popular. And that's why it's an
  • 7:41 - 7:45
    actual fit for this class. Because it,
    because we're working in the web browser,
  • 7:45 - 7:49
    that means our code can work pretty
    easily. We're gonna use JavaScript plus
  • 7:49 - 7:53
    some extensions that I've added just for
    this class. So this is not gonna look
  • 7:53 - 7:57
    exactly like a professional JavaScript.
    We're gonna work on phrases of code that
  • 7:57 - 8:02
    are ultimately quite short. Just enough to
    sort of get across the points
  • 8:02 - 8:06
    that I want to make and sort of explore computers. But without bringing in a lot of
  • 8:06 - 8:10
    the baggage that would be required for
    writing full, professional programs. All
  • 8:10 - 8:15
    right, so here's my first code example. So
    the way code is going to work for us is
  • 8:15 - 8:19
    we've got this, little rectangular area.
    And this text inside of here,
  • 8:19 - 8:23
    that's code. And then we'll always have a
    run button down here. So when I click the
  • 8:23 - 8:28
    run button. What's gonna happen is, the
    computer goes to the top here and it just
  • 8:28 - 8:32
    runs through these lines. And so it's
    gonna, as we say, it's gonna execute
  • 8:32 - 8:37
    each line. It's gonna do what it says. So
    in this case what we're looking at is the
  • 8:37 - 8:41
    print function. So there's just the word
    print. And the way the print function
  • 8:41 - 8:46
    works is that it has the word print, and
    then there's a left parenthesis. And then
  • 8:46 - 8:50
    there's a series of things. So here, I
    just have the number 6. And then eventually,
  • 8:50 - 8:54
    the line ends with a right parenthesis and
    a semicolon. And what the print function
  • 8:54 - 8:59
    does is it takes the stuff in between the
    parentheses, and it prints it out. And so
  • 8:59 - 9:04
    actually if you look over here on the
    right hand side, this is the output of the
  • 9:04 - 9:10
    when I hit the run button there. So if I
    were to change this to say, print(42). And
  • 9:10 - 9:15
    run it. Then we see here's the 42. So
    that's from this first print line and when
  • 9:15 - 9:21
    I say print(1,2), that's why we
    see the, the one and the two over here. So
  • 9:21 - 9:26
    the way this works. I did say that our
    first examples are very, they're not very
  • 9:26 - 9:32
    flashy. So certainly that's
    true here. So I can try you know, adding a
  • 9:32 - 9:37
    few more things here. So I could say comma
    47. So when I run it, okay, now we see we
  • 9:37 - 9:43
    get the one and the two in the 47. Also,
    just to show that these lines are just
  • 9:43 - 9:49
    taken one time, I'll copy that one,
    and then I can paste it in a few times, I
  • 9:49 - 9:54
    have multiple lines. So if I run it, now
    we can say, alright,
  • 9:54 - 10:00
    just, you know, we just get a, a
    repetition of whatever that output was. So
  • 10:00 - 10:07
    one thing to, to point out about this, is
    that the syntax of this code. Is not at
  • 10:07 - 10:11
    all free form, It's the opposite, It's
    very structured. It has to be just so for
  • 10:11 - 10:16
    the computer to understand it. And that's
    actually a reflection of the inner nature
  • 10:16 - 10:20
    of the computer. That it has this
    mechanical fixed quality and so the
  • 10:20 - 10:25
    language that it can understand is
    also gonna be mechanical and fixed. So
  • 10:25 - 10:30
    this is a little strange, right at first,
    that you can't just start free form just
  • 10:30 - 10:35
    writing English here and just having, the
    computer follow it. So think of this as
  • 10:35 - 10:39
    your first lesson in the nature of
    computers. Or you could think of it as
  • 10:39 - 10:43
    sort of a when in Rome sort of quality.
    It's, like, look, I'm asking you to visit
  • 10:43 - 10:46
    the world of the computer. And so we're
    gonna work a little bit in the language of
  • 10:46 - 10:49
    computers. It's gonna feel a little
    strange right at first. But the reality
  • 10:49 - 10:54
    is. This is not actually hard. The syntax
    is, it may be structure, but it's also
  • 10:54 - 11:00
    pretty simple. And so, I would encourage
    you to, don't be put off by the slightly,
  • 11:00 - 11:05
    structured mechanical quality of this
    language. It will enable us to do
  • 11:05 - 11:10
    some neat stuff. Alright, that's my first
    example, let's try a second example here.
  • 11:10 - 11:16
    So my first example I just did numbers. So
    in computer code there's also a thing
  • 11:16 - 11:22
    called a string. And here's a first
    example of a string here. Hi in quotes so
  • 11:22 - 11:27
    a string is just a sequence of letters and
    in the code it's written between the
  • 11:27 - 11:32
    double quotes. So that's why I have the
    "hi". So print can take in numbers and print
  • 11:32 - 11:37
    them, turns out it can also print strings.
    It just interprets the string as just a
  • 11:37 - 11:41
    sequence of letters and whatever the
    string is it just prints them out over
  • 11:41 - 11:46
    here. So, I could change this, you know,
    it says "hi". I could change it to say, "good
  • 11:46 - 11:51
    day". So the string can have a space on it.
    So if I ran that then we'll just, we'll
  • 11:51 - 11:58
    just get the good day over here. So in a
    computer program, strings and numbers are
  • 11:58 - 12:02
    both very, very common. So a string in a
    computer program might be used to hold
  • 12:02 - 12:07
    like a URL that you just typed or, maybe
    in a word processor each paragraph that
  • 12:07 - 12:11
    you're working on might be stored as a
    string. So the string is basically this,
  • 12:11 - 12:16
    sequence of letters. It's a very common
    sort of data in the computer. Another
  • 12:16 - 12:20
    thing that's shown in this code example is
    this first line here. That's called a
  • 12:20 - 12:25
    comment, and in JavaScript comments begin
    with two slashes, and the way the comment
  • 12:25 - 12:30
    works is, beginning with the two slashes,
    everything to the right on that line the
  • 12:30 - 12:35
    computer ignores. And so I could use that
    to write some remark about, you know, oh,
  • 12:35 - 12:40
    I have two strings here. Some little
    remark or note to myself or something
  • 12:40 - 12:45
    about the code. And so when I run this,
    the computer knows to sort of ignore this
  • 12:45 - 12:50
    part. Oh, that's just commentary. So, in
    some of my examples later on, you'll see
  • 12:50 - 12:55
    comments sprinkled around where I'm, I'm
    making some remark about, what's going on.
  • 12:55 - 13:02
    So one example I could do here that's a
    little tricky. Is, I'm gonna put the word
  • 13:02 - 13:09
    print inside of this string and we'll see
    what that prints. So here and now, the
  • 13:09 - 13:15
    second line, I get hello to print. So
    what's happened is, the word print inside
  • 13:15 - 13:21
    of a string is not treated as code to run
    the way the word print outside, that is a
  • 13:21 - 13:26
    function that the code is called. So when
    it's inside of the double quotes like
  • 13:26 - 13:32
    that, it's just data. So that is a, a
    distinction inside of the code. Well,
  • 13:32 - 13:38
    alrighty. So, I'm gonna, at the end of
    this section, we'll have some exercises
  • 13:38 - 13:44
    where you can write some code as I've done
    here. So as I mentioned before,
  • 13:44 - 13:50
    the code works within the system of being
    a very structured limited syntax. And it's
  • 13:50 - 13:55
    actually a very common error, even a, you
    know, a professional programmer who
  • 13:55 - 13:59
    writes code all day long. When they're
    typing in some code, there will tend to be
  • 13:59 - 14:04
    little syntax errors, sprinkled through
    the code. Oh, maybe a right parenthesis
  • 14:04 - 14:09
    is missing or there's a typo in one of the
    words. And, those syntax errors are very
  • 14:09 - 14:14
    easy to fix. And so it means that when
    you first hit that run button,
  • 14:14 - 14:19
    it is very common that there'll be some
    little typo that has to be fixed. And I
  • 14:19 - 14:23
    want you to understand that. Those little
    errors do not reflect some deep
  • 14:23 - 14:27
    misunderstanding on your part or some flaw,
    those are just superficial little errors
  • 14:27 - 14:32
    that happen in coding all the time. And
    professional programmers make those all
  • 14:32 - 14:37
    the time, and we just think nothing
    of fixing those. We, we don't even think
  • 14:39 - 14:41
    about it anymore. And so, I think that, when
    people are first introduced to coding,
  • 14:41 - 14:46
    this is something that derails them a
    little bit, that there are these little
  • 14:46 - 14:50
    syntax errors and it kinda, it puts them
    off their game and they think they're doing something terribly wrong when in fact, everyone
  • 14:50 - 14:55
    makes those errors. It's absolutely no big
    deal. So. To help, diffuse that problem a
  • 14:55 - 14:58
    little bit, I just wanna go through a
    bunch of examples where I've... So, I've
  • 14:58 - 15:02
    set up some examples here, where I just
    have typical little syntax errors. And I
  • 15:02 - 15:05
    wanna show you what the error looks like
    when you hit the run button. Right? So
  • 15:05 - 15:09
    what's gonna happen is, when I hit the run
    button, it's not gonna work. I'm gonna get
  • 15:09 - 15:12
    some kinda little error. And so I wanna
    show you the process of going from the
  • 15:12 - 15:16
    error and fixing the little syntax
    problem, just so you're a little bit accustomed. Like,
  • 15:16 - 15:19
    oh yeah, when you first hit the run
    button, that's a very common thing that's
  • 15:19 - 15:23
    gonna happen. So, let's just go through
    these. Alright, so I, I hit the run
  • 15:23 - 15:26
    button. And, you know, instead of running
    and producing output, I got a little bit
  • 15:26 - 15:30
    of an error over here, a little error
    message. Sometimes the error messages are
  • 15:30 - 15:34
    pretty good, describing what's going on.
    So, let's read this first one, It says,
  • 15:34 - 15:39
    Error: prlnt is not defined. So,
    what's going on here, is print is a
  • 15:39 - 15:44
    function, But this second one here, line
    two, and the, actually in this case it,
  • 15:44 - 15:50
    well, this won't always work, but a lot of
    times it'll highlight the line that has
  • 15:50 - 15:56
    the problem. The problem is that it's a
    typo. It doesn't say P R I N T, it says P R L N T.
  • 15:56 - 16:01
    So if I change that to an i. Ha!
    Now it works. So, this little program just
  • 16:01 - 16:05
    prints A, one and a B, a two and a C and a
    three, so it's just a little pointless
  • 16:05 - 16:09
    example I made up. Now of course, I did L,
    because I was trying to think of a what's
  • 16:09 - 16:13
    a letter that looks like an I. You would
    have to come look carefully, so I was
  • 16:13 - 16:17
    being a mean professor there. Alright,
    let's try another one of these. So I'll
  • 16:17 - 16:22
    hit the run button on this one. It says
    error, unterminated string literal, and it
  • 16:22 - 16:26
    highlights the second line. So I'm just
    gonna look at the second line from left to
  • 16:26 - 16:31
    right. You see the one, and there's the B,
    So you see, the problem here is that this
  • 16:31 - 16:36
    is a string. Our intention was the string
    B, but the closing quote is missing. You
  • 16:36 - 16:41
    need both quotes. I'll try the third one here. Let's
  • 16:41 - 16:45
    see, error, missing right parenthesis. So
    again, it's highlighting the line. So I'm
  • 16:45 - 16:49
    gonna, actually, so in this case, the
    error message is actually
  • 16:49 - 16:54
    pretty good. It's just saying, hey, look.
    As with the quotes, the left parenthesis
  • 16:54 - 16:58
    and the right parenthesis, they need to
    match. Like there must be a right
  • 16:58 - 17:03
    parenthesis there, exactly there for the
    print command. So now that one works.
  • 17:03 - 17:12
    Alright, here's the last one. Something
    wrong, it says error, missing right parenthesis, but I looked and the right parenthesis is there. but it happen to this case
  • 17:12 - 17:16
    the error message is just wrong.
    Sometimes, when there's a syntax error,
  • 17:16 - 17:21
    the computer, it just becomes confused and
    it cannot diagnose for you in the error
  • 17:21 - 17:25
    message, it can basically just say, well,
    something's wrong in line two here. So I
  • 17:25 - 17:30
    recommend just looking carefully from left
    to right and look here, it looks
  • 17:30 - 17:34
    pretty reasonable. It happens, in this
    case what's missing, is the comma. And I
  • 17:34 - 17:39
    think that's an example of maybe the
    difference between computers and humans. A
  • 17:39 - 17:43
    human could look at that and see your
    intent. Like, oh, I see the intention here
  • 17:43 - 17:47
    was to print a one and then a B. But the
    computer with this mechanical quality,
  • 17:47 - 17:52
    it's like. Things have to be just as
    they're supposed to and so the comma is
  • 17:52 - 17:57
    not optional there must be a comma there
    and so we're stuck until we fix it. All
  • 17:57 - 18:03
    right. Now that one works. Okay. So that's
    our first section of just basic print
  • 18:03 - 18:09
    with, numbers and strings. I've got one
    example problem here that I'll try. So this is
  • 18:09 - 18:14
    what the exercises will look like a lot of
    times. Although the later exercises will
  • 18:14 - 18:18
    be more fun, I do promise that. So it
    says, change the code below so that when
  • 18:18 - 18:23
    run it produces exactly this output. So it
    says one, two, buckle, so this is based on
  • 18:23 - 18:26
    the, one, two, buckle my shoe. So this
    code, there, there's a code here that does
  • 18:26 - 18:30
    something, but it's just not, not the
    right thing so we're supposed to change
  • 18:30 - 18:33
    it. Let's see. For one, so what I'm gonna
    do is I'm gonna add a two, and then I
  • 18:33 - 18:37
    gotta remember to put in the comma, and
    then I'll change this string to be a
  • 18:37 - 18:41
    buckle. Now I can just run it, just see
    what that does. I'd encourage you to, you
  • 18:41 - 18:44
    know, if you have some idea of the code,
    or you just wanna try something, you know,
  • 18:44 - 18:48
    you're never gonna break anything by just
    typing something in here and hitting the
  • 18:48 - 18:52
    wrong button. So, it's good to have a feeling of experimentation. So,
  • 18:52 - 18:59
    there's the first line. And I'll check the
    second line. So three comma, four comma,
  • 18:59 - 19:07
    knock. Alright, oh, right, now that works.
    So often times when I do a little examples
  • 19:07 - 19:13
    in a document like this It might be that
    in the video, I'll do a bunch of
  • 19:13 - 19:17
    examples and then you may wanna go try,
    you know, be, you'll be curious about the
  • 19:17 - 19:21
    second one. And so you wanna go visit that
    one and try some variant and hit the wrong
  • 19:21 - 19:24
    button yourself, that is absolutely
    something you're, you're free to do. Often
  • 19:24 - 19:27
    times, in the document, I'll have the
    little show solution button. So, that
  • 19:27 - 19:31
    means, that you can go visit it and it's
    blank, so you could do your experiment.
  • 19:31 - 19:35
    But if then if you're curious what the
    code was that I used, then that's also
  • 19:35 - 19:38
    available in the document so you can
    compare it to your solution. Or if you
  • 19:38 - 19:42
    wanna copy out of it, or whatever, that's
    fine. Okay. So, that finishes our first
  • 19:42 - 19:45
    section, so check out those coding
    exercises.
Title:
Introduction to Computing Principles (19 mins)
Video Language:
English

English subtitles

Revisions