Reusability
00:00 Quality code is reusable, meaning it uses parameterized and generic functions so the same logic works with any input. Let’s look at an example. You need to calculate the total price with tax in three different parts of your code.
00:16 Do you think this is a reusability issue? Well, you could technically get each product and add 10% of its value every time, like you’re doing here for A, B, and C, but then you’re just repeating yourself over and over again. So yes, this is a reusability issue.
00:34
What you could do instead is use a parameterized function so you can reuse it later on, like the function calculate_total here that gets price and tax_rate and then returns the total price, including the tax rate.
00:49 And that’s reusability for you. Okay, but here’s a challenge for you. This is a function that takes a list of IDs and returns the IDs that appear more than once. Review its functionality, readability, and efficiency, and then improve it where necessary.
01:07 In the next lesson, you’ll find an interactive exercise where you implement the things you learned so far practically.
Become a Member to join the conversation.
