6 ways GitHub Copilot helps you write better code faster

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi and welcome to coding with jesse i'm jesse skinner and today i want to show you six ways that github co-pilot has made me more productive [Music] so the first way is that github co-pilot can finish your patterns for you so let's say you want to have an array of months you can set that up like this and immediately it fills it in well here it has the full month name so maybe you want to have some other pattern like jan dot and there you go automatically it'll finish the pattern for you so for another example of this let's say you're trying to return an object here uh you might have age something like model.getage uh when you have another example like already it's showing me name maybe we have address and as long as your pattern is predictable github copilot is going to suggest probably the right thing for you so the second way copilot has helped me out is it basically finishes my sentences for me so let's say i want some active items here so i have items let's say i'm doing filter and i just pause and it already has it already has a pretty good guess item item active so let's say maybe item.active is not the way i need to determine if an item is active so i will do part of this and then maybe i have status and maybe status equals active is actually correct so i just uh keep typing until copilot predicts the right thing and that usually happens before the end of a line the third way co-pilot helps me is by naming things naming things is a very hard part of programming but copilot definitely makes it easier so in this example already copilot has named my variable item for me based on items which is absolutely correct but it can even do way more than that so let's say i'm making an async function here add book with some params i won't even tell copilot what those params are and already it's suggesting that i have title author isbn let's say i do a weight on query here and already it's suggesting a whole table in sql for me with a table named books author isbn description image price quantity this may or may not be what i want but a lot of the time copilot will make a suggestion and make me think of things i hadn't even thought of maybe i was going to make a books table but didn't think oh yeah maybe i should have an image maybe i should have price in there as well so there's been more than one time when copilot actually suggested a better name for me that i was intending to use and i ended up going with that i figure copilot is pulling from hundreds of thousands of lines of code written by other people and probably the names that those people have picked make more sense than what i'm going to come up with most of the time now you do have to be very careful here because you may notice that copilot has created a security vulnerability here so you shouldn't just insert your values into the database this way you need to escape them first so you need to be very careful about copilot suggestions they aren't always secure and you can't trust it 100 uh so you do still need to be the pilot here copilot is not the pilot you are the pilot and you need to be careful that you're not gonna do something super dangerous with your airplane the fourth way co-pilot helps me out is that i don't need to go to stack overflow that much anymore uh if i want to figure out how to do something let's say you want to pick a random number between a min and a max you can just type a function name like get random number and you give it a min and a max and then you let copilot tell you what that line of code looks like now you do need to be a little bit careful because you don't actually know if this code works so you still have to try it out you still have to test it and see make sure it does what you think it should but it definitely saves you from those sort of tricky things where you're not really sure how to do something maybe you don't have to search on the web you can just let copilot do the searching for you the fifth way copilot helps me out is by knowing what i'm intending to do especially if i define a variable it knows what i want to do with that variable let me give you an example let's say i'm going to process some items here i take in some items i want to have a variable called active items sort of like what we did earlier so it already knows i'm probably going to do a loop and it already suggests that if one of the items is active it's going to increment active items because i had this variable active items defined up here it's going to make a suggestion that you probably are going to do something like use that variable in some way so this is actually really helpful sometimes copilot reminds me that i have a variable i haven't used and suggests that i use it before i remember that i actually meant to use it even if the suggestion is wrong i actually appreciate that reminder so the last way copilot helps me out which i recently discovered and actually blew my mind because i had no idea was possible is that if you use test driven development where you write the tests first and then write your code copilot will actually suggest code that makes the test pass and i didn't even know this was possible let me show you an example so let's say you're writing a test here i'm going to import model.js this file doesn't even exist yet i'm going to import deep equal from assert from the node cert did you see it already suggested from a cert it just knew that that's what i would probably do let's say i have a test here it should return an empty array by default and then i'll just show you an example where i create the model it's actually already suggesting the test i wanted to write anyway so that's nice and then let's say i do another one it should add double the number to the list this is not code i would probably normally write but i just want to give an example here so let's say yeah i want to create the model but what i want to show is that if i add let's say seven then it should dependable this is actually what i wanted to do i wanted to so it'll have 14. if i add 7 14 is going to be in the list so i'm going to save this as model.test in a blank folder here and then i'm going to make a new file model.js and just by making that file i can now write some code so let's say i do export default space it's dirty suggesting class model and boom it does all the rest of it even the part where i'm doubling the number before adding it to a list isn't that mind-boggling it actually looks into the other code that's using that file and figures out what you've been doing and what it expects so totally changes test driven development where you can write your tests and for the most part copilot will help you write code that passes the test immediately isn't that amazing well i hope you've enjoyed this i hope you get a chance to try out copilot for yourself check out copilot.github.com and thanks for watching [Music]
Info
Channel: Coding with Jesse
Views: 50,775
Rating: undefined out of 5
Keywords: copilot, githubcopilot, vscode, javascript, coding, programming
Id: SXtMnn1v7d8
Channel Id: undefined
Length: 7min 0sec (420 seconds)
Published: Tue Mar 01 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.