Você está na página 1de 14

ProgrammingAbstractions-Lecture01

Instructor (Julie Zelenski): Hi. Welcome to CS106B, programming [inaudible]. The


website was probably the most important thing to take away from here, right, is where
can you find information about the class? Were going to talk today and give some
overview and stuff like that, but this is kind of the home base for all the material. If you
managed to get the handouts on the way in, youre golden. Otherwise, you can grab them
from the website. Theres a lot of background information, staff information, office
hours, all sorts of stuff gathered there. Its kind of one stop shopping for figuring things
out about our course.
Let me tell you what Im going to do today. The first day, I know a lot of you are
shopping and trying to figure out whats the right fit for you, so hopefully today, Im
going to try to give you some information that will help you make a good decision. I want
to tell you a little bit of what our course is about, tell you about the administration and
logistics most of that stuff is pretty ordinary, and you can read about it. Of course, I
have to do a little bit of marketing. I get to give you my unbiased opinions of why this is
the absolute best class you could possibly take.
I get paid per student, you know. Thats not true. Maybe well even have time to check
out a little bit of the C++ language before were done. Let me tell you about CS106.
CS106 is the introductory programming sequence here at Stanford. Its our version of
CS1, where you start at the beginning when you are interested in learning more about
programming. We have a two-quarter sequence, A and B, that kind of follow together.
Theyre not particularly tightly coupled, which is to say if you took A and you took a
break, you could come back to B.
We also have an alternate form of B, the CS106X, which is kind of an honors version of
that second course. So after youve taken that first course and youre feeling really jazzed
up, there is an alternative more intense way to get through the second course thats
offered. Its offered this quarter, in fact, so if youre thinking about that, that is an option
for you as well as sticking with us.
What do we do in 106A? The official title is programming methodology. It is starting at
the very beginning and assuming you have no background in programming. Its teaching
you how it works, what the languages look like, what the syntax is like, what things you
need to know about how to solve problems using a computer. It covers a lot of the
fundamentals about logic control and in general, I think the big issues of 106A have less
to do with any particular syntax or feature that you learn about a language but about how
do you solve problems on a computer?
Somebody gives you a specification of you need to write a program that does X, and you
have to figure out how to make that happen, how to break it down, how to step through it,
how to develop it, how to test it, how to iterate on it, how to make changes in it later, how
to debug it when its not working well, and those things, I think, transcend any particular
language. W e happen to use the Java programming language in our 106A course because

its a great tool for introductory programming, but I dont think of that as being really
critical.
In fact, if your introductory course was in some other fairly modern, high level language
lets say you learned in Python, C, Scheme, or something other than Java, youre
probably still fine, cause what were really counting on in B is that you know how to
program and think like a computer scientist. Not a lot of the details of the syntax are
going to be important to us. B picks up from there, saying okay, youve got some
fundamentals. Lets start really learning some of the techniques that extend the range of
problems you can solve.
We look at recursion, which is one of the fundamental problem solving techniques that
involves using something akin to mathematical induction to solve problems in terms of
themselves. Looking at a lot of algorithms for sorting and searching and hashing and
doing things efficiently, knowing how to compare and contrast alternatives in algorithms,
having some formalisms by which to discuss those things, and learn some of the classics
that are out there for solving these problems.
The dynamic data structure, which involves use of pointers to construct things like lists,
trees and heaps, graphs that model certain structures that are very effective in solving
certain kinds of problems well work through those. A large part of our time is spent on
this concept of data extraction, which is why extraction shows up as the main word in our
title. As we start to solve more and more complex problems, the code itself can kind of
become overwhelming if we dont have some technique for managing that complexity.
One of the big themes for 106B is how we can use this idea of extraction, building
something and dealing with the low level details but then closing up the box and treating
it as kind of a fixed entity and building on top of that and then closing another layer
around that as a way of working on something, finishing it and moving on to some larger
piece without having those details cloud our way. Its a very powerful technique for
solving larger problems.
In that context, well be looking at some of the classic data structures, like stacks, cubes,
lists, maps and sets as part of the domain for that. We do happen to use the C++
programming language, but this is not a C++ course, so to be clear about what youre
getting versus what you wanted, we use Java here. We use C++ here. We happen to think
theyre good reasons to actually expose you to both languages. In particular, C++ is an
enormous language. It has a lot of language features as well as a very large standard
library, and our goal is not at all to turn you into this industrial strength knows every
detail about quirks and ins and outs of C++.
There is another class, 193D, that does attempt to do that. In fact, if thats what youre
looking for, I suggest you take a look at that. What were here about is learning advanced
programming techniques taking those foundations and building on them to be able to
solve more interesting problems. We happen to use C++. You will learn some C++, but I
almost consider it a side effect of what were doing.

