From the course: Refactoring with GitHub Copilot
The impact of ai on refactoring - Github Copilot Tutorial
From the course: Refactoring with GitHub Copilot
The impact of ai on refactoring
Not only can AI speed up refactoring, AI can help uncover refactoring ideas you have not noticed. Always start by asking, how can I refactor this? You don't have to agree with or implement any of the responses, but it will influence your thinking. I'd also ask, how can I improve code readability? This is a great trick for code you've just written. You've refactored before your first pull request. Not surprisingly, it suggests adding comments, consistent formatting using constants separating concerns. Another thing you can ask, am I mixing abstraction layers? There will be an inherent bias Copilot will look for in the context, something that justifies a positive response here. Regardless, it may give you something to think about. Unsurprising, in here, we have this process order which calls apply shipping, calculate total price, validate order. Process order does seem one abstraction level above the functions that it's calling. Another one I like to ask is, is this code DRY? I might also ask things like is this code secure when it deals with transactions of any sort? Another thing I like to do is ask for a code review. Of course, it will only review the open file and not everything in your PR. At the time of writing, there's a waitlist for Copilot to review entire PRs on GitHub. It'll be interesting to see how that impacts my PRs and my reviews. Finally, the big warning and reminder, you and you alone are responsible for your code. As a professional in this industry, it's important to remember that AI is a tool, but your name is on the commits in the repo.