Mastering PyCharm Transcripts
Chapter: Refactoring
Lecture: Renaming items

Login or purchase this course to watch this video and the rest of the course contents.
0:01 Here we are in our program, basically in our game loop
0:04 and there's a few things I don't really like about it.
0:06 One, notice up here, we're creating our creatures and then we have our player
0:10 and down through here, our player is doing in attack,
0:13 and then we have information, like output from the player.
0:17 But, I'd like to call this hero, so we know exactly who this is,
0:21 this is the hero of the game, not just player.
0:24 So what we can do is we could go to the refactor menu
0:27 or I like the hotkey, just CTRL T,
0:30 say rename, and now I could just put hero
0:35 and as you type it's just going to change everything.
0:38 So it works like this, when you are renaming parameters
0:41 and local variables and stuff,
0:43 but let's bring in something else.
0:45 Over here we have an attack method on the wizard class,
0:47 let's suppose we want to rename that,
0:50 and it could be used in a hundred locations across 20 files,
0:53 it wouldn't matter, it would totally work.
0:56 So same thing CTRL T, rename and let's call this fight,
0:58 so the idea is the hero is going to fight the active creature.
1:03 Now, this is pretty cool, you can search in comments and strings
1:07 so this would fix like docstrings
1:10 and also you could search in like within strings that are just output.
1:14 So hit refactor and it pops up this little preview thing,
1:18 it says hey we're going to refactor this thing
1:21 and this is where it is used, it will say if hero fight is what is going to happen
1:26 you would see as many locations,
1:28 up here also we have attack is coming from the creature to rename,
1:30 and here's one of its usages, so we hit do it,
1:32 It also changed here, but also, now we have a wizard.fight,
1:37 if we run it, it should work just the same,
1:40 the Wizard has handily triumphed over the Bat, how exciting.
1:44 Okay so the Wizard is doing good,
1:47 our code is hanging together even across these multiple files,
1:49 and I want to emphasize, this is not find and replace, that's not super cool,
1:54 tech search this is abstract syntax tree understanding the entire project,
1:57 that's super cool.