From the course: Refactoring with GitHub Copilot
Unlock this course with a free trial
Join today to access over 24,700 courses taught by industry experts.
Refactoring data structures - Github Copilot Tutorial
From the course: Refactoring with GitHub Copilot
Refactoring data structures
Behind all your code are data structures. Some are simple, some are complex. Sometimes these tend to get out of hand. I'm going to walk through how I've dealt with these using Copilot. This is a sample data structure. Purposely broke some rules here, but you'll see why as I talk through this. First, I'll identify some of the problems. Details is ambiguous. Why can't these values like price and stock and categories and discount be at the root? Or why can't price and discount be moved to a pricing object? Also, discount is null, but on the second item, it's a string. And on the final item, it's missing entirely. Note that categories is either a string or an array. Back to a string here. I'm going to be pretty explicit to Copilot and I'll see how far I can get. I need to pull stock and categories to the root of each product. Also, categories should always be in array. Copilot suggested a function to change it. I'm actually going to ask it to change the code. I need to change the actual…