Just a little note on placement if youre kind of in between and not really sure, these are
the very rough guidelines, but they give you some idea of which groups gravitate where.
If you are new to programming or youre not confident about your background maybe
it was a long time ago. Maybe it was self-taught. Maybe it was in a course that you felt
was not as good as it could have been or you didnt do as well in it, 106A is a great place
to start. It actually is by all accounts an extremely popular course at Stanford and services
a wide group of people with a little bit of background or no background.
If you do have something like a solid first course experience you did well in 106A or
took a similar course or perhaps even self-taught your way through a lot of those
materials and you feel ready to move on, 106B. An AP course in high school the A
curriculum is a pretty good match for 106A here, so youre in a great place.
If you have this and youve got a little bit more going for you or youre super enthused
and you have a lot of extra time this quarter and want to sit in the company of only the
uber geeks, you can check out 106X, which covers the same kind of topical ground but at
a different level intensity. It amps up a little bit of the assignments, covers some of the
material that we wont get a chance to cover, and just pushes the envelope a little bit
there.
If you have experience comparable to the first two courses youve done all the things
that were talking about here in B and you feel comfortable with it, it might be that the
right place for you is 107, which is the third course in our sequence. Thats somewhat
rare, so if youre thinking about that, I encourage you to talk to me a little bit to make
sure that you wont be missing out on something important in doing so, but certainly
there are students who have for example, the APCSAD curriculum is pretty comparable
to this course here, and so depending on how high quality the course you had was, it
might very well be that 107 is right.
In some situations where that course was a little bit lacking, there may be some ways that
we can help reinforce the things youve learned and build a stronger foundation to move
forward from rather than jumping ahead. Any questions about placement?
Lets talk philosophy. I think theres a statement about what we officially are, but I also
think that 106 has a long tradition at Stanford that comes back from student motivation,
which is interesting. I was here as an undergrad in the 80s when the 106s were just
getting off the ground, and at the time, Stanford only had a graduate computer science
department, and the belief in the ancient period for computer science was you should get
a math degree, and only then would you be mature enough to learn about computers.
There was a groundswell of Stanford students who said we want access to programming.
We want it. Part of the 106 was a really careful thought about what the 106 would be a
Stanford and what we want them to be in a philosophical sense. One is that we welcome
students of all majors and backgrounds. We dont have a version of 106 thats for the
majors or potential majors and a version thats for the non-majors and a version thats for

terminals. We really think that we can bring you all together and design a course that
addresses this wide disparate group but still serves it well.
Im going to turn you into a CS major. Thats my plan. At Stanford right now, not having
to make that choice about a major until junior year is a gift to allow you to explore and to
feel unencumbered by having made some decision when you applied, and I think its
important to respect that gift that Stanford gave you by trying to make sure our courses
dont funnel you one way or the other before you figure it out. You are all welcome here.
We try to make it accessible to everyone. We have certain plans that help to make that
work.
We do try to provide a solid, practical foundation in programming that given our
placement at Stanford in the middle of the Silicon Valley, theres kind of a strong
influence for us to try to produce students who from the get go are learning things that are
actually quite useful outside of the classroom rather than teach you a very academic and
mathematical language like Scheme that is very rarely used outside of the classroom.
Were trying to teach you on the tools, languages and techniques that are actually in
active practice.
We are using Java and C++, two of the most prevalent languages out in the industry, and
we do a lot of learn by doing. We assign challenging, full-fledged programs that you
work on and you build, and so its not designed to be academic exercises. You really are
building skills that have applicability here and outside of the class. We have a big
emphasis on truth and beauty. This is one area in which some of the substitute courses
that we have seen students come in with have a little bit more trouble with is tackling this
part of it, which is that there are a lot of ways you can get a program to work. Many of
them are not pretty.
You can just type and type and type and eventually, you can get your way to something
that works. That, in the end, might produce a program that from external appearances
works. It plays hangman or whatever was the desired goal, but that internally is a mess.
Its not well structured. Its not well [inaudible]. Its not easy to understand. It wouldnt
be easy to modify. It makes a lot of decision that are really sub optimal, and were really
interested in producing engineers that have a good sense of design and really appreciate
what is involved in writing good, well designed software, not just working software.
We will be giving you feedback on both the correctness and functionality of your code
but as important if not more so, also on how well we think you did at designing and
implementing and writing code that is of a high quality. We make a big deal out of that.
That is something that is not always shared by other classes, and so in particular,
someone who is self taught or in a class that didnt emphasize this might feel that theres
a little bit of a gap there where we need to make that up with you, and we can work with
you.
This is a very individual thing, because theres not one good example of the perfect style
in the way that a lot of different people express themselves in written communication

