Improving maintainability
Another interesting use case is using GitHub Copilot to help you improve the maintainability of your code. So what are some things that you can do to improve the maintainability of your code? Here’s a list:
- Improve the naming of variables, functions, classes, etc.
- Separate concerns: For example, separate business logic from presentation logic.
- Remove duplication: Especially in large codebases, you’re likely to find duplication.
- Improve readability: You can improve readability by, for example, using comments, docstrings, event tests, and more.
Let’s start with a codebase and see how we can improve it. Here’s the code:
def calculate_total(cart, discounts):
# Define discount functions
def three_for_two(items):
total = 0
for item in items:
total += item.price * (item.quantity - item.quantity // 3)
return total
def christmas_discount(items):
...