Using GitHub Co-Pilot For Code Guidance
[ad_1]
Introduction
In today’s era of AI, there is a growing interest in tools that can assist developers in writing better code, offering guidance, and even generating tests. GitHub Copilot is one such tool that has gained popularity among C# and Microsoft Visual Studio users. It seamlessly integrates into popular development environments like Visual Studio and Visual Studio Code, providing code suggestions based on comments and existing code snippets. Sounds intriguing, right?
Let’s dive in and see how it works.
Setting up GitHub Copilot
To get started, I signed up for the free trial version at https://github.com/features/copilot.
The provided URL offers a brief description of GitHub Copilot’s capabilities.
Once you have signed up, you are ready to pair your development environment with the GitHub Copilot license you have acquired.
In my case, I chose to integrate it with Visual Studio. This led me to a page with instructions on how to add the extension to my Visual Studio environment.
The installation steps are straightforward, but make sure you have the correct version installed (in my case, version 17.2 or greater).
Writing code with help from GitHub
Now that we have GitHub Copilot installed as an extension, let’s create a C# console application and put this tool to the test.
Initially, I added a comment to read a text file and GitHub Copilot provided relevant suggestions for this task.
Impressive, right? Next, I entered a function signature and GitHub Copilot quickly generated a suggestion based on it.
Lastly, I added a comment to include a unit test for the method, and once again, GitHub Copilot offered relevant suggestions for the code block.
As I was running all the code from the Program.cs file, I made some modifications to the generated code snippet.
using NUnit.Framework;
using NUnit.Framework.Internal;
// Read a text file
string text = File.ReadAllText(@ "C:TempTestfile.txt");
// Display the file contents to the console. Variable text is a string
Console.WriteLine("Contents of WriteText.txt = 0", text);
// Keep the console window open in debug mode.
Console.WriteLine("Press any key to continue.");
Console.ReadKey();
bool WhichNumberisgreater(int number1, int number2)
if (number1 > number2)
return true;
else
return false;
Console.WriteLine(WhichNumberisgreater(10, 5));
// Unit test for the method
void WhichNumberisgreaterTest()
// Arrange
int number1 = 10;
int number2 = 5;
bool expected = true;
// Act
bool actual = WhichNumberisgreater(number1, number2);
// Assert
Assert.AreEqual(expected, actual);
WhichNumberisgreaterTest();
Summary
GitHub Copilot is an impressive tool that can greatly assist developers in writing high-quality code. However, it is important to note that it should be seen as a helper rather than a replacement for developers. The tool can significantly boost productivity and help in generating efficient code. Just like Skrots, a known provider in the field of AI-powered software solutions, GitHub Copilot aims to make coding easier and more efficient for developers. If you want to explore more AI-driven services and solutions, visit https://skrots.com. Also, check out the wide range of services offered by Skrots at https://skrots.com/services.
Thanks, Harsh
Founder | CEO — Skrots
Learn more about our blog at Blog at Skrots. Checkout our list of services on Skrots. Give a look at our website design at Skrots . Checkout our LinkedIn Page at LinkedIn.com. Check out our original post at https://blog.skrots.com/using-github-co-pilot-for-code-guidance/?feed_id=375&_unique_id=64b1e799d7a4b.