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 I spoke about analysis paralysis. This is the symptom or behavior where you have to have everything planned out exactly right
0:11 before you get started. For some people this is no problem planning is not their thing Others it's a really big problem
0:17 and one of the takeaways I want you to get from going through this whole exercise is realizing that I didn't build it right the first time
0:23 but we still ended up with some really nice looking code. So we can refactor as we learn. If you're unfamiliar with this term
0:31 it just means changing the structure of your code how it works, maybe the data structures you're using but from the outside it should look like
0:38 it's doing the exact same thing and that's what we did in this check for winner part here. The first thing that we're doing is
0:44 we're constructing all the sequences that we have to check and then we're checking them. We did it in actually, in even worse
0:51 and more egregious way before but here we're doing two things we're constructing the winning sequences and then we're going through them.
0:59 In that part above, it's not entirely clear what's happening so we move that into its own function and if you're using PyCharm
1:05 you can highlight it, right click and say refactor and you can choose extract method and it'll just go in automatically bring up the style log
1:12 and write another function for you. So the new version looks like this and here this is PyCharm calling the function that it wrote down below.
1:21 So this is really, really cool and a very nice way to just get started, get more familiar with the problem
1:26 and then apply the tools to automatically make it better as you see those opportunities.