very well but differently. The same thing is true about programs. You will have your own
unique style, and well work with you to coach you on getting your style to come through
and be beautiful and elegant.
This kind of comes back to point one as well is that we make heavy use of undergraduate
section leaders as mentors in this program. We have a staff of 50 or so undergraduates
who work with the 106A, B and X courses as a team. They have specific responsibilities
with their section, so mentoring and grading and meeting with sections to give
individualized feedback on their programs as well as answering questions, solving
problems, being in the lair 30 plus hours.
Theyre most weekday nights about six hours and often well past the midnight when its
supposed to cut off solving peoples problems, helping when you get stuck, answering
your questions and making sure youre all making forward progress. That comes back to
point one. In some universities where theyre choosing to use their intro course as a
weeder, its like lets separate the weak from the [inaudible] early and lets make it really
hard and not provide too much support, and that way well make sure we get the people
we want.
We have a different idea. Programming is hard, especially when youre learning. Theres
a lot of complexity to master, and there are a lot of details that can interfere with moving
forward, and we dont want you to get stuck on something that we can very easily resolve
for you. So make sure you have accessible staff members in person, in email and
regularly in session to help get through the roadblocks and keep you moving forward.
What do you need to know to be sure youre going to do well? There are people who
think to be a good computer programmer, you need to be good at math, logic, and
drinking Jolt. I think it comes down to more personality traits than any particular
technique or skill. You dont need to be good at math. How much calculus and trig shows
up in this? Not very much. A little bit of logic that helps. I think it comes down to traits
like curiosity and determination and hard work. Starting early, asking questions when you
dont understand something, trying to solve the problem by logic why does this case
work and why does that case not work?
I think these are the skills that serve you the best in this class and probably every other
thing youd want to tackle. There is a lot of time that will be spent here to master this. I
can talk about programming all I want, and you can go oh, yeah, that makes a lot of
sense. But when you go to write it yourself, its a very different experience. Thats where
being focused and staying on task and getting help when you get stuck can help you
move through that.
My unbiased opinion about why 106B is one of the best courses at Stanford its going
to be totally obvious when I say these things, and you guys are going to have to go along
with it. Im actually a big time geek, and I happen to love programming. Thats why Im
a perfect fit for teaching this course. I have taught 106 B or X more than Ive taught any
other class that Ive taught at Stanford in my time here, and thats because each quarter

when were setting the schedule, I say give me B. Give me X. Theres no better course to
teach.
Programming is just awesome. If you love programming, I think theres almost nothing
better to do in the world. You have this task. Youre trying to get there. Youre coding.
Youre making stuff happen. Youre testing, iterating and running. You see stuff. You
build things. When youre done, you know it works. When a program works, you know
it.
It does what its supposed to do. It gets the right answer. It plays the game. It solves the
problem. Finding and fixing that last bug although debugging is one of the last aspects
of programming a lot of people bemoan about, I happen to think that if you are driven by
debugging, that is one of the most awesome detective stories ever.
Trying to figure out why it happened when you did this, why it went this way when you
moved that and what this effect caused and understanding once you make the fix how it
fixes it staying up late. I have stayed up late more nights debugging than anything else
in my life, and Im not sad about that at all. That means Im in the right place. Hopefully,
some of that resonates with you. If that sounds really awful to you, hopefully we can
change your mind a bit. That is, in some ways, part of what drives computer science is
this wanting to build things.
We are engineers. We have this computer science name. Just remember any subject
thats name is something science is not a science. Were trying to puff ourselves up a bit.
We do a lot of really great work, and there are a lot of neat scientific principles and
theories that underpin what we do, but in the end, I think what drives a lot of us is just the
engineering building stuff that is really neat.
It kind of reminds me that my husbands a mechanical engineer, and so I used to be
envious, because he would always build things. Hes always toting foam core around the
campus on their paper bicycles and stuff, and its like they build all these things. Now,
having watched all the things he builds, its like [inaudible] really hard. You need all
these materials. You need all these tools. In computer science, you dont need anything.
You need a compiler and you need a computer. You need your thought. Its like an
abstraction we built out of our brains.
Theres this relatively small set of things that you need to master and then you can
combine them in these very sophisticated and interesting ways to solve all sorts of
problems. Theres a very low overhead, and the range of things you can attack with the
same set of skills is huge. Every domain out there can benefit from somebody applying
computers in a useful way without fail. Theres all sorts of problems where technology is
part of the answer not the only answer, but certainly something that you can take
whatever interest you have and combine it with computer science and construct
something cool.

