Clean Up the Code
So maybe we go a little bit rough on here and take out a lot of stuff to make it just easier to understand. Yeah. First of all, I would take this nested
if statement that’s, like, the quickest and easiest thing to take out. There’s, like, two
if statements on line nine and now on line 11 that just give us different conditions for when
load_model() should raise some sort of error.
So we don’t need this extra nested
if statement. So we have this to happen now, and at this point, we’re kind of like getting to the issue. I think we’ve maybe cleaned away enough that we’re starting to see what is actually the issue with the code in relation to the question that this person had. And at this point I get the feeling, “Aha!
01:49 It definitely took me a while to even just see that from the original state of the code. I like your little “aha!” moment there because that’s exactly the moment that you want to have right away.
02:00 You want a person to look at your code and be like, “Aha! Okay, so I see that there is a mix-up of those things. Let me help you fix that.” So basically, all the work that Martin has done so far is work that you should put into your question, but that not should your helper have to do until to get this “aha!” moment to actually help you. Yeah. It’s really nice that this happened.
02:26 So this is now the point that we actually can go into the refactoring and into, like, helping what’s going on there. But before we do, I, I want to address one last thing, which is important to note.
We kept the
load_model() one because it was a descriptive name. One thing why it might make sense to also adjust your code for your helper is not to make it just more generic, but also to remove any names that might be a security breach if you share them with the Internet. So for example, you write your code in your company, and you are—by contract—not allowed to share code that you write while you are working for this company.
03:18 So you have to try to abstract this question and the variable names and the function names as good as possible to make the example generic and not expose any information from within your company.
Become a Member to join the conversation.