00:0.04 Let's do a quick flyover of all the main concepts around re factoring and PyCharm we've
00:4.31 covered and actually introduce one or two more that we didn't take the time to do
00:8.76 as a demo. So remember we have the re factoring menu,
00:12.01 we can get to all sorts of good things.
00:14.03 I would say extract and introduces probably where you're gonna be most as well as rename
00:18.17 But there is the more specialized ones like pull members up,
00:21.76 push members down and so on.
00:23.94 The way that I typically get to refactoring is using the refactor this the
00:27.7 first thing in this menu which on Mac OS is ctrl+t.
00:30.23  So highlight the code or put the cursor on the thing you want to
00:34.55 rename. Refactor or whatever.
00:36.65 Press 'ctrl+t' or your OS is hotkey.
00:39.63 And then after the races, the first thing that we looked at was renaming.
00:44.46 Remember having a good name is super important and it can help avoid using comments as
00:49.48 deodorant for code smells. So good name often tells you what's happening in the code
00:53.67 without the need for comments here.
00:55.64 Maybe this was just for CN creatures,
00:58.52 we want to make it more obvious.
00:59.61 So for creature in creatures, you notice we're renaming in the for loop location and
01:5.19 it's changing throughout this whole file where the creature or see what's being used before,
01:11.04 if we wanted to change the way the game played.
01:13.0 So not just wizard could attack,
01:15.0 but like a toad could emerge from the forest and surprise attack us.
01:18.63 We'd want to use the attack functionality built into wizard,
01:22.13 but make it available to all creatures.
01:23.99 So we could use pull members up over here to attack,
01:27.54 say pull members up and say we'd like to push this up to the creatures so
01:30.8 all creatures have the ability to attack,
01:32.63 not just wizards, we wanted to reverse that,
01:36.0 we had some functionality that was in creature,
01:38.06 but we want a specialised version in each class,
01:40.88 we can push members down and we can check it off like that and then every
01:45.01 drive class will get its own copy,
01:46.84 which we can then specialize. I love the extract variable feature,
01:52.47 it helps with debugging, it helps with understanding and so on.
01:55.95 We talked about this, get defensive role,
01:57.77 we said, you know, this is not great,
01:59.89 it's not entirely clear what's happening here.
02:2.84 So we could extract this out as a variable and then we'll let us see it
02:6.41 in the debugger what we did is broken into multiple variables,
02:9.39 so we could actually see each little piece but still this will help us in our
02:12.58 debugging if we decided, you know,
02:15.32 that's not the way we wanted to go.
02:16.76 Actually, there's no real reason for this variable here,
02:19.22 let's just return that expression itself.
02:22.02 We can do the reverse of extract very but we can in line a variable and
02:25.98 now we have just this like,
02:27.15 clean one line feature. Another thing that's really cool is we can extract a constant
02:33.44 constant in python, it's not a real language way to enforce it,
02:37.98 but the convention is that they're all caps.
02:40.74 So if we go over here and we try to extract this 12,
02:44.49 it's a constant. It's going to put it at the module level and then we
02:47.25 can give it a name like the dye sides.
02:49.22 Like how many sides does my dye have this one,
02:51.46 it's a 12 sided one. This will let us easily change this one.
02:55.45 Constant that will apply to the rest of the program,
02:57.99 highlight the 12. We? Refactor and say create extract the constant and go
03:2.24 over here and then it's going to replace the usage of the 12 wherever we were
03:6.46 using it with the constant. We also saw that we might want to have some
03:11.97 kind of constant become configurable. That could be passed into a method.
03:16.12 Something that's not a variable at the moment,
03:17.8 but on an argument, what could be?
03:19.66 So in the for example, we have the seven.
03:21.54 That was our modifier. We can go over here and do an extract parameter.
03:25.21 It will create a modifier parameter,
03:27.67 give it the default value. So by default it behaves the same.
03:30.73 But now it's configurable. This is really handy way to add more extensive bility and
03:36.06 more flexibility to your code. Here's one that we did not cover if we're going
03:41.75 to create a python package, there's a certain structure that it has to have.
03:46.78 There's a directory name. That's the name of the package And in there there's a
03:50.19 '__init.py' file and potentially others what we've been working with so far
03:55.11 is just a couple of files that run together and they're technically known as modules.
03:59.52 So notice we have this actors.py,
04:2.34 we can re factor, convert to a python package,
04:5.74 watch what's going to happen here,
04:7.94 This actors right there and all the code in it is going to get changed.
04:11.84 Actors are going to become a directory.
04:14.84 There's going to be a file called __init.py.
04:17.34 And the implementation that was in that module is now moved to the __init.py
04:22.1  By default, we've got this new structure,
04:25.32 which it's not usually required, but if you're working with packages and you need to
04:30.15 install things or especially if you want to ship this over two PyPI or
04:33.6 share it with other programs, having it as a package might be exactly what you need. It's the quick way to do inPyCharm.
