Placeholder Image

字幕表 動画を再生する

  • All right.

  • Hello, world.

  • This is CS 50 on Twitch.

  • My name is Colton Ogden, and I'm joined today by Bryan and David for a part to code review Stream.

  • Yeah, I did a lot of fun the first time, and now we brought Brian one of our best teaching fellows here on campus.

  • Good to be here.

  • Yeah, I wasn't on sometime last time.

  • We had a ton of viewership, and it's super interesting getting the test.

  • See everybody's projects, a wide range of programming, languages.

  • Last time I looked at some python programming languages are projects programming projects on.

  • And I think we looked at, um, html page.

  • Actually, night.

  • Nate was 10 years old indeed.

  • Broad audience out there.

  • So it's good to see some familiar names and faces and emojis here.

  • And welcome to reveal who just followed as well.

  • Yeah, and we had another follower.

  • Actually, we're adjusting our view here a little bit in real time so that we can actually see not only the comments nice and wide, but also our followers here.

  • So sayyed 055 as well.

  • Thank you very much for the follow Lita to G and D Manda.

  • Oh, and we have a few, actually.

  • And see Miss Sweden.

  • Hugh, thank you very much for the follows.

  • We really should just say hello to people's numbers.

  • Yeah, maybe it might be a little easier to pronounce you, but Yeah.

  • So we have a bunch of awesome project today.

  • And also thanks to Brian for joining us for the first time.

  • Absolutely.

  • And many more going forward.

  • Why don't we?

  • Why don't we dive right into our first product roll?

  • Sure.

  • So if you're new to the stream, we via Colton solicited some code that folks had worked on other for personal projects or otherwise by a Google form a few weeks ago.

  • And we got a number of submissions python, html, c and other languages.

  • And so what Brian and I thought we would do today with Colton here is just provide some feedback, much like our teaching fellows here on campus Would, based on the design thing, efficiency, the quality of the code that we're seeing and certainly take all this with a grain of salt.

  • Reasonable people will disagree, so you don't need to take our thoughts as cannon.

  • But hopefully it's helpful food for thought whether it's your coat we're looking at or code, that's of interest.

  • Some of some of us might even disagree, We shall say Probably not.

  • Probably not with a bunch of regulars in the chat with ST Nate.

  • Uh, we just actually mentioned has submitted a thing last week.

  • And actually, is he saying that they submitted more code and they hope that they contribute again?

  • Well, thank you.

  • And, uh, we should probably preface this by plugging the actual you, Earl for the form for people that want to submit us projects in the future for more episodes after this one.

  • This is part two.

  • We didn't another one.

  • You can watch the video on YouTube.

  • If you goto billy slash CS 50 twitch code review, you can submit a get up or a Google form with your gift every but we're just and then you could be in any language.

  • Can be a small project, be an advanced project.

  • But we'd be happy to take a look at it.

  • Graded on a correctness, not practice on design and style.

  • Not correctness will not be bug testing.

  • You know, I think we need your else order for our u R l sort.

  • Yeah.

  • We probably should go to a C study that.

  • But what we have here a CZ the first project, and we sort of looked these a little bit in advance and cure.

  • At least, um, sort curated.

  • Want them in kind of an order.

  • This is a C library, which is kind of cool because we didn't actually look at any C code in the last video, but sees 50 teachers see a sort of the first language on ramps.

  • Everybody to the more dynamic languages.

  • It's kind of cool that maybe look at a real world project in C.

  • Yeah, It looks like we have a project here from Noah.

  • 1101 to live picks map on for the top of this.

  • It get hub.

  • You're able to put a description for every project he put on.

  • Get home.

  • This is a simple to use library to read and write P p.

  • M.

  • Or portable picks, map images.

  • Frankly, I was not familiar too much with p p.

  • M.

  • Just a few minutes ago.

  • Yeah, I think so.

  • But I think that's okay.

  • So let's actually go ahead.

  • And Google, for instance, on Wikipedia is probably a great source of information here, and indeed, there's our file format.

  • But in a different number of contexts here, uh, let's see pages per minutes.

  • It's probably this portable picks map format.

  • So Annette's PBM format is any graphics format used and defined by the Nets PBM Project.

  • Uh, this is the, uh, these air image file formats designed to be easily exchanged between platforms.

  • And they are with us since, like the 19 eighties, it seems.

  • Yeah, it looks like in the 19 eighties, there were first developed in order to make it easier to transmit images via e mails where you wanted to be able to send an email, that an image in it.

  • And it looks like this format.

  • The Net PBM format would allow you to take an image, turn it into a plane, ask you text, according to this article, in order to just send it more easily from one person to another over the Internet.

  • So no, if you're tuning in or if you tune and after certainly let us know why or what motivated this project because it's quite interesting, it seems, but as we did last time, shall we just dive right into the gate, huh?

  • Yeah.

  • And I should also mention that there get abusing Was actually from there.

  • Twitch.

  • User name, which we did solicit.

  • Twitch.

  • Every release is the talk of an eye out for every release other today or in some future stream.

  • So the way I only start by diving into the students code or colleagues code is just to look at, like, read me.

  • And I think if we scroll down here on, get Hub will indeed see, read me from Noah.

  • So here we have a nice description.

  • Frankly, we should just roll before I guess, what is live picks?

  • Map.

  • It's a library and impure.

  • See the names to provide an easy and convenient A P I for reading and writing.

  • PPM files four features opening ppm images creating blank ppm images, setting and retrieving the color values for specific pixels.

  • Not unlike what we do in CS 50 on dhe set and get all pixels.

  • This extra sounds reminiscent of what we do with bit map files, which is another relatively simple image format.

  • What I like is that this library is very simple, but very flexible, like you could use this to dynamically generate any image data based at least when I'm reading here.

  • But the fact that you create a blink image and then senator chief color values yeah, that's great.

  • That's good way to start because other formats that are more recent like J.

  • Peg are actually very highly optimized for compression and use much fancier algorithms to store the information.

  • It's not quite as easy, therefore, to get at individual pixel values.

  • All right, So should we take a look at an example, for instance, and get a sense of how this all works?

  • You wanna walk us through what you're seeing here and how you would go about reading someone's code for the first time?

  • Yeah, sure.

  • So we have the main function there, So it seems like well up at the top before the main function there, including Standard Out H, which you might be familiar with a few chickens.

  • 50.

  • We use that in a lot of see programs and then there, including picks map dot each, which looks like it's probably the header file for the library that Noah has created here, and that's gonna give him access to some of the types that we're going to see in just a moment, probably in some of the functions.

  • Meanwhile, so inside the main function we're defining a something of type picks WMAP image.

  • So not an image that's built in deceased's probably have some sort of definition that will take a look at just the moment on.

  • We're fighting a pointer to it called Image, and then we're running a function that looks like he's defined called picks WMAP Image open.

  • I presume this is gonna be some file path to the image that we're going to try and open, and we're gonna store some sort of data about it inside of what's pointed to by the Pointer image.

  • And we looks like there's an air checking here, checking to make sure that we're able to open the image successfully.

  • If we weren't able to open the image successfully, we print in error, return a non zero error code, And what would it mean for image to be not image like?

  • What is this?

  • Checking for C.

  • U S o N C.

  • When you have ah pointer value like image and you have exclamation point image or bang image that's checking to see whether or not image is equal to know.

  • And so no stands for the no pointer, meaning image is not pointing to anything.

  • And so it's a convention and a lot of functions.

  • If we try and run, pick snap image open, for instance, If we couldn't open the image, for instance, if the file didn't exist at the particular file path, then what we meant to get back is rather than a pointer to an actual picks me up image.

  • You might get a pointer.

  • That's just know.

  • And so if bang images checking to see if images know in which case something went wrong and we print that air.

  • So it's really like checking for zero really or fall.

  • So it's not false.

  • Then go ahead, right?

  • Do this.

  • So I'm a little nervous and we wouldn't know really until we dive into the code.

  • But because images declared is a pointer.

  • As per this asterisk right here, a pointer to a picks mapped image.

  • I'm a little nervous that were then in the sample code, getting the address of the pointer unless this image is actually gonna do a lot of our memory allocation for us and then change what is at what point changed the contents of that pointer itself as opposed to what it's pointing it.

  • But we'll see.

  • Yeah, that's a good place.

  • Is appointed to a pointer, which feels a little a little worrisome.

  • But maybe it's correct.

  • Yeah, all right.

  • And then down here, Do you want to fight on for what's going on a little further with these prints?

  • Okay, so next it looks like we're trying to print the images within height.

  • And in order to do that, looks like Noah's to find some functions, picks my image, picks WMAP image, get with and picks me up.

  • Image get height, each of which is taking that pointer a pointer to a pixel image.

  • And presumably those functions are able to take that image and somehow where inside the data stored within the image get access to the width and the height of that image and maybe a couple points year.

  • If you've been taking CS 50 you might know that in recent years we actually introduce students 2% I for integer well percent D for decimal into Juries almost identical, and it is in fact, with the context of print depth.

  • It's a little different if you're using scanning for actually getting user input.

  • But that's otherwise.

  • The same thing is percent I and I think it's worth noting.

  • For those of you who have heard about or familiar with object oriented programming, this is a convention.

  • And see that, frankly starts to get messy pretty quickly and see there is no notion of object orientation.

  • And so even though image kind of sounds like an object that represents an actual image, and you'd like to just, like, look inside of it for its with or its height, you could do that if it's a struck.

  • But if there's more to it, you sometimes need to pass these structures into other functions and let them figure out what the height the width is.

  • So this is a common procedural paradigm.

  • I've seen this in certain, like game code bases to and see they have to exact gonna pass everything around his inputs.

  • All right, so just a few more lines here, let's see if we can glean what's going on here.

  • Maybe, All right, so it looks like we're defining a variable of a new type.