Thursday, October 13, 2016

Abstraction by Professor David J. Malan

my name is David Malan and i teach a course called cs50 which is our
introductory course in computer science for concentrators and non concentrators
alike and it's of course I myself took albeit not initially sometime ago indeed
when I arrived on campus here I wasn't sure what I wanted a study in fact that
course catalog itself was completely daunting in so many new fields and so I
frankly rather gravitated naturally toward what I already knew I thought
back on high school and I liked history a bit and i really like this
constitutional law class and so when I was slipping through the catalog I
realized well maybe government is what I should concentrate in and i still had
this this curiosity about computer science but then and now to some extent
it was very much this discourse and more generally this field to to be where I
just kind of figured that everyone who's taking the introductory course cs50
surely have been programming or taking computer science they were 12 years old
I remember looking through the glass of the window of the computer science
classroom in my high school and not really knowing or caring what like my
own friends were doing in there just seems so foreign and so unfamiliar to me
it wasn't until sophomore year that i finally got up the nerve to put my toe
in the water and even then it was only by enrolling in the class pass/fail lest
i fail the class or or get a be in the class it was my way of getting up the
nerve to try what was a very unfamiliar field and what I realized immediately is
that even though i had this perception from high school especially the computer
science is programming and writing code and sort of heads down typing away on
the keyboard it's actually much more than that it really is about ideas and
it's about problem solving and in fact is about using techniques and using
ideas that were actually pretty familiar to me already
in fact the idea one such idea that I'd like to propose is just this today just
one of several ideas that of abstraction and abstraction is a fancy way of saying
taking something that's really complex and sort of taking a step back and
packaging it up in a way that simpler and that from the top down you could
just understand for instance I to this day have absolutely no idea how a car
works or underneath the hood what's inside the engine if something broke
would have no idea how to fix it but I've gotten pretty good at using that
machine and interfacing with this API or application programming interface
whereby get in the chair
and I turned the wheel and the things start turns and I push the pedal down
and I understand that and that's what's key
I've abstract away as have all of us we've abstracted away what a car
actually is to only needing to understand and care about and master its
interface and in fact underneath the hood all of those details can change it
can go from gas to electric at the end of the day other than filling it up
doesn't really matter to me when operating that device
what's going on underneath the hood and consider some other examples for
instance what is a country when we talk about a country well in this country a
country is a collection of states
well what are what the state well as state is a whole bunch of town
well what's the town a town is a whole bunch of houses
what's house so it's like four walls and a roof but what's a wall in a roof well
it's you know previously wood and from a forest or trees that have been turned
into two-by-fours the like
so if you get down to the nitty-gritty you could actually build the thing from
the ground up but we humans generally don't have to care about reconstructing
things from those basics we have the luxury of talking about fairly complex
ideas from the top down in a way that just makes them so much more manageable
and so much understood more understandable now let's consider things
that are a little more technological like in a computer at the end of the day
a computer's only input sources like a power cable or maybe a battery and even
if you don't understand how the computer works
you probably know that there's electricity coming out of that cable
battery so there's like electrons flowing in and out but then today that's
the only input to this device and how can it do so much
how can i write my essays on it and send emails and browse the web and watch
videos and listened to music how do we get to such complexity when the only
input at the end of the day is power or electricity and in fact what's going on
underneath the hood in this case if we can land there just quickly you have all
these little switches inside of a computer transistors as they might be
called millions these days they're just little switches that given some
electricity allow you to turn something on or off on or off and a computer
scientist we typically call on one and we call off 0 and it would seem that our
only vocabulary is zeros and ones but how do we get from zeros and ones to our
emails into images and two videos and music well let's consider just what we
humans no more familiarly
it is like the number 123 this is just a pattern of symbols 123 but why is it 123
think back just a few years to grade school and you might recall that this is
the ones column the tens column and the hundreds column and now how do we get
from these columns to an actual met value we understand well this is what
100 times 1 plus 2 times 10 plus 1 times 3 which of course is 100 plus 20 plus 3
ah there's my 123
well turns out the computers aren't as fancy as we humans we have 0 and nine at
our disposal typically so-called Decimal System computers just have the binary
system by meaning to because they just have zeros and ones often on so in the
world of computers underneath the hood the best we can do is not having powers
of ten up there up top 110 hundred thousand but rather the ones column the
tools column the force column on up in other words we can only use powers of 2
in this case so how in this world my represents the number we humans know a 0
a computer underneath the hood just turns off three switches so it off 000
this then is 0
how do we represent using a pattern of switches or lights the number where
humans would no is one again even if you're unfamiliar with computing and
binary the end of the day you just need those columns so what's the pattern
something something something will give me the number we humans know as one
what's that pattern 001 it's really as simple as that
well how about the number we humans know as to how instead we write this not just
001 but rather 010 and if i want to count up further I can do 011 which now
gives me three so that's it that's binary now we've gone from this low
level input just electricity flowing in and out of the device to being able to
represent numbers and in fact if I just keep adding more zeros and ones to the
left just like you can make decimal numbers bigger i can represent any
number i might want but how do you represent an email then how do you send
for instance the message hi ! or draw something like a flower on the screen
is an image that you might see on facebook or the like well how can we
decompose this well you know what why don't we just decide and society that
this pattern of zeros and ones is just going to represent three numbers in fact
I could do up the math the ones place to his place for his place 8 16 32 and so
I can convert those if i did a little quick math into these decimal values
which is a little more manageable in my mind 72 73 33
well it turns out that humanity just decided some time ago that this number
72 in the context of an email or Microsoft Word of the light just going
to be known as representing the letter H followed by followed by ! an arbitrary
mapping but one we humans all agreed upon some time ago
meanwhile if i take the same pattern of bit and think of it in the context of
like the web browser or adobe photoshop or something like that
now these patterns of bits just by nature of the software I'm using can be
considered in a different context so yes it's still the numbers 72 73 and 33 but
what this really means in the context of graphics software is give me a little
bit of red a little bit of green and a little less blue again 72 73 and then 33
and this is an RGB triple red-green-blue if you've ever heard the expression RGB
combine those three colors together and you get this sort of very very murky
yellow-brown that just barely shows up on the screen here but now henceforth i
do not care how murky yellow is implemented you really can't see it I do
not care how the word high is represented I just want to get real work
done and send an email and I've abstract away those low level implementation
details so to speak such that i know the computer can do it but I just don't need
to care now I can function at a higher level so to speak so from there we have
unfortunately a realization that abstraction is really really useful and
it's kind of hard to operate without it and in fact if you can't take for
granted what something is but instead have to consider lower-level how to make
it you realize a challenge in fact that i invite one brave prefrosh to come on
up on stage and appear before all of his or her
potential classmates you have to be comfortable appearing on cameras and
therefore the internet but if that hasn't set to har I of a bar anyone but
there's like three hands in this audience total 456
now this is a little litmus test ok IC bouncing in one ctor that works come on
down and meanwhile
meanwhile if those of you still seated can pick up that white sheet of paper
that has been sitting near you and if you have not received one tear someone's
in half next to you and grab pencil we gave you or something else
what is your name this is Catherine Catherine this is your future classmates
come on over here and what i have for Catherine here is the following in just
a couple of moments time i'm going to show Catherine a picture and Catherine
your charge is not to tell everyone what to draw but how to draw it in other
words if you in the audience cannot take for granted what this higher level
object is we're gonna find that it's quite hard to function without
abstraction so if you would into this microphone described for the audience
exactly how they should draw what only you see there that is the only role you
should not say what it is just how to draw it they have a pencil and a sheet
of paper to which they can apply that pencil
okay step one alright so you have to keep in mind that all of the lines will
be equally spaced apart arm so first you should draw a why in the center of your
ok and then from your right hand side from that are from the end of the top
right-hand side of your why draw a straight line down towards your belly
button not diagonal straight line make sure it's parallel to the paper arm do
the same to the other side so that the entire drawing is symmetrical and then
arm from the bottom of your why draw a line parallel to ok so when you first
started out with the why you'd you have three lines right so there's one on the
Oh No
okay no okay i hope no one saw that
ok so you have one on the top right hand corner and one on the top left hand
corner so you want to connect the lines from that you drew a parallel to your
belly button to the bottom of the why can you guys do that I feel like the
slip is it that you've this is that is what terrifying
yes it is now click ok so give them another instruction or two and then i'll
collect some of the answers and we'll see how close we just got okay and then
so you guys all know what the roof of the house looks like it's like a
triangle so give your wife a roof of that house so that the Y looks like a
square coming a little less abstract now but and how about two more instructions
to get them to the end I me I don't know what wouldn't people then let me do this
let me get you off the hook here it's actually a wonderful reinforcement of
the message which is that life is hard without abstraction but let me out round
of applause for Catherine here let me come out and play and real fast if I
could just steal a few of the incarnations of these drawings 120 come
down here real sorry 3456 that'll do it let's see just how close we came then to
what catherine was encouraging you to draw and I'll do so by swinging into
video mode here so we have one such drawing
alright so we have one such draw all of them actually look pretty similar
so a little something like that this one too pretty similar missing something on
the bottom and this one here and actually amazingly whether by sheer
application of those commands or a little bit of a flip of the paper there
we have what was indeed before Catherine which was this image here which might
jump off might jump off the page into as of course
hey draw a cube but when you don't have that higher level abstraction and
actually need to do it from the ground up
that's why this idea of abstraction is just so key and this then is just one of
the ideas that you would learn in the world of computer science and just one
of the ideas that you would learn at the coming fall starts and allow me to
conclude here with a look at some of the other ideas and experience that awaits
you in a course called cs50
is cs50 harvard university's introduction to the intellectual
enterprises of computer science and the arts of programming
if you walked in here today and see hundreds of people crowded around their
laptops smiling laughing thinking
that time