I happen to think that what happens in the second course is amazing. The first course,
youve kind of got to get up to speed, and theres a lot of basic material that needs to get
covered, and it does set you on the right path, but in this course, we really get to blossom
beyond the basic things.
There are a bunch of really neat and very accessible techniques that a second quarter
student can understand and master and do really cool things with. You can learn how to
do something like create a database that has a million entries and then ask for somebody
by name and be able to instantaneously be able to find the name. Change the size of it.
Make it ten million, a billion, and still be able to provide that kind of instantaneous
access. Youre going to learn how to do that.
The technique is not some superhuman thing. Its something very clever, admittedly, but
its very accessible. Taking that same million thing and learning how to sort it efficiently.
What if you happen to know things about how its almost sorted but just a little but out of
sorts? Are there ways you can actually make it even faster to put it in sorted order? There
are techniques, for example, like recursion that take on problems that you might not have
any idea when you first look at the problem how to solve, but once youve got your head
around recursion, you can look at that and say I can write a five line function that will
solve that problem.
This is the kind of power were going to give you with our quarter together. Theres a
bunch of really amazing theoretical and algorithmic stuff to explore that really increases
the kind of things you can do with programming. Im particularly fond of it. As always, I
think the section leading program that we have created and built at Stanford is a huge part
of what makes our 106 courses so successful, and so having somebody whos
individually working with you, meeting with you weekly and giving you that feedback
thats individualized and personalized for you and helping you get through the rough
spots is a lot of what helps to make the experience very fun and very personal, too.
What section leaders do I have here? Not a one. Where are those section leaders? We
havent yet identified whos going to what class, so maybe theyre all thinking theyre
going to go somewhere else, but theyre wrong. Well get some. 106B great. You
agree? Have I convinced you? Is anybody still hesitant? Is it a lot of work? Oh, no.
Let me tell you a little bit about logistics. There are some random things you may want to
know about how the class works. Were going to meet here Monday, Wednesday, Friday
2:50 to 3:05. It looks like we almost exactly fit in our classroom, which means were all
going to be very friendly and cozy. The lectures are being taped and are available online,
and so that has the neat side effect that you can watch them and review them later. You
could watch them lots of times.
It also means that if it were pouring rain and you were sitting at home in your bunny
slippers, you could just say hey, Im not going outside and you could turn on your
computer and watch. Im a big fan of having you come in person. Thats because I dont
want to lecture to an empty room. I also think theres an interaction there that Im fond

