3 ms·
One of the biggest boilerplate time savers for me is I have a service that maps HTTP requests to some specific class. I can paste an example HTTP request into a
by gamegoblin 4y ago
One of the biggest boilerplate time savers for me is I have a service that maps HTTP requests to some specific class. I can paste an example HTTP request into a comment like:
/*
<http request here>
The well-type class representation of this is:
*/
And then it spits out a totally sane and reasonable class. In this file I already have 10+ classes already defined and manually touched up by me to rename some things, remove some fields, etc. So every time I add a new one, Copilot takes into account the previous examples and each addition requires less or no manual tweaking.
- joshstrange 4y ago100%. Most of my calls to the backend literally only need me to type the function name `fetchItems()` and CoPilot correctly uses my axios instance, set the return type to be my base API response wrapper, sets the generic in my base wrapper to be `IItemDTO[]` (it guesses this correctly probably 90%+ of the time), and even shoves the response into a Vuex store just like I would have done (same deal, guesses right about 90%+). It's not like it's a ton of work to do that myself but normally the way I would accomplish it is to copy an existing function, change the return type, change the url, change the Vuex store it puts the data into but with CoPilot it handles that perfectly for me the vast majority of the time. And if I'm doing CRUD endpoint I don't even have to write the other function names, it will autocomplete the "RUD" part after I write the "C" (and by write I mean I put `createItem(payload: ICreateItemDTO)` or similar and it writes the body of the first function as well). For me it's the perfect blend of "generated code" and "human tending" to get exactly what I need without having to do the repetitive/boring parts. It's been a joy to work with.
- ktzar 4y agoIs it the case that the code you wrote with copilot is much more prone to be refactored.? The usage you describe sounds like a lot of repetition and hard to update if any of those requirements (Vuex store for example) change.
- joshstrange 4y agoThat’s not been my experience. I mean the code is no harder to refactor than anything else, the code follows the style I prefer (and my linters enforce), if it doesn’t I change it as needed. If I were to switch from Vuex to Pinia it would be the same amount of work with/without copilot. I don’t let copilot generate code without me reading/reviewing it and sometimes making tweaks. CoPilot literally (and I mean that) generates exactly what I was planning to write, if it doesn’t I start typing it my preferred way and often CoPilot then offers a completion in that style. Without CoPilot the code would be virtually the same, so refactoring isn’t impacted one way or the other.
- dnut 4y agoIf you find yourself generating so much boilerplate, it's probably a better design and more enjoyable to craft a single reusable abstraction than it is to rely on a glorified copy and paste tool to create a mess of redundancy.