You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: your-turn/04-refactoring/readme.md
+10-10
Original file line number
Diff line number
Diff line change
@@ -6,19 +6,19 @@
6
6
7
7
We are going to use a project located in the same folder as this file called `smelly_podcast` (as in code smells). This is code we used to download some things from Talk Python To Me.
8
8
9
-
It has been contorted to have many problems or [code smells](https://en.wikipedia.org/wiki/Code_smell). We'll use refactoring to freshen this up.
9
+
It has been _contorted_ to have many problems or [code smells](https://en.wikipedia.org/wiki/Code_smell). We'll use refactoring to freshen this up.
10
10
11
-
**Note**: Before you first run this app, you'll need to make sure you have `requests` installed via pip.
11
+
**Note**: Before you first run this app, you'll need to make sure you have a virtual environment active and `requests` installed via pip.
12
12
13
13
## Large method *smell*
14
14
15
-
Look at `program.py` and notice this somewhat complex app is actually just one big method, yuck. We'll use several refactoring to fix this.
15
+
Look at `program.py` and notice this somewhat complex app is actually just one big method, yuck. We'll use several refactorings to fix this.
16
16
17
17
First, notice the section with the comment **"SHOW THE HEADER"**.
18
18
19
19
Take that small piece of code and make it its own method. Highlight the lines, choose **Refactor > Refactor this**.
20
20
21
-
Choose method and name it `show_header()`. Notice it was created below and called from your current location.
21
+
Choose method and name it `show_header`. Notice it was created below and called from your current location.
22
22
23
23
After each refactoring, run the program to make sure it still works!
24
24
@@ -45,7 +45,7 @@ Accomplish this by refactoring the `url` variable and choosing *inline variable*
45
45
-----------------------
46
46
47
47
48
-
Next up, we have **"GET SHOW ID RANGE"**. We want a method that will return both the `latest_show_id` as well as the `oldest_show_id`. This is interesting because you'll see that PyCharm knows about tuple packing/unpacking on method calls. Highlight both:
48
+
Next up, we have the **"GET SHOW ID RANGE"** section. We want a method that will return both the `latest_show_id` as well as the `oldest_show_id`. This is interesting because you'll see that PyCharm knows about tuple packing/unpacking on method calls. Highlight both:
49
49
50
50
```python
51
51
latest_show_id =max(episode_data.keys())
@@ -80,7 +80,7 @@ Let's move the data container and type first. Highlight these two lines and "mov
80
80
Episode = namedtuple('Episode', 'title link pubdate show_id')
81
81
episode_data = {}
82
82
83
-
**Note**: If you have **not** opened just the `smelly_podcast` folder as the project root, you will need to market the folder `smelly_podcast` as a **sources root** for that to work. It should be blue like this:
83
+
**Note**: If you have **not** opened just the `smelly_podcast` folder as the project root, you will need to market the folder `smelly_podcast` as a **sources root** for that to work. It should be **blue** like this:
84
84
85
85

86
86
@@ -125,7 +125,7 @@ def main():
125
125
126
126
## Variable absence *smell*
127
127
128
-
Variable absence is something I just made up. There doesn't seem to be an agreed upon smell for it, but I'm sure you've seen it. Here's the deal. What does this mean:
128
+
**Variable absence** is a smell I created. There doesn't seem to be an agreed upon smell for it, but I'm sure you've seen it. Here's the deal. What does this mean:
129
129
130
130
`result = 7 * max(inputs) * (match / count)`
131
131
@@ -134,14 +134,14 @@ Let's try this one instead.
134
134
```python
135
135
largest_cell =max(inputs)
136
136
ratio = (match / count)
137
-
DICE_MULTIPLIER=7
137
+
DICE_MULTIPLIER=7
138
138
139
139
result =DICE_MULTIPLIER* largest_cell * ratio
140
140
```
141
141
142
-
Well, you'll still have to use your imagination. But it seems to do with a board game, rolling dice, etc. Why is one clear and the other isn't? The expression is computing many values inline. Once named, they are much clearer what they are and how they are combined.
142
+
Well, you'll still have to use your imagination. But it seems to do with a board game, rolling dice, etc. Why is one clear and the other isn't? The expression is computing many values inline all at the same time. Once named, the pieces are much clearer.
143
143
144
-
Open `service.py`. Notice this line `dom.findall('channel/item')` appears multiple times. It represents the `items` from the RSS feed.
144
+
Open `service.py`. Notice this line `dom.findall('channel/item')` appears multiple times. It represents the `items`elements from the RSS feed (part of the RSS 2.0 spec).
145
145
146
146
Make a variable for it by highlighting either single expression, choose refactor > variable. Name it something like `items`. Choose 2 locations!
0 commit comments