1
00:00:04,500 --> 00:00:09,220
Alright, so how did you get on? Did you spot
the places in escapechar.py

2
00:00:09,220 --> 00:00:13,379
where the code doesn't conform to the style
guide? Well, the three problems are with

3
00:00:13,380 --> 00:00:19,940
the names of our variables. Now, if we go and
scroll up and look on line one up here,

4
00:00:19,940 --> 00:00:24,720
I used camel case for the name split
String.That's the convention in Java, for

5
00:00:24,720 --> 00:00:27,560
example, but we should avoid doing that
in Python.

6
00:00:27,560 --> 00:00:30,880
It's called camel case, by the way,
because the large capital letters

7
00:00:30,880 --> 00:00:34,820
resemble the humps of a camel. Camel case
reflects the shape of the word, when you

8
00:00:34,820 --> 00:00:38,040
include capitals in it.
Alright so that's the first one.

9
00:00:38,040 --> 00:00:43,940
The next is tabbedString on line 4, and the
third one is anotherString down

10
00:00:43,950 --> 00:00:49,830
on line 14. Now those three variables
appear on six lines of the code; lines 1

11
00:00:49,830 --> 00:00:57,570
& 2, again on lines 4 & 5, and lines 14
and 19. Now it wouldn't be too hard to

12
00:00:57,570 --> 00:01:02,100
change them in this short program, but in
a larger program they could be appearing

13
00:01:02,100 --> 00:01:04,920
all over the place.
If you forgot to change one of them, or

14
00:01:04,920 --> 00:01:09,330
made a typing error, you'd cause an error
in the code. And that's not good, and it's why

15
00:01:09,330 --> 00:01:13,590
you shouldn't refactor code just to
conform to a style guide. But I'm gonna

16
00:01:13,590 --> 00:01:17,430
break that rule here, because I want to
show you how your IDE can make that a

17
00:01:17,430 --> 00:01:21,570
lot easier and safer. What we're going to
do is refactor the code, to make it

18
00:01:21,570 --> 00:01:28,440
comply with PEP 8. Refactoring code means
changing its structure, without changing

19
00:01:28,440 --> 00:01:31,530
its behavior.
Refactoring might change how the code

20
00:01:31,530 --> 00:01:35,860
does things, but it doesn't change what it does.

21
00:01:35,860 --> 00:01:40,079
Alright, so in IntelliJ and PyCharm, I
can right click on splitString and I'm

22
00:01:40,079 --> 00:01:44,310
going to do that on line one. So from the
context menu that appears, I'm going to

23
00:01:44,310 --> 00:01:49,860
choose Refactor, then Rename. As you can
see, that popped up a dialog where we can

24
00:01:49,860 --> 00:01:53,610
change the name of the variable. I'm
gonna change it to conform to the

25
00:01:53,610 --> 00:01:59,780
guidelines; split_string,
instead of a capital S like we had.

26
00:01:59,780 --> 00:02:04,860
Click on the Refactor button, and all
occurrences of splitString are renamed.

27
00:02:04,860 --> 00:02:09,199
We can see, in this case, it's been changed on
lines 1 & 2. I'm going to do the same for

28
00:02:09,199 --> 00:02:20,340
tabbedString on line 4. That should be
tabbed_string.

29
00:02:20,340 --> 00:02:24,600
Then we're gonna do the same again for
anotherString, right click, Refactor,

30
00:02:24,600 --> 00:02:30,900
Rename, and that, of course, should be
another_split_string

31
00:02:30,900 --> 00:02:37,470
I say, of course, but you get
the jist there. Okay, so there's the 3

32
00:02:37,470 --> 00:02:43,560
things changed, and you can see that both
lines 14 and line 19 are changed there.

33
00:02:43,560 --> 00:02:47,840
Now most modern IDEs have a feature that
allows you to rename things in your code,

34
00:02:47,840 --> 00:02:51,380
and that's much safer than doing it
manually. As I said, if you miss one or

35
00:02:51,390 --> 00:02:55,380
make a typing error, you'll break
the code. Make sure you test your code

36
00:02:55,380 --> 00:02:59,560
after refactoring it. Run the program to
make sure it still works.

37
00:02:59,560 --> 00:03:03,850
Alright so the code in this course
will follow the PEP 8 guidelines, most of

38
00:03:03,850 --> 00:03:07,690
the time. I'm re-recording the videos
for this course, and some of the earlier

39
00:03:07,690 --> 00:03:11,530
examples were written a long time ago.
You might find that some of them don't

40
00:03:11,530 --> 00:03:14,500
follow PEP 8.
You'll also find code in the Python

41
00:03:14,500 --> 00:03:18,610
libraries, and elsewhere, that doesn't
follow those guidelines either. The code

42
00:03:18,610 --> 00:03:21,520
that you write should follow the
guidelines, and I'll refer you back to

43
00:03:21,520 --> 00:03:25,780
them, as we cover various new Python
features. Now there's one more thing that

44
00:03:25,780 --> 00:03:30,300
I want to cover, and we'll look at that
in the next video.

