Pages

Showing posts with label Programming Methodology-Lecture25 Instructor (Mehran Sahami). Show all posts
Showing posts with label Programming Methodology-Lecture25 Instructor (Mehran Sahami). Show all posts

Saturday, 11 June 2011

Programming Methodology-Lecture25 Instructor (Mehran Sahami)


Programming Methodology-Lecture25
Instructor (Mehran Sahami): So welcome back to another fun filled, exciting day of
cs106a. A couple quick announcements before we start. First announcement, there is two
handouts. One of those handouts, which we'll spend some time talking about today, is
your last assignment for the class, which is assignment No. 7. It's worth noting, we sort of
talked about it the very first day of class when we talked about late days. The very first
handout says no late days can be used on assignment No. 7. So that’s important to
remember. No late days can be used for assignment No. 7 because it's due the last day of
the class.
If you're looking at the syllabus, you might say, I didn't think we had class on Friday, the
last day of class. That would still be correct. We don't actually have class, so you only
need to do electronic submission for turning in your program, but it's still due at 3:15 on
that Friday. We just don't actually have lecture on that Friday. We'll talk about the details
of that assignment as we go along.
The other handout that you got is the example of the code that you say last time for the
Fly Tunes music store. So you should have all that code, which shows and example of a
big data structure. In fact, the data structure for that program is perhaps more complicated
than the data structure you're going to need to use for the face pamphlet assignment, No.
7.
So as you know, assignment No. 6 review today. I have a feeling a lot of people may
have been taking late days on it because it was, for example, the last assignment to
actually be able to use late days on. So we'll just do a quick, painful as to how much time
it actually took you. Hopefully it wasn't too painful, but we'll see.
Just wondering, how many people are taking a late day? Wow. So for the six of you who
actually are turning in the assignment on time, anyone in the zero to two hour category? I
would be frightened if you were. I don't think it's actually possible to do in two hours.
Maybe, if you just sat there and wrote all the code. Two to four? Oh, I actually have a
couple for two to four. Wow.
Four to six? Good to see. I think all the [inaudible] is just going to be smaller. Six to
eight? That's a pretty healthy contingent. Eight to ten? Also good-sized contingent. Ten to
12? Couple of folks. 12 to 14? 14 to 16? 16 to 18? 18 plus? Anyone in 18 plus and still
hasn't turned it in, like you're just going for late days. All right. That's good.
So that's good to see. It's a good time. World is still normal, though the normal curve just
happens to be a little smaller because there's more people taking late days, but it's a good
time. If you haven't done it yet, two things. One is that this should give you an idea about
how much time it'll take, perhaps. Two is you don't want to push it. Even if you have late
days, don't push it off too late because you really want to give yourself time to do
assignment No. 7.
So any questions about anything we've done so far before we kind of delve into today's
great topic? All right. So I want to spend the beginning of class actually talking a bit
about your next assignment. So if you're still kind of in the mindset of thinking about
name surfer, and you're like, oh, I'm just so in the mindset of assignment No. 6, take that
little part of your head that's got assignment No. 6. Pop it off the stack. That's my whole
head. Yeah, that might be painful. Pop it off the stack for a second, and we're going to
think about our friend, the face pamphlet.
So just a quick show of hands, how many people are part of a social network or do some
social networking online. That's good to see. So I won't need to spend too much time
telling you about what a social network is, but I'll spend a little bit of time in case you're
not familiar with social networks.
Basically, a social network is just a way of keeping track of some set of people, or
profiles of people, and relationships among people. At the simplest level, that's all it is.
So what you can think about is you have some profile for a person. In some sense, you
can think of the notion of a profile and a person interchangeably most of the time. But as
most of you know, if you've ever read the New Yorker and seen that cartoon that no one
on the internet knows you’re a dog.
So you don't necessarily have to be a person to have a profile. So when we think about a
social network in the abstract sense, we always just talk in terms of profile. But if want to
think about it concretely, you can just think of a profile as being synonymous with a
person, but it need not be, so we generally refer to a profile.
So what a profile has associated with it, it has some attributes or some things that we
keep track of for that profile. For example, it has a name. In the case of your assignment,
it's also going to have some status that we care about, keeping track of the person. It
might have some other things, like the reason why it might be called face pamphlet is
because say you want to keep track of people's faces. You want to actually see what they
look like.
So you might actually have some image in there. Then I mentioned you want to keep
track of some list of friends. So there's some notion of a list of friends that is also
associated with a profile. Real social networks also have other things associated with
them, and the assignment talks about extensions you can do, but we're not going to get
into extensions right now. But these are things we want to think about.
For a person's profile, there's a name. One of the things based on some of the ideas we
talked about in the last lecture, is you can think of name as a unique identifier. What that
means is that you will never have two profiles in your social network that have the same
name. So once you have a name in your profile, in your social network, that name is
yours. That profile will be associated with that name until, at some point we decide,
maybe we want to delete the profile to get rid of it. But the whole time the profile's
actually live, it will have that unique identifier, which is the name of that profile.
So if you ever try to create another profile with the same name, the application will tell
you that you can't. I'll show you some examples of that in a bit. But the name is a unique
identifier, and this thing's just some string that we keep track of the name. So it can be
like your real name or whatever name you want to have, like Code Dog. That can be your
profile name. That's cool, too.
Status is just what you're doing right now. You can think of this as some string which is
what you happen to be up to at the time. Like Maron is teaching. I don't know. Ben is
contemplating life. It's just some particular string of the thing you happen to be doing.
You might want to change this a fair bit.
This image thing is just an image. In our world, that means it's a G image. That means it's
some picture. Originally, when you create a profile, you may not have a status, and you
may not have an image. You may want to add one. You may want to change one as life
goes on. We should be able to allow for that. Then you have a list of friends. When you're
born into the world, your list of friends is empty. Over time, you can gradually build up
friends.
That's the other part of the social network to consider, besides the fact that we have
profiles is that we also have some notion of friendship. The way you can think of
friendship is basically some profile or some person just has a list of friends. So an easy
way to think of a list of friends is a list of names of friends because names are unique
identifiers. So if we keep track of a list of names, we have a list of the unique identifiers
that are our friends.
That's an easy way to be able to look them up, for example. The idea behind friendship
that's key to us – this is not necessarily true in the real world, sadly enough, but for our
intents and purposes, as far as the assignment's concerned, friendship is reciprocal. That
means the if your friendship is reciprocal. Not all the time. That's the way it is.
What the really means is if I have two people, like I have Bob over here and I have Alice
over here, you can think of those as profiles. If they are friends, we draw a line between
their names in our little social network. This is not actually how we keep track of them in
the application that you'll see, but this is often how social networks are drawn.
We put in sort of a circle for each profile in the social network. Here's Don over here, and
here's Chelsea. Notice there's the ABCD phenomenon. Always a good time. So when we
put what we refer to as a link between two people, that means they're friends. Friends are
reciprocal. So if Bob is a friend of Alice, that means that Alice is a friend of Bob. That's
just the way life is all the time in face pamphlet.
It's just a happier place. Everyone's like, oh, I'll be your friend. Okay. Then you're my
friend, too. So that's the way you want to think about it. So if Bob ever adds Alice as a
friend, that automatically means Alice becomes Bob's friend. There's never a
directionality of friendship. Bob clicks, oh, Alice, be my friend. She's like, no. Talk to the
hand. That happens in real life all the time, but not here because it's just a happier place
to be in.
So think of friendships as reciprocal. Again, we don't necessarily have to have anything
explicit to model this link. All we need to do is think about just having a list of names. So
Bob might have Alice in his list of names of friends that he's keeping track of. That's how
I would keep track of the link.
What that also means is that reciprocally, Alice should have Bob in her list of friends
because the links are always reciprocal. When we actually draw this out, if we want to
draw the stylized picture, we could say Alice is friends with Chelsea and Don, and Don
and Chelsea are also friends over here. This is where the name network comes from.
When we draw this thing out, eventually you have millions and millions on these things
in there, all over the place. Everyone's holding hands and singing Kum Ba Ya. You have
a social effect because you have friendship, and what you actually end up drawing is
something referred to as a network.
If you're really the mathematical type, this is really a graph. In this case, it's an undirected
graph. If that kind of talk makes you hot and bothered, like, oh, a graph, yeah. Take
CS103B, which I'll be teaching next quarter. Graphs are just the coolest, most wonderful
thing. But that's a thought that's not important right now.
What is important right now is that this is where the name social network actually comes
from. We create this network that keeps track of social relations. So if we have that base
idea of social networks, how do we actually think about writing an application to keep
track of them. So [inaudible] the computer, I'll show you what, at the end of a week and a
half's effort, you will have your own social network application.
So we're going to call it Face Pamphlet because it's not really big enough to be a book.
It's a tiny book, so it's a pamphlet. So when it starts up, you can see there's interactors
galore all over the place. Over on the north side, we got a name. We got some buttons
over on the west side. We got some status, some pictures, some adding friends. What
does this all mean?
We'll actually go through an example and sort of create a little social network. So what
I'm going to do is create a profile for myself. You're like, oh, that's kind of narcissistic.
That's okay. I didn't want to – oh, we're going to create a profile for you right now.
So we add the profile on here. Here's what we get in the display. There's a bunch of
display elements. We have a name up there with some big font, and it's blue. We don't
have an image right now, so we just have a place holder. That's basically just a rectangle
with some text. It says no image. We don't have a current status, but what we've done is
created an initial profile with the name, Maron Sohami, which is a unique identifier in the
system. So right now, our social network has what we refer to as one [inaudible]. There's
one profile in there, and I don't have a list of friends.
You might say, okay, that's not so exciting. Let's actually add some stuff. So once I
actually have this active profile, I can say, let me change the status. Right now, at this
very moment, I happen to be teaching. So when I click change status, it says Maron
Sohami's teaching. Sometimes I could just be, no, I just really want to be doing this.
So I can keep changing the status. That's fine. It just updates here whenever I type it into
this field and click the button or hit the enter key. I can also add pictures. So I can say, for
example, MaronS.jpeg is a picture of Maron. There's a picture that gets loaded. It gets,
unfortunately, scaled to always take up the space for the image, which is a 200 by 200
region space.
It's constants that are given to you in the handout, but for these purposes, it's 200 by 200.
So this is kind of the bouncer version of Maron in the days of yore, when I was clean
shaven. There was actually a time when I shaved. That doesn't happen very often
anymore. If you were ever wondering what I look like without the beard, not that I care.
But that's what it was like.
So we've created a profile. Not a big deal. You could say, hey, next quarter, I'm planning
on taking 106B, and isn't that taught by Julie Zolanski? Yes, in fact, it is. So let's add a
profile for her. So we type in Julie Zolanski in the name field up here and click add. We
now get a new profile for Julie Zolanski. Julie is just a fiend. She codes like a fiend, so
she's coding like a fiend. That's what she's doing.
So you can see down here, not only is all this stuff getting updated as we typed it in, but
down here, there's something we refer to as the application message. The application
message always tells you what was the last thing you did or tried to do. So your status
was updated to coding like a fiend was the last thing you did. Let's give Julie a little
picture over here. JulieZ.jpeg, and there's Julie, also scaled to 200 by 200. So she's no
longer coding like a fiend. She's kind of feeling stretched.
So now we have her picture. We have her profile. That's all good and well. Let's add a
couple more profiles real quickly. So I'll add some of our section leaders. I'll add Sarah
K. I'm just going to abbreviate. Notice these fields over here don't necessarily get reset
when I create – they just have their old values in them. That's not a big deal. You could
add it as an extension if you wanted to, but they just leave their old values.
Sarah K. Sarah, is it okay if I use your picture? All right. Here we go. There she is, and
she's actually scaled reasonably well. So we'll also add Ben. There's Ben. We'll add a
picture for him. If you're wondering where all these pictures are coming from, in the
starter project that you'll get, you'll get a folder of images that contains the images of all
the section leaders from the class as well as Julie and myself.
I'm scaling until the cows come home. If you have your own pictures, you can add them
into the folder called images, and you, too, can display your image at a 200 by 200
resolution. Ben, where are you? Here's Ben.
Well, Ben's feeling kind of anonymous. So I gave you two anonymous-ish images as
well. There was a Stanford logo, which is just a super low-res version of our logo. Then
there's also Stanford Tree. So you can change the picture to one of those if you want to.
Those just come along for the ride.
If you do the web version, actually, the web version only has these two Stanford logo and
Stanford tree images. I didn't put everyone else's image on the web version because for a
little bit of privacy. Was there a question?
Student: [Inaudible].
Instructor (Mehran Sahami): No. If I empty the field, one of the things it says in your
handout is anytime the field is empty, it just gets ignored when I try to do something. So
any field, whether or not it's name or any other field, just ignore it. But I could have
something like the nonexistent picture.jpeg, and I try to change the picture to that, and it
says unable to open image file.
So in your handout, it actually explains how you can detect if an image exists or not. So
you can actually check the case where the image doesn't exist. If it doesn't exist, we just
don't update the image to the new image. Really, all we're keeping track of here is the
name, which gets created with the initial profile because it never changes, an image that
we display, whatever the current status is. If currently there is no current status, and a list
of friends.
So far, we've add a bunch of profiles. What else can we do? Well, there's a lot of things
we can do. Let's look up Maron again. So if I type in a name I can click look up, and if
that profile exists with that name, it brings it up and says you're displaying the profile
name down here. Then we can add some friends. So Sarah is a friend. Add friends. So it
says Sarah K, added as a friend. Ben is also a friend. So I add Ben.
I can try to add someone who doesn't exist in the system. Like I can try to add – who
should I add? Jenny. 867-5309. I add Jenny. Jenny does not exist. As far as I know in my
social network, Jenny's not there. I get this message down there.
Remember, friendships are supposed to be reciprocal, so I have Sarah and Ben as friends.
I never went to directly update profiles, but if I now look up Ben's profile – Ben N – Ben
has me as a friend. So when I added Ben as my friend, at the same time, I got added to
Ben's friend list. That's something that you're going to need to manage in the application.
Friendship should always be reciprocal. So when you add a friend to a particular profile,
you also make sure to go to that friend and add the current profile to that friend.
Now, another thing we can do, besides just creating profiles and done friends, we can
look up profiles, like when we had Maron's profile over here. We can look up a profile. If
I try to look up a profile that doesn't exist like Maron Sohami Bob doesn't exist. It clears
what profile's in there. It says a profile with the name Maron Sohami Bob does not exist.
When there is no profile in the current application – all this stuff, by the way, is explained
in the handout. This is just to kind of show you to get a feel for how it works. You don't
need to jot this all down in notes. When there is no current profile displayed, I cannot
change any of the things in the profile. It says please select a profile to change status
because I can't change the status of a non-existent profile or change its picture or add
friend to a non-existent profile. But the way I get a new profile displayed in here is I
either add a new profile or I look up an existing profile. Then there's a profile there that I
can change to whatever I want to.
Now, let's say I've looked up this profile. I say, that's great, and Ben decides he's had
enough. Get me out of your social network. So I say, oh, I'm sorry to hear that, Ben.
Here's Ben. I'm going to delete Ben from my social network. Even though I'm displaying
my own profile. I click Ben up here, and I delete him. Whatever profile was there, it
doesn't matter if it was Ben's or whoever else, it cleared, and it says profile of Ben N
deleted.
Now what happens when a profile gets deleted? It gets cleared out of the social network
so it's no longer there. If I try to look it up, it says a profile with the name Ben N does not
exist because, sorry Ben, you've been nuked. You're out of the social network. But Ben
was friends with people. He was friends with me, and now it's a sad day. So I go to look
up Maron. I should've just used the first name.
Ben has been removed from my list of friends. Sad day, but that's life in the city. You
can't be friends with non-existent people. So when someone gets removed from the
network, you go through everyone else in the network and say, did they have them as a
friend. If they did, they get popped out. I guess you're just not a friend anymore. That's
basically the whole social network. That's the whole idea.
So question?
Student: [Inaudible]
Instructor (Mehran Sahami): Okay. Names are not case sensitive, so I can have a
Maron Sohami, and then I can have a screaming Maron Sohami, and he's just different.
He's angry. I don't know if we have an angry image in here. I don't know if any of the
section leaders were actually looking angry, so we'll just make him the Stanford logo.
This is different than Maron Sohami, lower case. So you don't need to worry about it like
you did in the last assignment. You were worrying about case sensitivity. Here, you don't
need to worry about making things insensitive. You can just case – everything is case
sensitive, so you don't need to worry about making strings equal to each other, case
sensitive and stuff like that.
So any questions about this general idea? You got to think about it, right? Any more
questions?
If you kind of think about it, this is the basics of the social network. You have all the
people. You can have as many people as you want from the social network. You can
maintain friendships. You have attributes of the people, which in this case, just happens
to be their name, their image and their status and their list of friends, but you could
imagine – you could extend this in a whole variety of ways.
Really, what this is about is data management. There's a display component. In part of the
assignment, there's a bunch of milestones that are laid out. The actual only milestone that
deals with this display is the very last milestone, which involves a bit of work to get all
this stuff displayed at the right locations. There's a bunch of constants, which is all the
places, you put things at the right locations.
But it's really about managing data. How do you manage profiles, managing the
friendship relationships, being able to remove stuff, add stuff, which is what most
applications in the world are really about. So you're going to get a chance to really
exercise your data structure skills and your larger-scale application skills in this program.
So any questions about this program?
There's also a web demo of it, so if you want to go to the web and play around with it,
you can play around with it. Again, in the web version, there's only these two images, the
Stanford logo and the Stanford tree.
Student: [Inaudible].
Instructor (Mehran Sahami): No. That's the other thing. It's in big font somewhere, like
on page 15 in the assignment. So don't be scared by the fact that the assignment handout
is 28 pages like some people are looking at. Oh, my God, this is so big. The code is much
shorter than the handout, first of all. Second of all, one of the things – all the details are in
there, but one of the important things that comes up in the handout is you don't need to
worry about scaling.
So if I shrink or increase, yeah. No worries about size or resizing. I figured you got
enough practice with that with name surfer. Either you already got practice with it or
you're getting practice with it with name surfer. So we don't need to make you do it again.
So you don't need to worry about component listener and resizing and everything. You
can just lay this stuff out with t respect to the constants that are given to you, and you're
okay. But resizing, you don't need to worry about it.
It can be a cool extension if you want to add it as an extension. That's perfectly fine.
There's a bunch of extension ideas that are listed at the end of the assignment. As you can
kind of imagine, if most of you are on a social network, you probably already have
thousands of ideas for extensions, if you want to add them, but you're not required to add
anything in particular.
So any other questions about this? All right. So with that said, I just want to give you one
last little – before we moved into the advanced topic for today, one last little side note
about social networks. Has anyone ever heard of the phenomenon, six degrees of
separation? A few folks. There was a movie years ago about this phenomenon, and the
movie actually had nothing to do with the phenomenon. It just happened to have the
name, Six Degrees of Separation.
But it's basically this idea that everyone in the world is linked, potentially, to everyone
else by at most, six hops in this graph, which is kind of weird to think about. I won't go
into all the details an mathematics and stuff, but there's some very interesting stuff behind
it. But the biggest idea is that these social networks, you can sort of think of little hops
between people.
You can say Bob is one degree separated from Chelsea or two degrees, depending on
how you count, from Chelsea because you can get to Chelsea by going Bob, Alice
Chelsea or Bob, Don, Chelsea, whatever the case may be. But just in case you're
wondering where the six degree of separation idea came from, Stanley Milgram – anyone
ever hear of Milgram's experiments like obedience to authority, if you're a psychology
kind of person? Same Milgram.
We won't get into that. That's just a whole bunch of other interesting psychological
phenomenon that are discussed on the other side of the quad. But what he did was said –
this was back in the '60s, I think. '67, actually. He sent a whole bunch of packages to
various people in Nebraska. So let's just say that's Nebraska.
He sent a whole bunch of – yeah, my notion of geography – to random people in
Nebraska and said, these packages need to get to someone who's over here in Boston.
Yeah, I have no idea. It's Boston. That's Massachusetts, and here's Boston. These
packages need to get over here, but he didn't give them an address. He just gave them a
name of random people in Boston the packages need to get to.
The only instructions he gave were to say you can't try to figure out who this person is
and send them the package directly. What you need to do is send this package to someone
that you know who you think will be more likely to know this person than you are. Those
were the only instructions. Then when the packages was trackable, how many times it got
mailed.
He measured how many times the package had to be mailed to various people before it
actually got to its destination. What he found was there was an average of about five to
six for the packages to get from a random person in Nebraska to a random person in
Boston. That's where the six degrees idea comes from, but that's – now when people talk
about social networks, they talk about things like degrees of separation and what we refer
to as small world phenomenon. If everyone's linked by only six degrees of separation,
then it really is a small world after all. We can all hold hands and be mechanical animals.
If you've ever been to Disneyland, that makes sense. If you've never been to Disneyland,
you don't need to go on the small world ride now.
So time for something completely different. Are there any questions about social
networks before we delve into our next great topic? If you're really interested, you're like,
Maron, tell me more, take CS103B. It's a good time.
The advanced topic that you're going to get – and I hesitate a little bit to tell you this, but
this is something that you don't need to know for the final exam. As a matter of fact, you
don't need to know it for assignment No. 7. It's just something that's so cool with the way
programs are actually done today, it's something you should actually know. That's a
notion called concurrency.
It's also important for you to know if you want to understand, for example, in next class,
for example, I'll show you how to take the programs that you've written in this class and
turn them into applets or turn them into executables so you can share them with your
friends. You'll need to understand this idea.

Search This Blog