I learn best from reading, watching, and doing, which means I need various resources to create a robust mental model. When I've studied for interviews, colleges exams, and coding bootcamp, I'll watch videos, complete LeetCode exercises, and write an explanation of the code. Copilot Labs serves as an additional resource giving me more context on why and how specific algorithms work.
I will use Copilot and Copilot Labs to write and understand a binary search algorithm in this blog post.
Prerequisites:
Ensure that you've installed the GitHub Copilot extension AND the GitHub Copilot Labs extension.
Please note: GitHub Copilot is in technical preview, and thus not all users will be able to access this feature. Please join the waitlist if you'd like to sign up for the technical preview.
Writing Code with Copilot
Step 1: Open your IDE. For this example, I'm using Visual Studio Code via Codespaces. Type a comment that says, "Write a binary search algorithm."
Step 2: Type the keyword "const" on a new line. This should trigger Copilot to provide suggested code to write a binary search algorithm. To accept the suggested code, press the TAB key.
Explaining Code with Copilot Labs
Step 3: Now, we can better understand what the code is accomplishing by converting the code into plain language. Let's open the Copilot Labs sidebar.
Step 4: Highlight the code snippet, and on the top left-hand corner, choose "Explain." Press the "Ask Copilot" button to generate a step-by-step explanation of what's happening in the code snippet.
Translating Code to a Different Programming Language with Copilot Labs
Step 5: We can also convert this code snippet into Python (or any programming language of your choice). Navigate to the Language Translation of the Copilot Labs sidebar and choose the target language. Press the "Ask Copilot" button to view a version of the code snippet in a different language.
Follow GitHub and me on DEV for more updates on GitHub's newest features!
If you have any feedback you want to share with the team at GitHub, use the Discussion board.
Top comments (25)
Just sharing, I have this rule whenever learn new framework/language I will not use GitHub Copilot, I will do first, try and error hoping the thing I learn stick inside my head, if I can't do it by myself, then I use GitHub Copilot
But if I do my fulltime job, I'll fully utilized GitHub Copilot.
That’s a really good method!
Yeah, I also let my mistakes burn in my head before I could use any auto complete feature.
With that said, co pilot is too close to being a code buddy so I like that.
I really liked the part where you can generate the explaination for the code.
I would not fully rely on Copilot when I'm learning something brand new, but the explaination aspect is really interesting. Nice article!
I agree! I don’t mean to solely rely on it, but just having it for additional context
Thank you btw!
Damnnn github copilot is soo cool!
yes, it is!!!
Overall, I like CoPilot, and it has created some incredible code for me.
However, you need to (a) look for code you didn't realise that it had created when you took your eye off the ball for a moment, and (b) look at every line it has created because sometimes its intuition is either a little off or way off.
It’s still in beta mode! Definitely give feedback to help us improve. Also I wrote about use cases in this article, and I acknowledge that it’s not all the way there yet: dev.to/github/why-use-github-copil...
This wasn't meant as criticism, far from it.
It was merely a warning to always look at the created code, particularly when you didn't realise that it had created some :-)
Oh, I didn't take it as such. I was just saying when mistakes do happen or copilot does something expected..there's a feedback area in copilot where you can provide feedback and help the feature improve, so we could reduce chances of that happening.
Copilot Labs looks like it still has some work to do. If I didn't understand how that algorithm worked, that explanation would be almost useless. It seems to only explain the syntax without addressing the semantic meaning of the code.
It’s still in beta mode, so yes true! We are open to feedback to improve
Juniors will not be needed soon? I thinks - yes
I think juniors will still be needed, but it will help juniors to code more efficiently. I wrote another blog post about possible use cases for Copilot. You can check it out here: dev.to/github/why-use-github-copil...
I think junior may will be stay junior forever by this tools. Because, its tools stopping our thinks about code
I get what you're saying.
However..
Copilot can't write code without knowledge behind it. Copilot is more like stack overflow than someone who is thinking for us. You still have to think about code and understand what you're writing and why to use Copilot. Copilot just provides added context and suggestions. Also, Copilot is not ALWAYS accurate.
and junior cant understand correct code or not
I've been using Copilot for a few weeks now and I'm amazed how good it is. Sometimes, even the words and comments generated by Copilot are better than mine.
its true
That's a really cool use case. Thanks for the tip.
Ha-ha. I've tried it myself, that's sick! Maybe one day we'll no longer need to share knowledge with people who used to be involved in writing code, where the code wasn't commented clearly enough.
What to do with legacy code, if we need change it?
great to know that copilot can make our coding life easy