Placeholder Image

字幕列表 影片播放

  • All right.

  • Hello, world.

  • This is CS 50 on Twitch.

  • My name is called Knocking.

  • I'm joined by David Malin today, and we're going to do something really cool, which we haven't done yet so far.

  • Also make might be cool.

  • It's an experiment, but what we do, what we did to be broadcasted.

  • We sent out a Google form with a link that people could include their Twitter user name and also a link to a get hungry boat.

  • Or adjust and send us and source code that we could take a look at and then maybe provide feedback along the way.

  • We do would see us 50 with design in style but not correctness.

  • We will not be testing code for functionality.

  • No, in fact, that it works.

  • It's cold mentions for many years, the axes, so to speak, along which we evaluate students.

  • Cody's correctness.

  • Does it work?

  • Is it supposed to we?

  • Of course.

  • He's check 50 for that these days.

  • Design.

  • How well written is it?

  • Did you use Maur nested loops than you need to?

  • Did you write functions instead of copying and pasting code and so forth?

  • And then style does it look pretty.

  • Did you indented June?

  • Name your variables.

  • Well, for which we now have, for the most part style 50.

  • So that middle component is very much a human process.

  • And that's the part we do in person with students or a synchronously by get hub comments.

  • So that's what we're here to do today.

  • It's gonna be awesome.

  • There are a lot of different kinds of repose.

  • There was a good amount of python co, a little bit of Java script.

  • And if you have the language, somebody even submitted a C library, which that was really cool and fairly appropriate.

  • So why don't we start diving in here?

  • I'm gonna switch us.

  • We have a brand new Microsoft surface pro this big computer right here, the Sikh and kind of see that we're using.

  • It's got a nice touch game.

  • There we go.

  • There we go.

  • Nice.

  • Represent the wind ice brand placement today.

  • Okay, but yeah, we're using a new device today, so hopefully we have no pickups there.

  • This is our view.

  • So we have a nice full screen view and this is our first project and this is N a c l Eric.

  • It's assault Eric.

  • So any sale sodium, which is salt in the gaming community, That means like you lost in your upset Major salty.

  • So that's kind of the reference there.

  • It's apt because this is a super smash brothers, huh?

  • Themed project.

  • And so that's kind of where the reference comes on to see if any seal Eric's actually in the chat.

  • Because I feel a bit like an old man here.

  • Tell me more about this, this newfangled machine.

  • No, no, I don't see any seal arrogant yet already, but I'm sure that he will see a little bit later.

  • So this is just if you're not familiar.

  • Super Smash Brothers is a Nintendo fighting game on, and there's a very strong competitive scene, and there are multiple games that have varying degrees of relevance, sort of.

  • In that scene, Melee is probably the most popular one.

  • So this is a game that commandos in 1000 Jews and Smash Brothers melee very famous iteration of the franchise.

  • And this application here is kind of just a tournament data analyzer.

  • So maybe you want to pull up the C S V file here ashore on 18 issue H.

  • Nazi s V.

  • So this is just kind of some.

  • Now all of these on the left are essentially in the top.

  • It's basically a matrix of tournament data, and I haven't analyzed this deeply to know exactly what the numbers mean but essentially got from reading the Repo.

  • Looking at the other modules that it's sort of what I can infer, wins and losses against other players.

  • So hungry box versus hungry box.

  • Obviously, you're not gonna get wins and losses against yourself, so that's an empty grid.

  • But you can see against plucked, for example.

  • I imagine that's 16 wins, five losses, for example.

  • So that's just kind of the way that this great is laid out.

  • It may or may not be.

  • It might be the opposite way.

  • Might be losses and winds up in a cell.

  • Various NHL Erickson The chat of the very bottom.

  • If you can elaborate, maybe on the data for my hear, if I got it wrong or right, let me know.

  • But in any case, this is our database.

  • But you said this is a C S V.

  • But I'm seeing an HTML table here.

  • Correct, correct.

  • So get Hubble actually render a CSF very a table view, which is a cool feature of get hub.

  • If you have a CCTV in your repo, it'll actually render a table in its place instead of just, you know, the actual comma separated list of strong.

  • So if I click raw, though we should see all the commas so much you would less user friendly where we could open this in Excel or Google spreadsheets or Apple numbers?

  • Absolutely, Absolutely.

  • So, uh, this is the data format.

  • So essentially players and the wins and losses against other players if you want, maybe we could go back into the prior director.

  • There's a lot of drug fox.

  • That's an interesting name s.

  • So now, if you want, we could maybe go through some of the pi falls and maybe you can give your thoughts.

  • I'm sure she would take a look at the Read me to understand what it is we're looking at absolutely quick.

  • All right, so they read me dot MD is, you probably know is like a default file in the get hub world where you can set up some instructions for what it is you're looking at.

  • Frankly, this is the first place to look when you open a repo for the first time, and I have no idea perhaps what you're looking at.

  • So it looks like our n A.

  • C l friend kindly set us up very straightforwardly with some instructions.

  • So python three, setting up a virtual environment or the end.

  • We don't use these in CS 50 but it essentially allows you to encapsulate an application and a folder and in an environment, so to speak, so that you can install certain dependencies in that local environment without affecting your other applications had almost like Dr Rising a set of it's lightweight, lighter weight.

  • Pipe on specific.

  • Why, sure, sure.

  • So, indeed, it looks like our friend has some package requirements and requirements.

  • Dot texts.

  • I might take a quick glance at that.

  • In a moment you're setting a couple of environment variables, and even though you might not have done this in CS 50 itself, we do this for you in CS 50 I.

  • D.

  • We, for instance, have a default value off Last cap equals application dot pie, and that's how flask knows when you just type flats run what file to look at.

  • It looks like a and A C L.

  • How do we want to pronounce us?

  • And they sail?

  • Eric?

  • Yeah.

  • We're getting a salt to salt, Eric.

  • Okay, salt.

  • There.

  • Correct us If you'd like salt.

  • Eric here has chosen a p i dot pie for his final name, which is fine and flask Debug.

  • One will enable some nice debugging features.

  • But you see, just like in CS 50 flats Koran, we'll kick this off.

  • This isn't something that you necessarily get red at the gate when you're insulting a flask application?

  • Uh, well, ideally, if the 12 documented I mean, this is nice, because this is telling you when you started a new flask application, what about you have to do this in order to get this flash friend capability you have to do that is if you're using flesh run.

  • Yes.

  • You need to set those environment variables somehow.

  • And exporting it to your environment is the most persistent way to do it, at least for your current shell.

  • This is nice, because honestly, the first thing I was gonna ask is what are we looking at here?

  • Malay dot pie contains the function to query the CSB file.

  • AP Ida Pies, The main flask app cleaned up, I clears, cleans the data, and then we'll try to decrease the amount of material changes and add them.

  • So that feels more to do than a no.

  • So I feel like I would first be inclined to take a look at requirements that text just to wrap my mind around what this is using and then maybe start with a p i dot pie and makes sense because that's also that looks like that's the flask app itself.

  • So hopefully this is an easy one.

  • If we go up here on requirements dot text, all this is that fun?

  • Familiar is a text file.

  • That line by line has a requirement.

  • And if you want to fix the version of a pit python package you're using, you just do what assault Eric did here with the equals equals specific version number.

  • All right, so a few of these look familiar flask Jinja markup safe is probably HTML related.

  • I've used It's dangerous.

  • I don't remember what functions have used their and but we'll see what we're using them for.

  • In library name.

  • I haven't used that one.

  • Salt Eric feel free to chime in at any point cause you know the code and we're making it up as we Oh, so here we go a p i dot pie.

  • Nice.

  • All right, so we position this, I think, is an opportunity to comment on code.

  • So how do you want to proceed here?

  • I'll say what my original inclination is.

  • And I think this is a common theme throughout a lot of the reports that we see is there's there no comments in this particular module, and that may or may not be important for this example, because it's kind of small, but I mean, right off the bat, I'm already kind of forcing myself to go into read the code and not really get a program or high level understanding of what I'm looking at, S o.

  • I think definitely having at least a small dock string, if not just a single line header over all of these routes can at least you know, Seo, this route does.

  • It serves this information from here.

  • Is that our docks during?

  • What do you mean by that?

  • So Doc String is a comment like a block level comment that goes over a function that specifies your inputs and outputs to your function gives you a sense of, um you know what date I can feed the function.

  • What I'm expecting back and without having to necessarily get into the nitty gritty details.

  • Especially for looking at a really long, gargantuan function that we have no idea what it means.

  • Lincoln immediately kind of at least high at a high level.

  • Understand the code that and actually, can we talk?

  • Go over to your main screen.

  • Let me just go ahead and log in here real quick.

  • Sure.

  • So I'm gonna go ahead and Loggins with an account here just so that we theoretically could submit some pull requests here.

  • Just let me know when you want to do.

  • It would be right back.

  • Just typing in my super secure password.

  • In the meantime, remote says wait windows.

  • Yeah.

  • Now we're switching to windows today.

  • Um, Sem Perera.

  • Lee, here we go.

  • All right, let me go ahead and log in here.

  • Give me one second.

  • Yeah, it's a really nice piece of hardware and a 3000 but something Pixels two, we're going down to just 10 80 feet tonight, so we scaled down just a little bit.

  • Somebody my commercial.

  • Okay, interesting alley one.

  • I think that was a separate conversation.

  • OK, Do you want to keep here?

  • Let me change one thing here.

  • You want to go ahead and read some of the comments we have what we have to get going.

  • Don't Ton saying here from Nigeria thing that might be the first Nigerian student we've had.

  • Actually, it's so awesome.

  • Thank you so much.

  • Welcome from Nigeria.

  • Um okay, just make sure I don't want the folks got caught up in a little Facebook commercialization, chatting on a non contextually pull a little bit out of that.

  • Um, just make sure So all the regular a lot of regulars air here.

  • Isabella cures McKnight remote.

  • Sergio one says hi.

  • I don't know, it's kind of a familiar name, but that might be the first time I've seen Sergio.

  • BBO one Brenda Saying Good morning.

  • So Hi, Brenda.

  • Thanks for joining us today.

  • Acid Jack, three of three says hello, world.

  • Nice.

  • Hello as well.

  • Um m Kloppenburg.

  • So Martin from Facebook.

  • Thanks for joining in Injure ready five you make with the hello and that always every time I see that you think I'm looking at Aaron?

  • Looks like Aaron from it does.

  • Yeah, Aaron, from our own team here, which which we're trying to get her onstream as well.

  • This this bear is drunk.

  • That's a great user name.

  • Kaizer Twitch.

  • Um, see, for mostly, Kind of.

  • Just make sure sends a touch.

  • Three D.

  • Awesome.

  • Thanks.

  • So much lasagna.

  • Eleanor says love your CS.

  • 50 course on YouTube.

  • Nice.

  • Nice.

  • And they don't forget me.

  • Well, everyone.

  • Hello, Cold.

  • Hello, Professor Malin says Andre.

  • I lo I Lo Andre.

  • Good.

  • Familiar name to thank you very much for joining us today.

  • All right, Think we're caught up and I'm good to go here.

  • Okay, let me go ahead.

  • Emma switches back to our service pro here.

  • All right, So first, take all this with a grain of salt, if you will, which is an expression meaning don't necessarily take.

  • What we're saying is gospel cause reasonable people will disagree.

  • Hopefully, we'll be able to offer some objective comments that even some software and python standards will corroborate.

  • But certainly again feel free to disagree with some of the things we said.

  • Maybe not everything.

  • So I'm gonna go ahead and just pretend to edit this just so that we can kind of talk as we go.

  • I could go so far is to submit a pole request.

  • Thio Salt Eric if we wanted to.

  • But at least this way, we have a little bit of edit ability.

  • So the fort do you forget?

  • You know, I just click to the the pencil icon, which allows me to on the fly start editing the file.

  • And if I were to try to save this, then I would actually have to seo say, this is a brand new start over.

  • I think that's cool indeed.

  • So there aRer standards in the world of python known as Pet for a python enhancement proposal.

  • And this has come to mean a set of standards have been added to the languages community over time that govern how you should write python code.

  • And Pep eight, for instance, is the newest version of the style standards that, actually, if you're familiar from CS 50 style, 50 tries to enforce, so anytime you run style 50 and get feedback on your python code, we are comparing it to this so called pep eight Standard.

  • And any time there's a difference between your coat and that standard, we pointed out with red or green highlighting to imply you should be changing it in this way or some other.

  • So I've gotten good enough at running style 50 on my own coat that I know some things to look for.

  • And I'm pretty sure, for instance, that Pep is gonna complain about some of the aspects of this file.

  • For instance, it's conventional toe actually separate your imports at the top of the file from your actual lines of code or logic.

  • So having a single space there, it turns out that Pep also says, even though I find this one a little annoying, you should have to blank lines in between functions and above the first function.

  • So you'll notice that we have a deaf hello function here.

  • So Python's gonna yell at us.

  • Our pep is going to yell at us if we try to have any fewer than just two lines there and getting ahead of myself, it's gonna want to lines there, and maybe I think below this one as well, though I don't recall 100% on that one interesting.

  • I don't think I typically do the two lines after each function, but it makes sense.

  • It's okay.

  • It's a little excessive.

  • I'm okay with one, but so be it.

  • So stylistically, I think if you if this is production code or if the application is nearing the end of its development, you should definitely just remove stuff that doesn't need to be there.

  • I'm guessing this was there for debugging or just getting you started, but of course, that probably shouldn't be there ultimately.

  • But it's OK that it is there now.

  • But what I was noticing a moment ago is an inconsistency.

  • There's some quoted strings or stirs in this code, and this is This is subtle, but we're using double quotes here and then down here.

  • We're using single quotes all of a sudden, and then down here we're using single quotes as well.

  • Good point, and none of those is incorrect.

  • But it's just it's sloppy, I think.

  • What do you prefer personally when your programming?

  • So in CS 50 we use double quotes on Lee because see for strings requires double quotes, and it's just simpler, I think, cognitively to keep everyone in the same mindset.

  • However, with Java script, we do you single quotes because that world just really evangelize the single quotes.

  • And honestly, I've come around to liking single quotes, cause it means one fewer keystrokes.

  • You don't have to hold shift anymore, and that's compelling.

  • But whatever use, I think it's fine teaches or her own, but you should be consistent, especially in a language like python, where it does not matter.

  • So you don't have to start using double quotes just to achieve some feature like like in PHP, where double quotes are actually functionally different from single quotes.

  • So we could just ignore this problem, though, and delete those lines of code is probably not Germaine to the program fixed and honestly, this does not need to be here anymore.

  • To this is a remnant of older virgins of plastic.

  • You don't need that anymore.

  • You should instead, according to flasks on documentation, use flask, run and not even have a main routine, and your flat so kind of injects it doesn't like inject a main routine or something like that underneath the hood or this year.

  • So this would the winning caught flat screen without main without this app That run call does it.

  • It doesn't take this module and therefore inject its own app that round or behind the scenes kind of do that when it's not there, it actually looks for believe of variable.

  • Uh, it looks for a variable called ap inside of the file that you're specifying via the art environment variable Which application dot pie or a P I dot pie Okay, as well.

  • So we don't strictly speaking need this year.

  • And this one I don't love am almost okay with this because if you had sort of Rick Well, actually, we're using Can't tell from get up If it's spaces or tabs, it's fine if you want to line it up that way.

  • However, this line is short enough, Honestly, that I would probably just keep it on one just like this.

  • Here.

  • What's going on?

  • You can keep going on.

  • I'm gonna check the street.

  • Okay.

  • Colton's gonna check the YouTube stream here.

  • So what else might we do here?

  • Well, we have eight to h stats, and that's being paired to this named argument here matchups.

  • You could, of course, make this even trimmer by taking that print player function and just assigning it there.

  • I don't know yet what print player does, but I'll admit I'm a little uncomfortable with the fact that the functions called Print Player the variables called H two h stats and you might know better with that signifies.

  • And then the named parameter is called Matchups.

  • Like semantically.

  • It just feels like the names are all over the place here and again.

  • I say that without knowing what the function does yet, but I'm not seeing any relationship among these three strings.

  • And so I'd like to see this cleaned up.

  • But I don't know offhand how best to do that.

  • Yeah, I think I think, like I said, with the doctoring, having like, kind of a mapping between what is hoh stats mean or with that short for for somebody coming into the code.

  • And maybe they don't know what melee is or smash, maybe in that scene at all.

  • But you you need to hire an engineer to work on your code base.

  • I think having these acronyms variables, that map kind of makes sense, and somebody just followed.

  • I don't have the indicator up, thank you very much.

  • Liz.

  • A lasagna, Lenart lasagna.

  • Leinart's Welcome aboard lasagna.

  • Nice to see you.

  • Have any other mentions?

  • It's up now.

  • The B K labs also.

  • Thank you very much for following in.

  • Puppy, Puppy stumper 92.

  • Okay, we're just trying to move on from that.

  • All right, So what else might we comment on here?

  • Well, that's a pretty trim file.

  • Assuming assault, Eric is okay with our removing so many lines of code.

  • But I kind of like thinking about new code that you're looking out for the first time is kind of following the bread crumbs and the fact that I'm you and I are curious.

  • Now what print player is suggests that we should follow that bread, chrome and see OK, we'll print player comes from a file called malay dot pie.

  • Presumably if it's from the local app.

  • So let's actually go back.

  • I'm not going to save these changes.

  • We're not gonna impose our ideas on you, but feel free to adapt yourself.

  • Let's go take a look at that file as well.

  • But before we do that, let me go back to the read only version of this, which is where we started and I just Googled earlier because you could run style 50 on your own Mac or PC on din fact, or you could you see a 50 i d.

  • But it turns out someone online made a website called Pep eight online dot com, where you can paste your python code click check code and then this website will lint it, so to speak, analyze it, statically top to bottom left to right and provide you with feedback.

  • It's not quite as maybe visually useful as style 50 tries to be, because it just has this list of all of the problems with the code.

  • But if Salt Eric wants to take a look at this to you, could see online five and nine and 13 and 16 are their suggestions for how to align this code with Pep.

  • Eight says nothing about correctness.

  • Nothing about design but does say something about style.

  • There's a sad onto that a lot of modern text editors to have these have plug in systems.

  • Yeah, V s code Adam sublime and within those plug in ecosystems is usually very some one big, really good lynching plug in that you can install for python and many other languages, but they usually defer, ultimately to a command line to a call pilot.

  • But it will inject the actual lynching sort of how we have here on the screen.

  • There's red and yellow tags with the actual numbers for the for the pep spec actually inject those into the left side.

  • So V s code is what I use.

  • You can get it for V s code Adam and Sublime amongst other plug ins as well.

  • Date.

  • And actually, we're seeing some things that I didn't even notice and get hub notice here.

  • This warning online 13 indentation contains tabs.

  • So here, too, we're not gonna probably didn't start a religious debate over Spaces versus tabs, even though you should do spaces.

  • But mixing them badge certainly frowned upon for the same reason.

  • Stylistically, that shouldn't be mixing your quotes.

  • It's just sloppy.

  • It's harder to see Case in point.

  • I can't even see the tabs and get hub.

  • So frankly, personally, I would actually I'm doing it already.

  • I would advocate Spaces because they're 100% robust on any person's text editor, and what we're seeing here is exactly the symptom it might look like uniform indentation.

  • But there's some tabs intermingled and most tech senators.

  • Now, we'll just let you convert taps.

  • Two spaces, not by default.

  • Yeah, I'll just do that for you.

  • Which is not have to worry about that too much.

  • If you're using a modern Texas if using something that's not, you know, something like, uh, I've been doing automatically, if you can figure it out automatically.

  • Yeah.

  • So, yeah.

  • Either way, Yeah, I find myself in agreement with that.

  • All right, well, let's So there we go way slipped into the religious debate there.

  • So that's going to make light up high where there should be at least one function that was afforded at least print player.

  • We do indeed.

  • See here.

  • Yeah.

  • Yeah.

  • This is really the meat and potatoes of the applications, far as I was able to see this one function.

  • Yeah, I do see that as well.

  • So C s V Fine.

  • Okay, so let's just kind of read the stop the bottom.

  • So importing the CS for comma separated values to read that big data file that you gave everyone a tour of.

  • Here's our function.

  • Takes a player is in put up just to your point earlier.

  • I'd love to see some comments here because, honestly, my brain is already starting to hurt.

  • As to now, you're making me think too much as to what this does.

  • Yeah, I would love to see minimally a doc string.

  • If not, I mean, we do have comments here along the right hand side, but the problem with the comments along, you know, being here on the right hand side, Especially when you have lines like 21 here.

  • The line that starts with Jason here.

  • It might be a little small in the er enhance a little bit.

  • That's about as big as it didn't look like you got any larger and, Well, it will in a few seconds.

  • All right.

  • I'm sorry.

  • Looking past, I thought it was looking at our current view looking at looking at our life Seem great.

  • Uh, bring this up here.

  • Okay.

  • That's gonna be better.

  • Um, so online.

  • 21 here, which is a really long line.

  • If you're mixing that with these comments that are in line comments, not only will those lines the very large in your text editor there requiring you to sort of zoom out, but it it gets a kind of mix and match your actual code with where your comments are just a little bit hard to read on a little bit too.

  • Uh, what's the word?

  • I'm looking for a jam packed looking forward.

  • Greece of words 100 clutter, clutter.

  • All right, so what else could we comment on Appear So matchup data and Jason, I don't really know what those are gonna be.

  • Yet it be nice to probably comment what they're gonna be used for.

  • And honestly, I'm not even seeing them used in the next several lines.

  • And so here, too, I would argue they should not be declared right at the top of the file like this isn't see from yesteryear.

  • I would define those variables closer to where you're actually using them, just to give them proximity to where they're logically being useful.

  • Thes lines here are fine, although, honestly, there's so much you could just nest all of this into one line if you really wanted to.

  • In order to read the entire contents of the CSC.

  • However design wise, this seems very vulnerable to errors.

  • For instance, if this file is missing or For some reason, it doesn't parts correctly.

  • All of this should probably be encapsulated in a try, except thanks.

  • So is the handle and error.

  • We don't introduce this in CS 50 but it's, ah more sophisticated way of doing error checking, trying literally to do something and accept if something goes wrong.

  • You handle the exception in some way, and they literally have predefined exceptions, like file, not found error just date.

  • Which is probably what we would use here for that example.

  • And you would see some pretty arcane error messages on the screen that if your new programmer or user, God forbid, is seeing this, it's gonna completely confuse them.

  • You can catch those and provide much more user friendly messages like 2018 h 28 dot c S v not found in here to this is generally frowned upon design wise, too hard code.

  • Something like this.

  • String this file name into your code that should probably be factored out to a constant or a global variable somewhere that's configurable.

  • Maybe in a file called config dot pie in a Jason file or a yam Oh file or even a CIA file of variables for the program or just take it in as an input to the function.

  • And I would go so far as to say it's okay to sign that the default value to a parameter, but allow the caller to override it so that when you're playing, maybe you want to test it with a super small CST.

  • You don't have to go changing your actual code to test it with a different files, a good point for scalability.

  • So here it looks like we're just filtering out all of the empty elements of that list, and I'm okay with that.

  • Although stylistically, there should be a space between the hash sign and the first character, According to Pep.

  • Pep also frowns upon these in line comments that are at the ends of lines.

  • They should really be going above the corresponding blocks of code, and it's nice that you've aligned them all like this for readability.

  • But that is a pain in the neck.

  • To maintain on that quickly becomes more of a headache than anything, and I would just not even go there, put it above the lines.

  • You can read the code top to bottom.

  • Offhand, Do you remember So typically what we do internally for our comments is we capitalize The first letter of each comments.

  • We D'oh.

  • Yeah.

  • Is that a pet thing, or is that just something we do?

  • No, that is not yours.

  • If you have multiple sentences and pep comment, it's supposed you're supposed to use proper grammar and periods.

  • I don't think it specifies if you just have a single phrase if it so much matters.

  • We did standardize, though really to be nitpicking because if you do have a two sentence comment, you're of course, going to start capitalizing.

  • So I just inferred from that what?

  • We should probably just start capitalizing.

  • The 1st 1 for consistency makes sense.

  • So here is where suppose I were your colleague working on this code for the first time?

  • You're really hurting my brain.

  • Trying to read through this now like I would really love a comment.

  • Ah, top line 10 maybe 11.

  • Just tell me in a short phrase, what are the following five or six or seven lines of code doing?

  • And don't make me think, cause I'm literally going to start staring at this code, trying to understand what it's doing looking back at the CIA file to see what the data is.

  • And it's just wasting time like, you know, right off the top of your head what this is doing.

  • And you could save yourself weeks hence and even others days hence.

  • Ah, huge amount of time in on boarding online 21 especially.

  • I think that's the largest line that I can see.

  • Yeah, I mean, there there is some readability in there because it can say that wins and losses and assuming that, you know, putting those two together in some sort of data structure, you know, to compare them at some point, but or just at least probably to display them here.

  • But just having a string there just to our comment there to let me know what I'm doing, exactly what your code gets pretty complicated like that agreed.

  • Now here, strictly speaking, we have the single quotes, but that's fine in this file because they're used uniformly.

  • I don't love now that I see how this is being used in Line 21 that the variable is called Jason because, frankly, it's not.

  • This is a python dictionary.

  • Now I understand the intent.

  • It's eventually meant to be kicked out by the A p I route in a pie day pie as Jason.

  • But this feels like it's prematurely named.

  • This should really be a player, data or player or some representation of the actual data.

  • The fact that it becomes Jason later is really an implementation detail, part of the controller, not part of the model, so to speak itself.

  • And we don't need to go down this road.

  • But this is an example, it seems, of NBC.

  • This is kind of a model file.

  • It doesn't need to get into the weeds of the transport mechanism, which might be Jason might be something else altogether.

  • Sure, and I would also say, to add on to that, they're given that Python has a library called Jason.

  • I believe it has a library called Jason, Yet there is.

  • There's a potential opportunity for a bug here.

  • Yep, indeed.

  • And agreed.

  • Agreed.

  • Another note.

  • Here, you can actually have Python closed files for you.

  • Refuse the with proposition and say, with open such and such, you could do that.

  • And honestly, this should have been done way earlier, because if this file were open, tear and we converted the whole thing to a list here.

  • We already have all of the data.

  • As of line eight, it would seem so.

  • We certainly shouldn't be closing it all the way there again.

  • Close things.

  • As soon as you're done, finish your thought.

  • A cz proximal to the code where and you're using it just like I proposed.

  • Declare your variables proximal to where you're using those as well.

  • Pep.

  • It is also not gonna like this.

  • I think it's gonna want spaces in between the arguments to a function like range.

  • So minor point?

  • Yeah, pure because they do use yet now we got inconsistency.

  • So even if you disagree, you got to agree with consistency.

  • Consistency?

  • That's probably one of the main themes, right?

  • Just be resisted and also being well documented.

  • Those two are probably good for stepping stones.

  • Yeah, absolutely.

  • I see it again here.

  • There's no space after this comma, even though there is nicely enough after the Colemans there.

  • So just be consistent.

  • Pep is probably gonna want you to have spaces around the plus sign.

  • Even I find that's getting a little bulky, but so be it's if you're gonna use pep and just just we won't go through pep every time.

  • Let me go ahead and copy this code and just paste it in and you'll see that we do get a nice summary of a lot of these same stylistic concerns, not in the design ones.

  • And indeed, here there's a whole bunch of warnings or errors.

  • Visa VI the pep specifications.

  • All right, so I feel like we've let me go ahead.

  • Oh, I was gonna say fuck off.

  • A few comments or questions broke up.

  • Few comments.

  • We'll do that while if you want to search, the next report will bring us over to the blank screen here.

  • We got a couple of 21 that I did notice what we're doing.

  • So the I love Malin user name somebody created here.

  • Interesting.

  • Thank you.

  • Um let me see.

  • Oh, somebody mentioned Airbnb.

  • Styer baby has a good style.

  • God, you're very detailed.

  • Um, spaces imposed indentation style across the team.

  • Ideas and text editors can be configured to set tabs to space is four spaces or whatever.

  • Both spaces, if using four.

  • That's four spaces for everyone.

  • So that is true.

  • But frankly, within a company in a code base.

  • You should all be using the same thing anyway.

  • Honestly, I have here a go e have never bought the argument that programmers should be able to interpret the tabs as two spaces if they prefer, or four or eight.

  • I think, frankly, within a code base, you should all just agree to disagree on some standard and stick with it.

  • The reality is spaces avoids exactly the silliness that we just encountered, where there's actually mixed tabs in spaces and you can't tell.

  • How about you?

  • What's your personal opinion on two versus Four Spaces?

  • Because two is very common in the Java script world.

  • Yeah, it is just because I've still used for certainly for CS 50 and for learning code, I think it's just a little more.

  • It's twice is obvious, and two spaces is eight is excessive.

  • You shouldn't even be.

  • No one should be talking about 86 is weird, too is OK Ht melon more okay with it, but for code, honestly, I think four is reasonable and honestly, now that you have promises and a sink and other such techniques and Java script, and don't worry about call back hell like you don't really need to worry about indentation as much.

  • You're sure?

  • I think I think four.

  • Fine.

  • I think I prefer four versus two.

  • CS 51 TV show.

  • Nice.

  • We gotta check that channel.

  • Can I get an upgrade?

  • Yes.

  • Tune in tomorrow to see a 51 dot TV.

  • Uh oh.

  • There's somebody before you mentioned.

  • Is that the open computer?

  • Nice.

  • Thanks for catching that.

  • Norris says Thanks.

  • He's 50.

  • I know what to do with my life now.

  • Smiling.

  • It's a very sweet comment.

  • Pretty simple codes is the duck, though.

  • Yeah, the code is simple.

  • But even regardless of simplicity, though, I think the documentation having documentation is key.

  • No matter how simple your your code is ultimately, um, j only seven.

  • Is this the first report you reviewed?

  • Yep.

  • The 1st 1 we've got to get to our 2nd 1 How many reports ever gonna cover as many as we could get in an hour?

  • Probably three or four.

  • Um, Adam Man, teens saying just got here.

  • Code reviews.

  • Very thorough.

  • Good.

  • Happy.

  • Happy.

  • You think so?

  • Variable names are inconsistent.

  • Camel case versus snake case.

  • Oh, Did we miss it.

  • Thank you.

  • Very good catch.

  • Yeah, I'm seeing some scouts.

  • Can't snake case here with underscores but indeed Campbell case up here atop its very own dramatic and python to you snake case.

  • There was a case that was made to me as I was doing some documentation about older python modules that like re, for example, I think it was or one of those other modules it might have been.

  • It might have been an XML library.

  • Whatever part of the core standard library was written in Camel case and people were saying, If you're using that library, it's idiomatic to stick with Camel case.

  • Despite the fact that python as a whole, it's idiomatic to snake case.

  • It's a bit of a weird ecosystem, but I think it's probably safer to use snake case always.

  • Um, yeah, I think a couple more comments Hello from India says kill stealer 10 80.

  • Wait, I think we missed one.

  • Why are we not talking about Fibonacci?

  • Indentation were not So how do we ban someone?

  • Oh, lasagna was saying this guy's a walking in seconds.

  • That's all you there.

  • Thank you.

  • That's you.

  • Oh, in any seal saying thanks for the comments will definitely make some of the changes.

  • You guys.

  • Awesome.

  • Thanks, Eric.

  • Yeah, we made every all of what we're saying, although we mean, is definitely just to help you improve.

  • It's not meant to crap on your coat.

  • All we promise.

  • Thank you very much for submitting.

  • Were happy.

  • Happy?

  • No, this is great.

  • Great place to start.

  • Um, okay.

  • Go away.

  • The logging python written and Campbell case Andi, Jason G from Greece hasn't been a long time.

  • One of our original.

  • Hello, Greece.

  • Hello, India.

  • I saw as well.

  • Very nice.

  • Cool.

  • All right, so do we have here.

  • Let me, uh Okay, so on this thing, there's let's go back to I think we looked at a p I.

  • We go do it.

  • Okay.

  • Melee.

  • Yeah.

  • I mean, I think that's it.

  • We could keep going a little deeper, but I think we're okay.

  • I can't if we really want to nit pick convention would be the lower case, the MD.

  • Another case to read me for whatever reason, but that's clearly renders.

  • Okay, fine.

  • And get help.

  • Should we take a look at another one?

  • Yeah, let me go ahead.

  • Thank you.

  • again.

  • Toe salt.

  • Eric.

  • Thanks.

  • I appreciate it.

  • All right, so we're gonna go back to another.

  • Another one.

  • Here, let me go back through our submissions here real quick, and let's gets the next u R L Next up, Indra.

  • Ready five.

  • Indra Ready?

  • Five.

  • Cool thing.

  • This is a, um, rock paper scissors game.

  • Nice.

  • So I from what I remember, it's a fairly short rib.

  • Oh, it's not.

  • It's not too long.

  • But there were a few points that I definitely thought of when I was reading it, and I think it's actually a gist.

  • So I'm gonna go back to our our computer here and adjust for those unfamiliar is just like a paste been.

  • It's like a quick and dirty way of pasting and syntax highlighting code for other people to see.

  • Really?

  • Yeah.

  • Yeah.

  • Nice way.

  • It's specific to get home, get enough to share whole Rebo.

  • Just a just a single thing.

  • Yeah, All right.

  • Well, I already like how injury went ahead here and have this has space after the import.

  • That would be python IQ, if you will, Uh oh, list.

  • I don't know.

  • Maybe ordered list.

  • If it is an ordered list.

  • It really doesn't need to be called ordered lists, cause lists are ordered in Python.

  • Of course, you can't call it list because list is a class in Python.

  • So I think here I mean, really gonna start nitpicking quickly.

  • Tell me what these are, right?

  • Like, I don't even know what they are in the game.

  • Rock paper.

  • It's like the moves or the symbols.

  • I would give it something semantically meaningful.

  • Yeah.

  • Describe what the data is not how you're storing and probably call it move.

  • Underscore type something move, types, types I would like.

  • Yeah, absolutely.

  • Another thing that I wish we had.

  • And I wish more repos did.

  • This is having the doc string.

  • And if we have enough time, I might get to a couple of examples that have great doc String is used in them.

  • But this one doesn't have doc strings.

  • So game we're not sure what it takes.

  • What it returns, what it does.

  • Just that we see that it says gameplay and result.

  • But that's way too general of ah statement.

  • It doesn't sort of encapsulate the flow of the function.

  • I don't know.

  • You know what the start middle and end is, you know, and it's a long function.

  • This function is basically the entire entire script here.

  • I think I think so.

  • In fact, I'd kind of propose we pause because I don't know what the game function is.

  • We should probably scroll down and see what's going on.

  • Sure.

  • So he see another function here.

  • Computer.

  • See Player, See and main.

  • So funny enough, I would argue that the whole point of Maine is to be, indeed the main function and the value of giving it a name is generally to put it way up top because you already made us think you made me scroll through all of your code.

  • And yet all I care about his mane and ironically, game is the first function called.

  • So that's a good thing we could go back up.

  • But if you're going through these hoops and python of actually checking whether the name of the file is underscore, underscore made and you're defending defining a main function.

  • Put that main function up top because this way, all of your other functions air helper functions or more generally speaking abstractions that you don't need to look at unless you care to, but main you presumably do care about.

  • I agree.

  • Yeah, if you if you see at the very beginning instead of us trying to parse this wood.

  • I don't remember the name of the function off hand, the very first function.

  • But now we know that we should indeed work our way backwards and look a game first.

  • Getting over all encompassing view of the application.

  • Indeed, and I would comment to these kinds of comments while in the spirit of commenting rigorously are not that helpful because Maine is, by convention, the main part of your program.

  • So it's not really added anything.

  • And so, honestly, I've struggled with this because I comment all of my functions one writing code.

  • But I never really know what to write for Maine, and I just settled on writing nothing for Maine when at least it's obvious that that's the main point of the program.

  • Definitely don't write main part of the program.

  • You're just now you're just wasting the readers time like don't repeat yourself kind of the dry prints in the context of comment.

  • Indeed, so let me go ahead and stroll back up to what's going on here, and it looks like this game plays rock, paper, scissors, You know, why don't we go ahead and play this game real quick on our human hands for those unfamiliar but in other communities?

  • All right.

  • So you can either be a rock by holding your fist up paper by holding it flat or scissors by holding it like this.

  • And let's do two out of three and we'll explain as we go.

  • Who's winning and why, Sure.

  • All right, so we want to go rock paper sitting, and then the 3rd 1 is where you know, your rock paper scissors.

  • Shoot.

  • Oh, is that how you do?

  • How do you do?

  • In California, we did rock paper, and in the 3rd 1 is rock, paper Scissor.

  • You say, Say scissors, but it's no you got to say shoot.

  • Okay, fine.

  • We'll do rock.

  • All right, We'll do it.

  • East Coast style.

  • Rock, paper, scissors.

  • Shoot.

  • Okay, but we were both paper, so nothing happens.

  • It's a tie, so no one gets a point.

  • Okay?

  • Paper is just the same thing in this paper.

  • Rock paper, scissors.

  • Shoot.

  • Tried to trick him.

  • Okay, here we go.

  • One more time.

  • Rock, paper, scissors shoot.

  • All right, so Colin was rock rocks obviously break scissors.

  • So Colton gets the point and so forth. 00:36:

All right.

字幕與單字

單字即點即查 點擊單字可以查詢單字解釋

B1 中級

我們審查你的源代碼!- CS50在Twitch上,EP.32 (WE REVIEW YOUR SOURCE CODE! - CS50 on Twitch, EP. 32)

  • 0 0
    林宜悉 發佈於 2021 年 01 月 14 日
影片單字