Find a Balance
00:00 Oh, we still need to change, of course, refactor,
refactor the question and answer.
`validate()`. All right. That is a common thing when you work with comments, that they may need to be updated as well when you refactor your code. But good catch there.
I also really like how you cleaned up the code and, at the beginning, the dictionaries that we now have on line 17 and line 21, so the
"target" and the
"target" were just called
Like, the dictionary was called
X, and the keys were
And you might have experienced this sometimes when you read questions online, where people use
bar as variable names to make the code generic.
And we were saying before that you should aim for making your code generic so people can understand it. But you shouldn’t go too far with it, because it’s always a good idea to call the variables what they are and help your readers to understand what you mean with it. So by naming the dictionaries like Martin did here,
invalid_input, it says what it is.
"target", instead of
"t", as keys, you are also very clear about what the content of your dictionary is.
So if you go generic with your code to share it, which is generally a good idea, don’t take it too far. Still name the variables in a way that helps your readers to understand what they mean. Great. And so maybe one thing we could still do here now is to—because we removed this
except block, but there’s good reason for catching exceptions too—and let’s reintroduce them in the next lesson to show where, if you actually did want to catch the exceptions, where you would do that and how then raising and catching exceptions can play together to be something useful for your codebase. Perfect.
Become a Member to join the conversation.