Python for Absolute Beginners Transcripts
Chapter: Problem solving techniques for writing software
Lecture: Concept: Refactor as you go

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Remember in the beginning
0:01 I spoke about analysis paralysis.
0:03 This is the symptom or behavior where
0:07 you have to have everything planned out exactly right
0:10 before you get started.
0:11 For some people this is no problem
0:13 planning is not their thing
0:14 Others it's a really big problem
0:16 and one of the takeaways I want you to get from
0:18 going through this whole exercise
0:19 is realizing that
0:21 I didn't build it right the first time
0:22 but we still ended up with some really nice looking code.
0:25 So we can refactor as we learn.
0:28 If you're unfamiliar with this term
0:30 it just means changing the structure of your code
0:32 how it works, maybe the data structures you're using
0:35 but from the outside it should look like
0:37 it's doing the exact same thing
0:39 and that's what we did in this check for winner part here.
0:42 The first thing that we're doing is
0:43 we're constructing all the sequences
0:45 that we have to check and then we're checking them.
0:48 We did it in actually, in even worse
0:50 and more egregious way before
0:52 but here we're doing two things
0:54 we're constructing the winning sequences
0:56 and then we're going through them.
0:58 In that part above, it's not entirely clear
1:00 what's happening
1:01 so we move that into its own function
1:02 and if you're using PyCharm
1:04 you can highlight it, right click and say refactor
1:07 and you can choose extract method
1:09 and it'll just go in automatically
1:10 bring up the style log
1:11 and write another function for you.
1:14 So the new version looks like this
1:16 and here this is PyCharm calling the function
1:19 that it wrote down below.
1:20 So this is really, really cool and a very nice way
1:22 to just get started, get more familiar with the problem
1:25 and then apply the tools to automatically make it better
1:28 as you see those opportunities.