of, and so I hope that you will make every effort to attend in person as much as you can.
It is nice to know that if you do miss a lecture or you get caught up with something,
youll have a chance to review it later online.
We will have sections that will meet once a week, just like 106A. The section leader who
meets with you is the one who will be grading your programs and sitting with you and
doing the conferences. What you need to do to get yourself into a section there are
several section times listed. Ignore them.
What you do is you go to the online if you go to our class webpage, theres a link that
tells you how to sign up for a section. The section times arent up right now, but they will
go up tomorrow, and theyll be up through the weekend. You go in and put in your
preferences about what times fit your schedule or not, and theres this big computer
program that gets everybody into a section that fits into their schedule.
The signups will be up from Thursday at 5:00 until Sunday at 5:00. If by Sunday at 5:00
youve got your schedule fixed, then youre fine. If you happen to change after Sunday at
5:00 and after the assignments have been made, at that point, its a little bit harder. We
can make adjustments, but its on a very case-by-case basis. The best thing you can do is
by Sunday at 5:00 have a pretty firm idea about what you can and cant do. Theres a list
of preferences, so maybe what you can do is pick things that you know will work no
matter what happens.
The workload everybody wants to know how much work. Its a five-unit class, and its
a five unit engineering class. You get your five units worth, I would say, so dont worry
about that. I wont shortchange you. We have programming assignments not quite
weekly. I think there are seven of them across ten weeks, so you can calculate it out. Its
about a week and a third for any particular one. The students report that its about a 15-20
hour project, each of them. Some people get them done in less than that. Some people
take a little bit more. I would say thats kind of the mode range for what people are
reporting.
I do think that of the people who report less, some of those are people who are naturally
gifted, but a lot of it has to do with your habits about how you work and how you make
progress, so if you are one of the people who feels you might be more likely to be on the
other end, you can come and talk to me and I can give you some suggestions.
Choosing to work in the lair where the helpers are on duty has really positive effects in
that when you get stuck, you have easy access to somebody helping you work through it
rather than spending an hour or two fighting something that turns out to be simple but
required knowing something that you didnt yet know.
Im a big fan of learning things yourself. Theres also a time when a well-placed bit of
advice from somebody can save you a lot of time. There will be a midterm and a final
exam. Theyll both be in class, open book, open notes. The midterm is actually
technically out of class. Were going to have it at night because we need more than a 50-

minute period to get any coverage of that. Our final exam is scheduled in our universityscheduled slot. Sadly, that is at the very end of the exam week, but thats when the
registrar put us, and thats when we need to go. You may want to take a look at that
before you head off for spring break.
Unfortunately, our publisher will not allow me to distribute the course reader
electronically. Theyre not exactly very in the modern age on this. Yeah, Im working on
it is the truth. By the time the world sees this, hopefully, we will have some other
strategy. We currently are in negotiations. The nice thing about the course reader is that
we have not changed it in the last year. If you know somebody who has it from last fall or
last spring, it has some minor edits and typos that were fixed, so if you can get a hold of
an old one, its good.
We are getting no royalties on it. Were publishing it at production cost, so where it
would have been a $100.00 textbook had it been bound and snappy, youre just getting
what it cost to photocopy and bind the thing, and Eric and I are eating ramen. Its
hopefully cheap enough that you can find a way to get to one or get an old one without it
being too much of an obstacle.
People in general find the course reader to be an asset. We do say its required reading. It
does have a lot of material thats very useful in understanding the course. There are other
people who dont make as big a use of it, but there are some sections that are really very
valuable and other ones that may be more or less depending on your learning style.
Theres also a lot of good sample problems and review questions in it that help to test
your understanding.
You know, its tricky, because the university in general discourages you from giving
alternate exams because of you can imagine the issues of having an exam that has been
seen by some number of students before some other number of students take it. Even
though were all bound by the honor code, it does create a situation where there is some
temptation. Its possible it could be a little bit early without a lot of gap, but I dont think
early enough to make a lot of help is the truth. We can talk about it. The current plan is
not, I would say.
A little bit about compilers. We use C++ and we also use some custom libraries, which
limits us to distributing on a certain number of platforms weve had a good chance to test
on and work with. The compilers that we have support for is X Code on the Macintosh.
Anybody who has Mac OS10 can freely download that and install it.
Were using Microsofts Visual Studio Version 2005 on Windows, and we have an
arrangement with Microsoft where they have distributed the software free of charge to
students, so if you would like to install that on your own Windows computer, well give
you some handouts on Friday that tell you what to do to get the compiler and get it
installed on your computer.

