Effective PyCharm (2021 edition) Transcripts
Chapter: Refactoring
Lecture: Your turn

Login or purchase this course to watch this video and the rest of the course contents.
0:00 I hope you got a lot out of watching me do all sorts of cool re
0:03 factoring it's really one of my favorite parts of PyCharm because it lets you write
0:07 code without too much care for how it's put together or being really careful.
0:12 And then, as you understand it better,
0:14 just quickly apply these things that make it better Now,
0:17 it's your turn to do some refactory.
0:21 Remember that podcast app that we had,
0:23 the one that would download and show the titles.
0:25 Well, we're going to take that code again and I've contorted it to have some
0:29 problems or code smells and you're gonna use re factory and to freshen it up,
0:34 don't be at the top. You can see there's this smelly podcast,
0:37 it's smelly because there's lots of code smells to make sure you run it before you
0:41 get started, it's gonna need a virtual environment with requests installed.
0:45 Now, there's a couple of code smells to pay attention,
0:48 particularly to and I'm showing you where this is happening.
0:52 So just go through all the notes here and follow along.
0:55 The first one is a large or long method smell.
0:58 This one is just piece function that's just got too much going on and needs to
1:02 be broken into pieces. So take that run with it the next one.
1:08 This is a little bit of a deviation from the traditional code smells.
1:11 If you think back to the languages that Robert C martin and kept back in.
1:16 Those folks who came up with code smells,
1:18 the languages they were using were purely object oriented,
1:20 basically small talk and C++.
1:23 So over there, one of the code smells is a large class that has too
1:27 much going on, but in python often classes that are just static.
1:32 Well, those are basically modules,
1:33 Right? So we have what I'm coming up with as a name here is a
1:36 large module smell. So there's another one here where we might want to break our
1:39 code up into smaller pieces across different files.
1:44 And finally, there's something I'm calling variable absence.
1:47 So we've got this result that looks like this.
1:50 Well, what is this? We don't know.
1:52 But if we could name each piece,
1:53 maybe we could make a lot more sense out of it.
1:55 So once you make all these refactoring,
1:57 just verify that your code still runs and then it works the same as when you
2:01 started. But of course it should be cleaner,
2:03 easier to understand and easier to extend. Have fun.