Developer tools and practices have evolved significantly over the last decade. Earlier developer ecosystems were IDE e.g. Eclipse, Visual Studio, technical self-help books, stack overflow, and Google. Artificial intelligence terms were first time used in 1956. AI tools have become so popular because of increasing data volumes, advanced algorithms, and computing power and storage improvements. With the evolving times, we have varied options to get assistance for developers, testers, and business analysts.
Before AI Tools Launch
- Earlier developers may spend a lot of time finding issues with a minor syntax error in the string formation.
- Earlier developers had to look and browse various links on Google to search for a solution and read multiple suggestions.
What is GitHub Copilot?
GitHub Copilot is an AI coding assistant that helps you write code faster and with less effort, allowing us to focus more energy on problem-solving, collaboration, and domain. GitHub Copilot has been proven to increase developer productivity and accelerate the pace of software development.
Why use GitHub Copilot: Copilot is a powerful tool in the right hand.
- It generates code snippets for the developer.
- It suggests new code syntax the framework launches
- Design pattern suggestion and explanation
- Get code performance suggestions
- Developers can even master new coding language
- Developers need not leave their development environment to get the solutions. They can just type keywords in their environment and get solutions.
How GitHub Copilot Works
Open AI Codex, a machine learning model that translates natural language into code, powers GitHub Copilot to draw context from comments and code to suggest individual lines and whole functions as you type. Codex is a version of GPT-3 (Generative Pre-trained Transformer 3) fine-tuned for programming tasks.
Features of GitHub Copilot
- Suggests code as we type in IDE
- Chat: We can prompt and get suggestions
- Command line tool: Get code suggestions in the Command line
- Copilot Enterprise only: Get a description of the changes for pull requests
- Autocomplete repetitive sections of code for the method and functions
- Policy management for administrators
- Conversion of code comments to runnable code
- Access management for enterprise owners and organization owners
Real-time Usage of GitHub Copilot
- Generate class file for JSON structure for API.
- Write test case for the Method or function
- Generate string for JSON output for post request in API
- IntelliSense suggesting code like assistant and developer can accept the code
Different types of subscription for Copilot:
- CoPilot Individual: For individual developers, freelancers, students, and educators.
- CoPilot Business: For organizations ready to improve engineering velocity, code quality, and developer experience.
- CoPilot Enterprise: For companies looking for the most customization based on their organization’s knowledge and codebase.
For more information on the cost, we can get it from the below URL. We can use free trial or buy any of the above plan from this URL and there are contact sales: GitHub Copilot · Your AI pair programmer · GitHub. Even for free trial we need to provide credit card information.
Advantages of using GitHub copilot
- Git hub copilot is auto enabled in the IDE (Visual Studio, VSCode, Eclipse) it keeps suggesting us auto complete code.
- Suggests code for object initialization for a class, Writes test cases. To achieve code coverage of 85% or above developer needs to complete it in few hours hence it improves developer productivity
- Provides suggestions for a new framework and developers can type their question in chat and get appropriate responses.
Realtime use cases for GitHub Copilot.
- Code Snippet for Class Person in C# which has nested class and generating JSON for this Sample response from GitHub Copilot when we want to test Web API POST request with sample data
Class Person { public Name PersonName { get; set; } public Address PersonAddress { get; set; } public int Height { get; set; } public string EyeColor { get; set; } } Public Class PersonName { public string FirstName { get; set; } public string LastName { get; set; } } Public class Address { public string AddressLine1 { get; set; } public string AddressLine2 { get; set; } public string City { get; set; } public string State { get; set; } public string State { get; set; } public string ZipCode { get; set; } }
- Prompt to GitHub is convert to string datatype.
"{n" + " "PersonName": {n" + " "FirstName": "John",n" + " "LastName": "Doe"n" + " },n" + " "PersonAddress": {n" + " "AddressLine1": "123 Main St",n" + " "AddressLine2": "Apt 4B",n" + " "City": "Anytown",n" + " "State": "CA",n" + " "ZipCode": "12345"n" + " },n" + " "Height": 180,n" + " "EyeColor": "Brown"n"
3. Explain repository pattern: Below response from Github Copilot
Key Concepts:
- Repository: A class that acts as an intermediary between the business logic layer and the data layer (database). It hides the details of data access and allows the business logic to work with an abstracted interface.
- Interface: The repository often exposes an interface, allowing for flexibility in how data is retrieved and stored (e.g., from a database, in-memory, or an external service).
- Abstraction: The repository provides an abstraction of the underlying data source, allowing the rest of the application to work with simple method calls without knowing the details of how data is stored or fetched.
Benefits of the Repository Pattern:
- Separation of concerns: Keeps the data access logic isolated from the business logic.
- Testability: Allows for easier unit testing by mocking the repository in tests.
Maintainability: Easier to manage changes to data access logic without impacting the rest of the application.
4. Writing Test cases. Prompt to Github Copilot is write test case for split a string using MOQ
Sure! Here's an example of how you can write a test case using Moq for a string with the value "one, two, three, four, five": ```csharp using Moq; using Xunit; public class StringServiceTests { [Fact] public void TestStringService() { // Arrange var mockStringService = new Mock(); string testString = "one, two, three, four, five"; mockStringService.Setup(service => service.GetString()).Returns(testString); // Act var result = mockStringService.Object.GetString(); // Assert Assert.Equal(testString, result); } } public interface IStringService { string GetString(); } ``` In this example: - We create a mock of the `IStringService` interface. - We set up the mock to return the string "one, two, three, four, five" when the `GetString` method is called. - We then call the `GetString` method on the mock object and assert that the returned value is equal to the expected string. Feel free to ask if you need further assistance or have any questions!
GitHub is available for following IDE
Visual Studio, Visual Studio Code, JetBrains
GitHub Supports Following programming languages: Python, JavaScript, TypeScript, Go, and Ruby
Downside of using GitHub Copilot:
- GitHub copilot keeps on suggesting code which a developer may not intend to write is kind of annoying.
- It may generate code based on the prompt we provide which may have some error and developer must rework accordingly
- Once Copilot is integrated into the developer environment it will prompt to press tab to accept the code which may be incorrect, developer completely needs to always use their discretion.
- Hence it is a powerful tool in the right hand.
Quotes from one of the news about AI tools
I would like to reference a statement by “Nvidia CEO Jensen Huang at the recent World Government Summit in Dubai said youngsters should stop focusing on how to code, at this early stage of AI revolution programming is no longer a vital skill. Coding can be taken care of by AI, humans can take care of more important expertise like domain, biology, education, farming etc.”.
Conclusion:
This tool can be very well utilized by the adept developers and also by new developers for their focused learning and work towards organization productivity.
It is the time to evolve our beliefs and work alongside AI powered tools enhance our knowledge and learn to use these tools so that we could get along with changing times.
Developers can focus on enriching user experience with their product and bring in more innovation.
Source: Read MoreÂ