Jump to content

How to Use GitHub Copilot Labs to improve your Code Quality and Productivity


Recommended Posts

Guest kevin_comba
Posted

largevv2px999.png.fda1594caf9e003da34de11352030fec.png

 

I am a computer science student at Kenya's Kirinyaga University and a Microsoft Learn Student Ambassador. As a student, I am committed to gaining new skills and knowledge in the field of computer science, and I am always looking for opportunities to apply my knowledge and make a difference. More about me

.

As a student new to coding, you will face numerous challenges with software development in general these include things like:

 

- Code quality

- Productivity

- Debugging code

 

- Fixing bugs in code

 

- Explaining code

 

- Commenting Code

 

These are just a few of the issues you may encounter. Out of curiosity, you might write a simple calculator program in JavaScript and then try to find its code equivalent in Python or C#. Visual Studio Code GitHub Copilot Labs will make your life easier, and your learning curve will be less steep.

 

 

What is GitHub Copilot Labs?

 

 

GitHub Copilot is a groundbreaking AI pair programer for developers, but we’re just beginning to explore the future of coding. GitHub Copilot Labs is a companion VS Code extension it is separate from (and dependent on) the GitHub Copilot extension. Labs provides ground for experimental applications of machine learning that improve the developer experience.

 

 

Getting started GitHub Copilot Labs

 

 

We will ve showcase the power of GitHub Copilot and Copilot labs with a JavaScript example.

 

 

Requirements:

 


  1. An active GitHub Copilot subscription. Visit the Copilot QuickStart to learn more.
     
     

  2. You must have the main extension of GitHub Copilot installed alongside Labs.
     
     

  3. Install node.js. Get it here, for our test case will require it.
     
     

  4. Click on GitHub Copilot Labs to install the VS Code extension else open your VS Code and search for GitHub copilot labs as shown below.
     

 

largevv2px999.png.e4e11d0c8f0aa75135521135fb635768.pngSearch for Copilot Labs

 

  1. Click install, after installation you should see a GitHub copilot labs icon on your left side menu.

 

largevv2px999.thumb.png.6fdbaf22a09f8442280fcb99cdb11eeb.pngVerify your installation.

 

Let’s create a sample project.

 

 

Suppose we have a simple function called isPalindrone (A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward. Example eye, level, radar).

 

Let’s setup our example.

 

  1. Create a folder name it test folder and drag it on to VS Code or right click on the folder and open with VS Code.

 

largevv2px999.png.efe40a6611f5c225d535e96ab9324ad5.pngcreate a folder

 

  1. Create a file.
  2. Name it explaining.js.

 

largevv2px999.png.350caee4c44b011a02fcb78f551f8be7.png

 

  1. Write the below code snippet on explaining.js file.
    function isPalindrome(s) {
    s = s.toLowerCase();
    let i = 0;
    let j = s.length - 1;
    while (i < j) {
    if (s !== s[j]) {
    return false;
    }
    i++;
    j--;
    }
    return true;
    }
     
    isPalindrome("deified");

What can Copilot Labs do?

 

  1. Explain what the code does.

 

largevv2px999.png.a29c62244ba42f573444083577f5ae05.pngExplain what the code does

 

  • Highlight all code.
  • Select code does the following.
  • Click ask copilot.

 

largevv2px999.png.b7e0a66dffeea712e730fa84e0a61aee.pngThe results show five points explaining what the code above does.

 

 

 

  1. Explain code - GitHub Copilot Labs can assist us in understanding our sample code by providing a step-by-step explanation.

 

largevv2px999.thumb.png.aaeb831f105e9d507354c296103f4cc6.pngExplain code - GitHub Copilot Labs can assist us in understanding our sample code by providing a step-by-step explanation

 

  • Click on the GitHub copilot labs icon.
  • Click on explain.
  • Highlight all you code.

 

largevv2px999.png.874fff8b5e4441903b2b2c35e00dfa56.pngAs you can see, we have 4 points explaining our code auto generated by copilot labs.

 

  • Show code example – This option lets copilot give you several instances of our function being called with different inputs and expected results.

 

largevv2px999.png.468c47f03e461abf9df118ca5b757450.png

 

 

 

  1. Language translation - converting code from one language to another.

 

largevv2px999.png.e0ab364783430723b7f7b5f11beaa8ad.png

 

  • Select language translation.
  • Highlight all code you want to be translated.
  • Select any language. I choose to select python.
  • Click ask copilot.

 

largevv2px999.thumb.png.9a1cc017314ce33ff51f43d82567ae26.pngJavaScript to Python

 

  • Moment of magic. Python code is auto generated for you, equivalent of the JavaScript on your right-hand side.
  • The same case if Select Java, Our JavaScript code will be converted to Java.

 

largevv2px999.png.e4b9217f98970d60886ba6d27381647b.pngJavaScript to Java

 

  • The same case if Select typescript. Our JavaScript code will be converted to typescript.

 

largevv2px999.png.bb5f88ca8c88aaf20f73e4a05d6768c1.pngJavaScript to TypeScript

 

 

 

  1. Debugging code – Copilot Labs injects output functions (console.log) to enable you to track how your valuables are changing during iterations. This is helpful during debugging your code.

 

largevv2px999.png.5c27e6db89cf1c925b475e3351075ce4.png

 

  • select Brushes category.
  • highlight all your code you want to debug.
  • Click Debug.

 

largevv2px999.png.522aa0fb26deab55c1f47e0f28e93292.png

 

  • Injected code which helps you to track the values I and j as they change in the program.
  • Let’s run our function using this command ‘node explaining.js’ on the terminal (to open terminal on windows use ctrl + ` )

 

largevv2px999.png.e38eb58a1bf676f06500e76b9d22951c.pngOur console is filled with pair of values tracking I and j while the program is looping.

 

  1. Fix Bug – assuming you have made a typo on your variable names example instead of s !== s[j], you make a typo and have this instead s[k] !== s.
    • Our error. Highlight all code.
    • Click fix bug.

 

largevv2px999.thumb.png.715d4fcde241d0f500be6093f8f1bb8c.pngFix Bug

 

 

 

largevv2px999.png.cca0383f851fc5d503587f5449c30dcf.pngCopilot labs fixed the typo and just like that your bug free with a click of button.

 

 

 

  1. List steps – this feature will document your code explaining every step your code is doing. Simply highlight your code and press List steps button.

 

largevv2px999.thumb.png.dbec1d383f37141fdc612919a018d3ad.png

 

 

 

7. Code Formatting - Clean formatting your code by removing unnecessary comments which might make your code look dirty. Simply highlight your code and press clear button.

 

largevv2px999.png.91115a638c9f77157174d385049fa89f.pngbefore

 

 

 

largevv2px999.png.38f2e9d5e486ca53c1a867fb4e4b335a.pngafter

 

Summary

 

 

 

 

This is just some of the features which are currently available now. New features are always being added to this library. GitHub Copilot Labs is trying to solve the challenges faced by developers in writing and collaborating on code by providing real-time feedback, suggestions, and best practices to help improve their coding experience and skills. To learn more about GitHub Copilot Labs, read their official site.

 

Continue reading...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...