00:0.34 One of the most important things that you can focus on is giving the various symbols
00:5.8 in your code good names. Why?
00:8.42 Because if they have good names,
00:10.08 those can be the descriptor for what they actually do.
00:13.59 Remember up here we said show header,
00:16.1 we have this silly comments said we want to show this this series of print statement
00:19.97 shows the header the name is so communicative that we don't actually have to have some
00:25.76 kind of comment. It just says show header game.
00:28.74 Well done. I know this is just going to go around and around while the
00:31.4 game plays. I don't have to go look at it right?
00:33.67 The name is good. But sometimes you write some code then you decide,
00:38.7 you know, a better name has shown up or it's got more complicated.
00:42.46 It has to be more specific.
00:44.14 For example, notice if we click on player at highlights all the use cases of
00:47.62 player like there's player dot name,
00:49.72 there's player dot attack, there's a player,
00:52.35 this is you. But I want to really emphasize that this is the hero of
00:56.27 the game. So I could go over here,
00:58.52 right, click go and say refactor rename or go to the menu up here
01:3.83 and re factor rename. But again,
01:5.92 what I really do is I just hit ctrl+t figure out what I want.
01:8.85 You can see the really common ones right at the top under rename.
01:12.7 I'm gonna give this a new name.
01:14.29 I'm gonna call it hero. Now watch as I type where it's used below all
01:18.94 the places that it's being used,
01:22.24 it's getting updated. Right And again,
01:24.4 remember this is not fancy, find and replace this is understand the abstract syntax tree
01:30.2 and actually make those changes where this is happening.
01:33.84 And we also want to do that for this constant up here.
01:36.55 Let's go and rename this notice.
01:37.93 I don't have to go to the definition.
01:39.39 I can go to a use case here and say rename again.
01:42.84 There's a little bit bigger model wide change.
01:45.61 So we're gonna get this dialogue here and then it's going to do it.
01:50.44 All right, cool. So now our hero does the things that you know,
01:54.9 was the player right? A little more obvious like All right.
01:56.77 This is not just the player,
01:57.81 but the hero. Another thing I noticed this attack method.
02:1.62 We go over to the actors.
02:3.37 You can see the wizard class has this attack and let's imagine that I wanted to
02:9.53 not say attack but fight. Okay,
02:13.04 we can come over here again.
02:14.55 We could do it at the definition or at a use case and say I want
02:19.03 to rename this from attack to fight.
02:22.46 Now there's a few more options here.
02:24.05 I can search in comments and strings.
02:26.27 This is cool because if I have like a doc string or a comment that talks
02:30.57 about the attack method, it's also going to rename that So my comments don't get
02:35.03 broken. You also just full on search and straight text and you can also choose
02:40.38 the different areas that you might want to apply those changes.
02:44.14 Okay, So I'm going to say re factor and it says,
02:46.88 okay, we want to make sure that you know what's happening here.
02:50.08 So you're going to re factor this,
02:53.54 but it's actually being used over here.
02:57.04 All right. So, if you make a change,
02:59.13 if you rename attack, we're gonna have to change the code here.
03:1.68 Now, this is a pretty simple example,
03:4.04 But imagine this is being used in 50 different places across multiple files.
03:8.91 Notice that we did the renaming game core.
03:11.84 It's changing that in the actors and then fixing up game core where it uses the
03:16.99 wizard dot whatever attacks going to be.
03:20.04 All right, it looks good to me.
03:21.21 So, we're gonna go ahead and click do we factor and notice hero now fights
03:25.68 It doesn't attack it fights and over here also.
03:30.34 Right, let's just run it one more time to make sure it's still working.
03:33.61 Love our little character there. Let's have it well,
03:37.04 attack. So, the wizard gained off attacks.
03:40.07 The dragon, you the hero role 1 1350.
03:45.4 The dragon slightly has rolled a higher number there,
03:48.8 67,500. We've been defeated and we had to go hide but there's now a toad
03:53.23 we could kill. So we'll do that.
03:55.41 Wonderful. So you can see that we can use the re factoring tools again,
04:0.32 not just on one file, across as many files and places as that codes used
04:5.83 on real projects. This will be many,
04:7.45 many places. And you might forget it's a huge problem.
04:10.75 You could make a change to say I'm gonna replace everywhere.
04:13.29 I see attack with fight. And if there's somewhere you forget,
04:16.36 not that code is broken with PyCharm.
04:18.43 It just understands the whole project and it'll keep that stuff all consistent and give you
04:22.66 a little preview even before you hit go.
04:24.6 So you know what you're in for.
