00:0.0 Let's look at some code we haven't touched yet.
00:2.57 So, here is a little wizard project and it has a couple of classes.
00:7.43 Let's go ahead and compress this down a little bit you can see.
00:11.11 So we've got a wizard a little higher.
00:13.95 We have a creature object a class.
00:17.14 Some behaviors you can create one of them and it can do this.
00:20.08 Get defensive role is going to be a little role playing dungeons and dragon type game
00:23.96 And then there are other more specialized things in here.
00:27.49 Like there's a wizard that derives from creature,
00:29.83 there's a small animal, there's a dragon and so on.
00:34.34 Now let's just run it real quick so you can see what it does.
00:37.04 So it has this cool little header here that looks like a dragon.
00:40.18 The wizard battle app. And you can see it's in the smoky breath or the
00:44.23 fire of the dragon. And turner says a level a tiger of level 12 has
00:49.01 appeared from a dark and foggy forests.
00:51.18 And you have some options here.
00:52.24 We could look around, we could attack it.
00:54.94 We're pretty strong so we can attack it and look the Wizard gained attacks the tiger
00:58.65 We rolled 900. The tiger rolls 108.
01:2.14 The wizard has handily triumphed over the tiger.
01:5.34 All right, So this is what the program does.
01:6.95 We can also look around and we can run away and we can quit.
01:12.14 So what we want to do.
01:13.84 Not so much play the game is we want to look around and see where are
01:17.0 some code smells. There are some things that we might be able to make better
01:20.0 And let's get started at a real simple thing over here,
01:23.58 this is the start up of the whole program.
01:26.0 We do this big print statement here,
01:28.44 notice here's the dragon text, A huge welcome to the dragon game on the wizard
01:35.73 game with the big fiery breath writing set up here.
01:38.54 It's a bunch of text and we're just printing that out and then we'd run the
01:42.52 game. Well this this formatting just right in line in this main method.
01:47.9 It's not beautiful, is it?
01:49.14 It would be nice if we could just real quickly read what's happening main like,
01:52.74 oh, we're gonna show the header that we're going to run the game loop,
01:55.64 but that's not what's happening here.
01:56.81 We've got to figure out what does this print mean,
01:58.42 Why is it all here? And then we run the game loop.
02:1.34 So the first thing we want to do maybe is to make this its own function
02:5.84 with its own name. So instead of saying,
02:9.84 we'll show the header as a comment.
02:13.71 Remember this is a bit of deodorant for this.
02:16.38 Not so great code for this code smell.
02:19.94 What would be better is to just make it more clear with some kind of 
02:23.57 refactoring and that brings us to the refactoring features.
02:26.76 So there's a couple of ways to get to them.
02:28.53 I almost always use this first one 'Ctrl+t' on mac Os.
02:32.62 And it's something else on the others.
02:33.79 You will see in a moment what that is and what I would like to do
02:37.1 is just go highlight the code and say,
02:39.29 well what can I do to make this better?
02:41.64 But you could be more specific.
02:43.87 Like if we were on a variable,
02:45.21 we could rename it or a function,
02:46.77 we could change the signature, we could introduce a variable,
02:50.03 a field, a parameter object.
02:52.22 Remember I talked about the function that takes too many arguments.
02:55.03 This is one of the proposed fixes.
02:57.94 We create a method and so on.
03:0.14 We can also not with what I have selected,
03:2.58 but in general we could reverse that.
03:4.3 We get in line a variable in line of function and just make it happen right
03:8.15 there. I said this is this parallel refactoring and the anti re factoring and
03:14.01 both times they're useful and they're both useful but at different times.
03:17.37 Right? So you want to keep in mind what we're doing here?
03:20.74 All right. So what we want to do is we want to instead of just
03:23.22 do this, we want to have a function that has a name that kind of
03:26.7 tells us what's happening. So I come down here and get ctrl+t or 
03:29.7 You can see I can get control shift t on windows or Linux.
03:33.05 I'm going to go down here and have a bunch of options.
03:35.94 I know I want to extract a method,
03:37.66 you can see there's a hotkey for it.
03:39.09 Option command M for me, but what I can actually do is I could just
03:43.35 type start typing method until it gets to be a nice short list.
03:47.37 You can actually search or narrow down this list.
03:49.89 We have that, we get this thing here,
03:51.53 it says show header or something like that.
03:55.94 And if we choose it had arguments or if it were using variables that need to
03:59.71 be passed through as an argument,
04:1.0 it would allow us to put them here and change the order and stuff.
04:4.02 But this doesn't have any. So we'll just say go and look at that.
04:8.39 It means the same thing. If we run,
04:9.81 it's going to do the same thing.
04:12.14 See down here is the wizard just like before the wizard text being shown.
04:17.54 But when you read it now def main we'll show the header,
04:21.38 show header. Do you think we need this deodorant here anymore.
04:24.93 Is it smart to leave this comment?
04:26.69 No, because it doesn't make sense to have it when the code is so simple
04:30.46 and it just so clean. It just says show header.
04:33.55 Alright, this is silly. So we'll take it away.
04:35.81 That's one of those cases where the code was acting as deodorant. That's how we can invoke different refactoring tools.
