Thursday, October 13, 2016

Computer Science 10 - Lecture 1: Abstraction

he right to know
thing I no I'm Jane Garcia and I'm delighted to be cocky
this course this semester on this is a brand new course
she probably knew I from Lakeside answer from other
PR I'm if you are here because up there have to put in the newspaper
came it later turned had newspaper had
didn't work right I know and for so
well I'm serious 10 there are looking you're welcome who saw the ad in that
case in the daily cap
okay well to okay okay
I so the tunnel the course the beauty and your computing
and this is a brand new court
a year ago we hot to university this course
its kinda pilot offering to see it if scratch the language you using
and BYOB the extension could hold up the University
pounding on and it did held up wonderfully so we decided
let's go 446 span the language makeup or your course in fact replacing the other
introduction his course yes 3l
titled and Russia symbolic from symbolic programming
so see Austria was gone never going to be
hot another I we're really excited about gonna be computer science
sharing the love and the joy and beauty enjoy up
computing with not majors and review actually the
push to make this the course that everyone takes coming through we're
really excited about that
just some context this course was chosen as one
5 national pilots for the new advanced placement course on computing called
apcs principles and that's really exciting
if you watched it the website CS Principles .org
Dorell Wright after this arm is a place to describe that project and we are
one university example a course that make and model
back at the high school level at ten thousand new high schools to brand new
course in high school so they're trying to expand 10,000
high schools and that's really exciting that our course might be a model for
really a fun thing wattages again next semester that hopefully every semester
after that so really
very happy about this we've got two outstanding teaching assistants
republish introduce
are so you can seven churches selves into the camera can get over to
with the folks are go ahead tell us
when rices are you doing first for your study up
group alright I
well growth sir Brian just tell you more about the
doubt so I we have if you look at our website we've got so many wonderful
happy faces to help you with read with regard to readers
and lab assistant we've got so many excited people about this course this
course is really got a lot of energy
and the CSI really happy about that brought a more details have covered the
course being
computing and have programming ap have the
talking about the social impact computing history and happen learning to
program this wonderful language right to play more
but that just one last yr the AP we're gonna be I'm poking prodding you cuz i
really wanna know
whether this coursework right comparing this course five other courses across
the country
to be having some surveys before and after was to work with them
to figure out the exact details the servo more service that
probably surveyed more than other alright
solid device is priced lecture but I gotta kinda sharing the lectures are
also gonna be having some guest speakers
outstanding faculty from across campus and maybe even supposed ministry coming
back and telling us
how their particular technology works yet where we already have
Twitter coming to talk to us that's really exciting maybe some other folks
I for Minister coming as well so to me really thanks mister and went back to
okay so as you can tell dan is in charge of joy so that makes me the beautiful
up I'm Ryan r-wi
I'm I am interested
in the use of computers in teaching kids
younger than you that sorry makefield I'm and
I so I had a lot to do with the development a
BYOB which is the extension to
scratch they're going to be using scratch in a language whose
this is scratch before people
okay scratches a computer programming language designed for kids
I'm so it was designed to be really really easy to get started in
which is why we thought it would be good for non-computer science majors
I'm but because scratch is designed for kids there are some things that he
didn't do
and I so some other schools who have courses like this
I'm use scratch for like the first week or two
and then switched to some real language I'm
which is a kind of bait and switch it back I'm
and we wanted instead to extend scratch that I could actually do the whole
curriculum in
that's what we've done and I'm really excited about it um
okay okay so is dan said
um there's the practical half for the course which you do in lab
learning to program computers and then there's the big ideas
I component are which involves the lectures and the discussion see or spend
some time sitting around in a small group
i'm talking about things I'm I really do talk in the discussions by the way are
also kinda defeats the purpose
don't leave it all up to the tast carry the ball I'm
right so one other reasons for this
all-new courses we want you to understand that there is more to
computer science
then just had a red a computer program home
it's true that there's a lot of programming in the curriculum but there
are other things to do
and we want to give you a broader introduction om
to it cell are so we're going to talk about
on San aspects is social context of computing and also some other
theoretical computer science ideas about
measuring how good a an algorithm is a process for computing something or other
arm summer the limits of computation
our summer the history of computer science for example in a few weeks
you're going to learn how one of the first ever computer scientists
more or less single-handedly won world war two after the good guys
I'm by breaking
secret German code and getting patient
allies about the Germans were up to without that
we would have probably lost the war so this week's big ideas abstraction
pounds is probably the central idea of computer science
arm so it's worth talking about and
on I also teach 61a which is our first course
for CS majors Tom that assume some programming background sir
so into actually there's a question how many people are as if now planning to
take 61a
and spring are a lot of great okay so you get to see me again
I'm and you will hear me say computer programming is really easy Klein and
yeah I'm computer programming is really easy
as long as the program your writing is small
so the world is full of 12 year old computer programmers and and they do
interesting work
on but not great big programs or industrial strength
you know can write characters from right to left for Chinese people
stuff like that programs from
when you write big programs what's hard is controlling complexity
an abstraction is about controlling complexity and I know that
that's a lot of big words you have no idea what I'm talking about but bear
with me
and you will arm so the solution to the problem of complexity
is Chongqing or layering so instead of thinking about your problem
in a TBD little piece its you take something anybody pieces and put them
together and give them a name
and then you can think about your problem enters a bigger pieces you keep
doing that
until you have a very big pieces that I'm you can
can I think about all at once search ranking is one metaphor for abstraction
the other is layering where you start with very low level things and you build
on top of that
higher level things on top of that I love of ass
so the classic example is thinking about
I what's under the hood in a car Oroville
I'm so water cars made out well really if you look carefully
cars are made of nuts and bolts and and metal rods and
little paper gaskets and and
rubber hoses and things like that I'm
each piece of metal by the way is made and Adams
right which are made a electrons and protons and neutrons
which are made of quarks so there's lotsa levels of abstraction
even below the things that you ordinarily think I've
as the basic units like a bolt
I'm cats may do something to but if you're trying to repair a car
are you don't think about it in terms of quantum physics
right the you think about it in high level terms you think about things like
this is the engine this is the alternator this is the transmission
I'm an
thats abstraction okay so taking the
little pieces in the car and grouping them into bigger units
and thinking in terms of the bigger units and there are two reasons that
that helps
one is that there are so many of the bigger unit C you don't get lost
and the other is the bigger units are more meaningful you can say
what the purpose if the transmission yes
right whereas it's hard to say anything interesting about
what's the purpose if this particular bolt
you know inside the car arm
okay so the march of technological progress which has been going on for
you know a couple millennia is at least in part
a march toward greater and greater abstraction
so arguably its abstraction that enables
technological progress in every field it's certainly true about computer
um sustaining with cars
in the earliest days a vote amid bills everybody who drove a car
had to know at least something about how to fix them cuz they broke down all the
time right
and so you couldn't drive an automobile
unless you understood the card a pretty low level love abstraction
and cars got more reliable after a while but you still had to know
some things about how the car worked in order to drive it
in particular the main example I'm thinking I've is
I'm the transmission I mentioned before so
I'm it used to be that there were only manual transmissions not automatic
and so in order to drive a car
you had to think about why the car has different gear ratios and what that's
all about and
low gears for more power and high gear is from where speed
you're cruising speed and all that stuff and you had to know
things about how to shift gears which involves pushing down the clutch in that
there's a lot of complicated timing involved
and in the really old days I'm
are you had to know had a double clutch if you want to be able to downshift
anybody know a double clutching is nobody's heard
right I'm Noack
exactly exactly if you wanted to do what you had to do was
hit the clutch get into neutral rev the engine
it the clutch and get into the lower gear that you want it
I'm otherwise the gears grind you know
as the each other and anyway it was really really hard to drive a car
because you had to think in low level terms about how it worked
me invention the automatic transmission was the main
enabling technology for a really wonderful abstraction that we have today
today basically you want to drive a car there to payrolls
the one on the right mix the car go faster the one on the left makes the car
go slower
and that's all you have to know right arm
an suddenly anybody could drive a car
is really a big deal when that happen now
side comment the widespread use of cars has turned out to be a mixed blessing
because a pollution and global warming and you know having to fight wars in
Iraq to get more oil and things like that
I'm drunk driver yeah there there are reasons
I'm so just like computers
cars are not a completely
wonderful no problems technology they are wonderful
but their problems associated with them and you're gonna learn is course that
the same thing is true about computers
about the use of computers and the social impacts of computers
arm so in fact many historians of science
don't like to use the word progress at all
because they think progress brings in implicitly the idea that every new
technology is completely good
you know I instead they talk about technological change
which is a more neutral and language
I'm so
two pedals that the gas pedal on the brake pedal
are what's called an interface a user interface
there so the means of communication
between a human being and the Machine the car
om so
on the driver's side have this abstraction bar so
an interface is also called an abstraction barrier
it's like a wall and one side or the way you think and I'll a book
well horizontal and once I do you think in high level terms and
down the bottom you think a low level terms about how it works so
above the abstraction barrier the driver just asked to now
right pedal faster left little slower arm
and that is about the behavior of the car what the car does in response to the
person the pedals
now once that interface became standard
that wasn't the end of inventing new technology
so above the abstraction barrier things haven't changed very much
the automatic transmission made a big change in the user interface
there haven't been many changes in the user interface
NEC as significant is that since then but they're being huge changes
on the other side of the abstraction barrier
I'm so original a for example
when you push the gas pedal you were mechanically operating a little lever
that adjusted as valves that control the ratio
a gasoline to air going into this on there is in the engine
so you made the car go faster by
making the fuel/air mixture have more fuel and less air
okay he did a very mechanically by pushing the pedal
that's not true today today when you push the pedal
all it does is I send a signal to a computer
in the computer can sense exactly how far down you push the pedal
and the computer takes that into account
in adjusting the fuel/air mixture but it looks at other things too it looks at
how fast you're going
and what you're you're in and whether you're going up or down on many other
things that
that affect what it what it does and
I'm also the
forming a that fuel air mixture is now done separately for each engine cylinder
so instead of having with that used to be in all cars the carburetor
that's there was 1i have now every engine cylinder has its own fuel
that does this fuel/air mixture attack so they've been huge changes
underneath the extraction barrier but I'm
the engineers who built that new technology
could have for every change in the underlying technology put some lights
and switches
on the dashboard to help you control the technology more finally
but they wisely didn't do that
they didn't change the interface about the abstraction barrier
okay not they changed a lot below the objection very but they tried to make it
said it was still true you push the pedal more a car goes faster
and you didn't have to think about I'm
how that works need the surface
the same thing is true about the brake pedal
used to be originally that
you push the brake pedal and you were mechanically
squeezing the wheels
okay you're operating old had that rubbed against the wheels to slow the
car down you did that with the street if you're for it
from see how to be strong originally drive a car
and now wasn't so good so they invented power brakes
so you push down on the brake pedal your operating
I hydraulic cylinder which is is a machinery
that essentially amplifies the power up your foot
and it's the breaks under that actually squeezes the wheel to stop the car
I'm except that isn't quite true that was true for a while when they first
power brakes I was at work your for it
went through intermediary to get to the
actual breaks and then there were few accidents because people's engine
failed on the road and so
on the hydraulic system stopped working and so they push the brake pedal and
nothing happened
you know they had car crashes so now you know actually have power brakes
when you have his power assisted breaks
in which you push the pedal
and you're doing two things your operating hydraulic cylinder that does
most of the work in stopping the car
but also there's a direct mechanical linkage for me refer to the break
so that you know if your engine dies and I where you can stop the car
arm these days
they have anti-lock brakes which means
between your foot and hydraulic cylinder
there's a computer and that computer
I'm looks at various aspect to have the wheels are turning
to decide if you're about to go into a skid
and if so it overrules you
you're slamming on the brakes and the computer in the car saying no
if I actually operate the breaks that fast this guy's gonna go into a skid
and so it kinda Paul says the brakes in you can feel the AI Craig pushing back
on the pedal I'm and so
again there's a very complicated interface using
various levels of abstraction are
underneath the brake pedal but as far as you're concerned it's still
push the payroll stop the car cap
I'm and the point of all this technology is to make that more true
so that no matter what the road conditions are the purse the parallax
was the car down your pressure
ordered stops the car I'm
and again with the brake system they could have put a lot of lights and
switches on the dashboard
help you control it but they wisely didn't
I'm although a footnote to that
these days there are
automatic transmissions that pretends to be manual transmissions
I'm because young man
like to feel that they're controlling the car
and so they're all these extra widgets that you can
operate if you want to this order
normal mode where the car just drives itself and
pseudo manual mode where you can actually change the gear shift
and make your fuel economy worse and make your
engine performance worse but feel like you're in charge
okay so there too
aspects to abstraction that you have to know about the 1 I've been talking about
up to now mainly is
hiding details see you doing something very very complicated
and you find a way to develop a simpler way of thinking about it where you
sweep allow to details under the rug
arm the other aspect a abstraction is generalizing patterns
arm so I
to illustrate that I wanna talk about the wheels of the car
you know this for other right the front lines in the back ones
and um they're actually different from each other
the front wheels are the ones that steer the car
footnote technology marches on you can now get cars
in which the back wheels also turn a little bit
om and this is opposed to improve your turning circle and help prevent skids
I but mostly the front wheel steer the car
I'm cuz if you think about it he steered from the back
car would go the opposite other way think it's going and
when Rivera I'm depending on what model car you get
the front wheels may also be polling the car providing the power to run the car
or the back wheels might be pushing the car that's our front wheel drive
and rear wheel drive and then there's also four wheel drive where all four
wheels are
car under power I'm so the front wheels in the rear wheels are different from
each other that's the point
but in many ways they're the same
there round there you know for made at a rubber with air inside
I'm and so
as a kind of abstraction I
you is a car driver are allowed to think about it is if the wheels were all the
they make the wheels all look the same and they're all the same size on its
that there have to do they remember those
and where you don't remember but have you seen pictures
a really old bicycles they have a huge rear wheel in a tiny front wheel
I'm but its front wheel out any real
okay whatever yeah Wireless
I'm well
they could done in front wheels and rear wheels have cars
something like that they probably wouldn't do it to such an extreme extent
but it could have turned out
to be a slightly better now engineering
yet to have the Pro is bigger
or something I'm but it's much simpler to have them all the same size
so that's taking things that are almost the same but a little different
and combining them into one
pattern so we can say use this pattern
and then you only have to talk about those details which are different in
different cases
okay so
I you're gonna be working with I'm this
Scratch programming language on the computer and
you wanna dry square so
you could write a program to draw a square that's an inch
by an inch and then you could write a separate program to draw a square that's
two inches by two inches
and so on I'm but the other thing to do
is driver write a program that says draw square
and when I use this program a given an input saying how big it should be
aka so it's they're having a lot a separate programs to do a different
kinds is great
we just have one program to draw any square thats
also abstraction arm and it's the kind of abstraction that's about generalizing
a cautionary note here abstraction is not the only
concern when you're doing engineering and sometimes I'll see situations which
engineers decide
not to generalize patterns so
my example if that is I'm some cars
I am recently have different size
wiper blades for the 2i provides in the front of the car
I'm so they'll be think this is right
small one on the driver side in a bigger one on the passenger side
typically and to make this work
there's a lot of complicated engineering at the motion of the passenger side 1
so it doesn't just go bloop bloop because ruden
Mike back I'm to it sort of cover more the windshield
really anyway so the cost if that
is when it's time to replace your ways you can just
they give me too 14 in Draper blades right you acted
get this one for the left in this one for the right I'm so it's a little bit
harder to think about
but I'm it cleans the windshield better so that's an engineering trade-off
arm all else being equal
it's better to abstract to find common patterns
arm to find ways
chunking things together and use them but every once in a while
are for some efficiency reason people decide not to do that
from that's a upper division computers and
okay arm
now I may finish early so
how does abstraction work in computer programming
well let me describe scratch a little bit com which you're gonna see I guess
today this afternoon on so
your computer screen an of fun the left
is a menu things that it knows how to do
at right there's a stage which is a little
window where there's I'm a cat
and it doesn't have to be a cat you can change the shape but when you start it
up it's a cat
also named scratch I'm who carries out
the instructions that you say to do like you say I'm
move ten steps and the cats are
jumps ten steps over on the screen and whichever direction it's
facing and there's a turn
demanded changes what direction it's facing but here's this cat
and you see a cat book like that move on the screen
okay well
there isn't really a cat inside your computer
I'm with the is is pixels
an abbreviation for picture element dans the graphics guy said he's gonna tell
you all about that later on
but I'm what looks like a cat is actually a
to pixels have different colors and
were in Intel's what has to happen when you say to move the cat
is we have to erase all those pixels where the cat was
meaning turned into white or whatever this color the screen background is
and then dry a new center pixel someplace else
and that actually happens dot by died
right deep inside I scratch
which is itself a computer program it's a programming language
so that's an abstraction as far as you're concerned
scratches just given and your programming in scratch your taking these
blocks like move
so many steps and linking them together
to make what's called a script om that tells
the cat to do a bunch of different things I'm
and scratch is the underpinning of allowing you to do that programming in
that way
but scratches itself computer program
written in terms of a lower level abstraction
I'm actually happens to be written in a language called small talk
I'm that's pretty obscure otherwise
on better interest you hear a little bit about it and sexy 18
you do that um and small talk
is sort of closer to how the computer hardware works
but still pretty high level and their lower level languages and then finally
at the language the machine actually speaks
so scratch is an abstraction every single thing you do in scratch
involves busily is it abstractions the you don't even have to think about as
far as you're concerned
that's a cat there really is a cat inside the computer
writing you can tell it to do things and I'll do I'm so I guess it really should
have been a dog
because you know cats don't do it it on Twitter but
I'm that impact your know why
okay so if the abstraction is working well
then you don't even think about it as an abstraction so
you know think about all the things you do with computers that have nothing to
do with this class
okay I'm so you run a browser
you're in. Firefox or Safari or chrome or something
any better and Internet Explorer
don't do it bad idea
at a gay bears is on your computer I'm
02 browser an
either you type in your Google that calmer else maybe you click on a
thing at I'm bookmarks toolbar
it says Google and up pops this thing on your screen
it says you know enter your search query here
um well how did that happen you take it for granted but it's hugely complicated
we're going to be talking about client server stuff
later on it's in the dan actually has this on the right side
I'm but not only is a lot a complicated stuff going on on your computer
but all are complicated stuff is going on Google's computers on which there are
a lot
and many many different computers in between so you know
I'm if you do it on campus I
their other computers on campus at berkeley whose job it is
to forward your message from the computer on your desk
on your lap to the outside world
and then I'm we get our
internet from used to be spread the one point might be anyway
let's say it's Brett their computers have to figure out where Google is
try and that's actually a little tricky cuz Google's everywhere
I'm but so there's all this complicated handshaking going on
and all you see is this career pops up in you type something in
are and then it does the search
and you get results more or less instantly right think about how amazing
that is
arm and making that work is layers and layers and layers about traction okay
so thats abstraction in computer programming
on okay so let me tell you
a little bit about BYOB to because that's the silly into the story about
I'm in scratch you can take
a bunch of commands that scratch knows how to do and soda
cook them together there they're kinda cute they're shaped like Lego bricks
you're supposed to think if it is snapping Lego bricks together
I'm sorry they are Birmingham and you can say do this
and does the first one is echoing other one and so on which you can't do
in scratch is take that sequence if things and give it a name
to make it a new block
they will appear in the menu so that you can use it
to build other blacks and that abstraction right instead of
talking about the little low level things so like
I'm move so many steps in turn so many degrees is stated that
you make it so that you can talk about square right that's a kind of
which you can't do in scratch I'm buchanan BYOB the name BYOB actually
does not stand for what you think it does
it stands for build your own blocks and the main thing that lets you do is
add blocks to the scratch menu
I'm so huge missing feature
I they're actually gonna put it in scratch
in version 2.0 which is coming out someday
I'm but it's not clear that they're gonna put it in full generality
and really decided yet how they gonna do it um that basic
enabling technology com lets you do something called recursion there
among the big ideas in this class
two of them really are about
how you write a computer program the others are bad you know social things
or what computers are good for kinds of things number two in armor
are about programming in the first one is called recursion I'm
which you learn about later a man im gonna tell you it means right now I'm
but recursion and being able to build your own block is the enabling
technology for that
and the other big idea they were gonna talk about
is I'm russia has two names to aspect to the same thing higher-order functions
and procedure as data
and the enabling technology for that is being able to take
a block that you created her black that came with structure whatever
and instead of putting it a program
put in a data structure so make it
use it the way we use a number or string of characters or something like that
make it data and procedures as date is the other big
on programming idea that's in BYOB thats not a scratch
om and that you're going to be learning about in lecture as well as in lap
okay we have 12 minutes
now you can have stretching your computer you can have beer I being your
they're both Reserve Corps I'm track
and I up
up yep
aka up okay so fine from the course of age
get there I'm about a
I'm the word of thanks to other person who
actually did all the programming worker making BYOB
I'm his name is yen's manic I'm he's not here he lives in Germany
is a lawyer have all things on
BRB is kinda his spare time happy and
he's done amazing is at work or
I've done a lot of design and documentation and stuff but
he did all the actual programming so banks Jens questions
yeah you next yes
I'm the prerequisite for 61 a
is knowing how to program a recursive function as a recursion the first to
those big ideas
about programming I mentioned is the key idea that you need for 61 area
yes a
mean making making moving it okay you had the quest yes
the answer is yes how many how many vacant
chairs do we have in this reality 23 456
89 yeah are you guys would actually of it and chairs so next time
I mean it's not worth it right now but next time I'm
it would be really good at people who come early no
I know I was like to sit by the aisle to
it's a pain in the neck so yeah
there's yeah there's cs3 s which is a self-paced version of the old
class still exists I'm their mind they were teaching this class for the first
our plan is that this class will
totally prepare you for 61 as well as 3s whit I'm
3s has a slight edge
in that the programming language that they use
is scheme which is the same language 61a is I'm
but our idea at berkeley
is that after the first time learning a new programming language is not a big
so you know at the end we'll do some
talking about scheme a little bit but I'm but
essentially what we've done with BYOB
on because all the ideas really came from scheme odin is taken scheme in
disguise it
a scratch I'm see really gonna see the same ideas
and discuss would be more fun
because we talk about all that other stuff too and because
danas you've seen up
by the way danza PowerPoint guy a PowerPoint
I'm so when he is up you'll see all kindsa pictures and everything
I'm when I'm lecturing either are they just like this
or Adobe I'm typing it BYOB to show you
you know how a week earlier or something there
a power dang can tell you why I have spare point a PowerPoint because
it kinda makes you always say the same thing and not pay any attention to your
and you talk too fast you doing PowerPoint
down they are in my
in my class social implications have computers one of the things we read is
I'm a New Yorker article there was an interview
but the guy who invented PowerPoint about how terrible it is
because he thinks it's terrible to so they are other questions
yes math when there's a coal requisite for sixty one day
I'm yes see you really are supposed to do that
are you mad hatter hater
your now I'll great when you wanna take oh i should say I'm sorry
this something I should say I'm I'm in can I race this
okay in ordinary non-computer science vocabulary
when people talk about something as being abstract
they mean to removed from common experience
the opposite that is concrete something you can actually look at
so in ordinary language people would mostly say
up things like this are concrete
you can't C atoms are protons are quarks
those are abstract and the big pieces abstract also
so concrete is kinda in the middle that's normal usage in language
that's not computer sciences in July
in computer science we mean what's built in terms of what
so the higher up you are on this chart
the more abstract in the lower than you are the more concrete so concrete
his quirks there's a kind of the fundamental building blocks
and then as a lair abstraction and you
put quarks together in certain ways we get protons and neutrons electrons
you put those together in certain ways and you get Adams and molecules
and then you get materials and then you get
little parts you combine the parts store
and then you get big functional units and then you get even bigger functional
units are
okay so we talk about abstraction it doesn't mean
far removed from your experience
it means built in terms about this
aka sir
try not to get confused by that yet well
a richer up you can yeah I mean you know
lingo below quarks you know they're the string things maybe
or something I'm
I below I'm not a physicist but I believe the current state of things
is they know that corks can't be the bottom but they don't know exactly for
what comes next I'm and yeah we can take you know budgets have cars and make a
road elements our
okay I'm one more question
early radio right welcome to the cow it one question yes
is the course
can it be take can it be taken makes major
yes absolutely I'm if
mostly X majors won't need it because you learn to program a nice person yes
is there a lotta madness cars now
matter of