Effective PyCharm 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 factoring it's really one of my favorite parts of PyCharm because it lets you write
0:08 code without too much care for how it's put together or being really careful. And then, as you understand it better,
0:15 just quickly apply these things that make it better Now, it's your turn to do some refactory. Remember that podcast app that we had,
0:24 the one that would download and show the titles. Well, we're going to take that code again and I've contorted it to have some
0:30 problems or code smells and you're gonna use re factory and to freshen it up, don't be at the top. You can see there's this smelly podcast,
0:38 it's smelly because there's lots of code smells to make sure you run it before you
0:42 get started, it's gonna need a virtual environment with requests installed. Now, there's a couple of code smells to pay attention,
0:49 particularly to and I'm showing you where this is happening. So just go through all the notes here and follow along.
0:56 The first one is a large or long method smell. This one is just piece function that's just got too much going on and needs to
1:03 be broken into pieces. So take that run with it the next one. This is a little bit of a deviation from the traditional code smells.
1:12 If you think back to the languages that Robert C martin and kept back in. Those folks who came up with code smells,
1:19 the languages they were using were purely object oriented, basically small talk and C++.
1:24 So over there, one of the code smells is a large class that has too much going on, but in Python often classes that are just static.
1:33 Well, those are basically modules, Right? So we have what I'm coming up with as a name here is a
1:37 large module smell. So there's another one here where we might want to break our code up into smaller pieces across different files.
1:45 And finally, there's something I'm calling variable absence. So we've got this result that looks like this. Well, what is this? We don't know.
1:53 But if we could name each piece, maybe we could make a lot more sense out of it. So once you make all these refactoring,
1:58 just verify that your code still runs and then it works the same as when you started. But of course it should be cleaner,
2:04 easier to understand and easier to extend. Have fun.


Talk Python's Mastodon Michael Kennedy's Mastodon