Our cluster computers in the dorms and the libraries and the lair have both the compilers
and libraries installed, so if you work in a cluster, you dont have to do anything special.
You just walk up and its got the stuff ready to go. Im a Mac person. Ive been a Mac
person forever. I cant get over the fact that you go to the start menu to shut the machine
down. That makes Windows impossible for me to use. I would say campus wide, there
are more Windows machines than Macs on campus, so if you want to take a popular vote,
you could do that. If you want to be on the side of the Mac bigot, you can come and be
with me in X Code.
Ive got ten minutes to tell you a little bit about C++. That is the next journey that were
going to go on together. The first question is why are we doing this to you? I just got
comfortable with Java and now youre telling me to throw away my Java and start over.
Lets generate a little bit of love for C++. The advantages of early multilingualism I
have two small children at home that are two and four, and I read a lot about
bilingualism. Its very clear that for natural languages, when youre acquiring a language
at those young ages that that is the best time to introduce a second or third language.
Its been looked at in terms of programming languages as well, that when you are
learning a programming language, there are certain kind of ruts your mind gets into about
the way a language is that is based on your early experiences. If you spend a very long
time working only in one language, those ruts get deeper, and you have a certain way of
thinking. Youre a little bit stuck in that paradigm and its approach. Whats easy to do in
that language, whats hard to do in that language tends to make a stronger impression on
you in a way that makes it harder as you grow and explore the languages to kind of get
out of those ruts and shake yourself out of it.
Theres been some pretty good evidence that somewhere between one and two is a good
time to think about branching out and starting to think about different ways of doing stuff
and seeing some different syntax and some different ideas to help build in the flexibility
from an early age in your career to buy you some strength later. Thats part of what were
doing.
Another part of it is actually that a lot of our upper division courses rely on a knowledge
of C and C++, that family of languages, and that the longer we postpone it, the more
painful it becomes. In the later courses where youre learning about compilers or graphics
or networking, they dont have the time in those classes to stop and teach you C or C++.
They need you to know C++ to get the work done. Moving the foundation into a
programming class seems to make the most sense in the context of our curriculum.
We do switch you over here. The good news is that its not as big a change as it might
sound at first glance. Java is actually highly derivative of C++ for a start. Theyre kind of
cousins in the scheme of language design. They have a lot of syntax. How much C++ do
you need to know to start? The answer is zero. You dont even need to know what the
word means. In fact, you actually probably know a surprising amount about C++ just by
virtue of what you already know just translated a little bit.

Things like the four loop of Java or the way you declare variables or the way parameters
are passed into a function is exhibited in Java in very much the same way it is in C++.
There are a bunch of things you already know and you dont even realize. It is not
assumed that you know C or C++. If you happen to already know those things, youre
ahead of the game. If you have not, then not to worry.
How much C++ are you going to learn? We will spend the first three or four lectures just
talking about how things get expressed differently in C++ and mostly talking about the
differences in the libraries. The syntax itself is quite similar. Some of the more extensive
changes have to do with how the C++ string is operated on versus the Java string.
How you do file input and output reading in C++ is a little bit different than the way its
done in Java. Well spend some time saying here are some things you know how to
express in one language. Were going to teach you how to express them in another
language. Its just mapping from your previous vocabulary onto a new one.
Along the way, we will actually introduce some of the C++ features that we need to
support our pedagogical goals. Well be talking about how classes get designed in C++.
Well see how to use classes. Well see how to define those classes, and well look at
things like templates, which is the C++ construct for doing generics that you seen in Java
how you can build containers that are type unspecific and things like that.
We will learn a little bit of some of the fancier features of C++ like the pass by reference
parameter, but theres actually a very large amount of C++ thats just off the table for us.
We will not make extensive use of the standard template library or the fancier features of
static and [inaudible] and a bunch of key words that mean nothing to you and should
mean nothing to you. You will learn enough to have reading familiarity with C++ and to
be able to express yourself quite well in the subset were using, but it is a subset of C++
that youre being exposed to.
If you find yourself really wanting to master C++, we are offering CS106L. CS106L is a
lab companion course that is open to students enrolled in 106B or 106X. It meets twice a
week. Its actually on Monday and Wednesday late afternoon. Its 4:15 in Hewlett 103.
Its being taught by a veteran section leader who is very well versed in C++ and who of
his own volition volunteered and created this course because he himself was a little
frustrated as a prior 106 student in wanting to get at some of those C++ things that
werent fitting with our goals. It is a place where you can get more exposure to standard
C++, do some exercises that help you to test out those things and see how those things
are expressed and get another unit. Its a pass/fail lab course.
You can also just attend or grab the materials if you just want to look at them. Its a great
way to broaden that knowledge of C++ beyond whats useful for us in terms of our goals.
Im going to ask you some questions, because I dont get to do all the talking. How much
C++ do you need to know? Some of you may know nothing about it, and that is perfectly
fine. Some of you probably know something about it or at least have heard something

about it. Im going to have you guys tell me what it is that people tell you about C++ that
makes you either excited to learn it or frightened to learn it or interested in how it works.
Student: Its what Java is based off of.
Instructor (Julie Zelenski): It is what Java is based off of. That should be a little
reassuring that there is a syntax there that got adopted with some minor changes. It
should feel more familiar than different when you look at it. It was very strongly
influenced by a generation of programmers who C++ was their native language who
designed the Java language. Thats a good thing to know. What else do you know about
C++?
Student: Its extended C.
Instructor (Julie Zelenski): Yes. Its extended C. Heres how it fits in the spectrum. C is
kind of a 1970s creation. C++ is a decade later. C is the language which it is based on. It
is an extended C. Its called a superset. Everything that compiles and works in C still
exists in C++, but then they added a bunch of features. Not only did they add a bunch of
features but they tried to fix some of the things about C++ by replacing existing things.
For example, theres some string handling in C thats kind of very primitive. They added
a string object with much cleaner handling and safer semantics into the C++, but they
kind of left the old one around. Some parts of C++ feel a little strange because of this
history to it the legacy of incorporating everything C was plus the stuff means at times
theres a little bit of weirdness there. It also means that the language, as a result, is very
large. Cs safety and runtime features were extended by what got added in C++.
Student: A friend of mine told me that [inaudible].
Instructor (Julie Zelenski): Thats a good thing to know. C++ might be a little bit more
dangerous than Java. That is true. Java is very concerned with safety, in particular since
Java was designed for web delivery of content. It was very important that the program
have very constrained features on what it can and cant do, and so as a result, Java tends
to be very parental. When you forget to initialize a variable or forget to return from a
function, Javas very aggressive about saying hey, youve got to fix this.
C++ is a little less parental. Heres the overly protective mom, helicopter mom, the ones
who stand. Thats Java. Javas making sure oh, are you okay, sweetie? Let me stand
here in case you fall. C++ is crack mom. Shes like yeah, Im over here with my friends.
Dont play with the kitchen knives. Its a professionals tool, and professionals dont
want to feel encumbered. There are certain things they want to do that require some of
this low-level access, and safety usually comes at a cost.
Any sort of feature where the language is double-checking for you is taking time and
efficiency. Theres a cost associated with that. Every time you want to get something out
of an array, its checked to make sure that that number was not off either end. Every array

access costs you a little bit more. C++ says Im not going to charge everybody that
penalty. If you actually have the bad sense to write a program that does those things, you
deserve to be punished. As a result, you will at some point in this quarter get to
experience some of that firsthand.
Some of it is a growth experience. Some of it can be frustrating. It is part of what
professional tools often look like. They are making these tradeoffs of efficiency over
safety that put more of the work back on you as the programmer to be a little more
attentive on those things. You can write programs that crash in very spectacular ways
much more interesting and varied and dangerous than the kind of things you can do in
Java. Good to know.
Instructor (Julie Zelenski): You want to use pointers. Youre going to get to use
pointers. Pointers are really neat, and theyre also very challenging. Pointers are these
ways of building these very flexible and amazing data structures the kind of things that
were going to try to build. At some point, they are going to be the only way to achieve
those things well, so building these things called trees, graphs and lifts rely on
understanding a mastery of the pointer type.
The pointer type is complicated, and its part of that danger thing, which is having access
to rearranging memory by virtue of addresses opens up a lot of opportunity for there to be
mistakes. Mistakes can be made in the passive voice that have consequences. Youll get
to experience firsthand what thats like. Theres joy in it, because getting it right is
awesome, and there are things that you can achieve that are really extraordinary with
pointers, but when its not working, it can be frustrating. Youre getting a little bit of
both.
It turns out C++ does not have a graphics system built into it. Java is actually
distinguished from previous languages. Java tries to solve all problems. Traditionally, a
programming language tends to have a set of libraries that have facilities for data
management, reading and writing files and sometimes some networking, but they dont
tend to actually solve application layer problems. That tended to be a different piece of
technology. The Mac OS might offer a graphics library that was written in C++, but C++
the language didnt have a windowing system or graphics system.
C++ does not have those features itself, so any C++ compiler you get comes with these
basic things about handling files and managing these types of data structures, but it does
not come a priori with a bunch of graphics routines. That said, Windows and Mac and
Linux and all these things have graphics routines that are written in C++, but theyre all
different. To say what are they like relative to Java? Theyre all different relative to Java.
Its not standardized.
Theres a wide variety of them out there, and they tend to have a lot of very impressive
and different solved problems, because C++ has a longer history than Java that a lot of
problems have been solved in C++ that are available to you, too. Theres a lot of existing

code other than what you might think is standard. I will see you on Friday, and well be
seeing some C++. If you have questions about your situation, come and talk to me now.
[End of Audio]
Duration: 43 minutes

Você também pode gostar