GitHub Copilot Chat: Evaluating the New Tool
Table of Contents

GitHub Copilot Chat: Evaluating the New Tool

You're probably familiar with the game-changing impact that GitHub Copilot has had on the programming world. The AI-driven tool has become an indispensable assistant for many, taking the heavy lifting out of everyday tasks and transforming the way we write quality software. What if we told you that your trusty Copilot is about to become even more interactive?

Meet GitHub Copilot Chat, the next generation of AI-powered software development. Designed with a more natural, conversational interface, this upgrade combines the best features of GitHub Copilot and integrates it seamlessly with your existing workflow. Imagine having a valuable teammate by your side every step of the way -- one that knows the context and can provide insightful support to help you overcome challenges, explain code snippets, or even fix errors effortlessly.

With the integration of OpenAI's GPT-4 capabilities, the GitHub Copilot X platform aims to bridge the gap between humans and AI, making it easier than ever to collaborate and communicate effectively on software projects. Now, you'll be able to rely on your AI pair programmer not only for code suggestions and completion, but also as an active problem solver and team contributor.

Is it good enough, however? Can your teams really rely on the suggestions, solutions & completions of the tool? Let’s find out. We will ask it questions to determine whether it’s a  

Solutions

One reason we turn to our AI helpers is to solve our problems. Let’s see how it will do with some of the more common issues that could arise.

Rendering Large Lists in React

When we have large lists of data, rendering them naively, will slow down our apps significantly. React does very little for us in that department out of the box. One solution is to create a virtualized list – the app shows only what the user sees vs showing everything at once.

How can I optimize large lists in React?

Answer:

To optimize large lists in React, you can use the React.memo higher-order component to memoize the rendering of list items. Additionally, you can use the windowing technique to only render the visible items in the list, which can significantly improve performance. Here's an example implementation:

import React, { memo, useState, useCallback } from 'react';  
 
import { FixedSizeList } from 'react-window';  
 
const ListItem = memo(({ index, data }) => {  
 
  const item = data[index];  
 
  return <div>{item}</div>;  
 
});  
 
const List = ({ items }) => {  
 
  const [scrollOffset, setScrollOffset] = useState(0);  
 
  const handleScroll = useCallback(({ scrollOffset }) => {  
 
    setScrollOffset(scrollOffset);  
 
  }, []);  
 
  return (  
 
    <FixedSizeList  
 
      height={400}  
 
      itemCount={items.length}  
 
      itemSize={50}  
 
      width={400}  
 
      onScroll={handleScroll}  
 
      scrollOffset={scrollOffset}  
 
    >  
 
      {({ index, style }) => (  
 
        <div style={style}>  
 
          <ListItem index={index} data={items} />  
 
        </div>  
 
      )}  
 
    </FixedSizeList>  
 
  );  
 
}; 

In this example, we're using the FixedSizeList component from the react-window library to render a fixed-size list of items. The ListItem component is memoized using React.memo to prevent unnecessary re-renders. We're also using the useCallback hook to memoize the handleScroll function to prevent unnecessary re-renders.

To further optimize performance, you can also use the useVirtual hook from the react-window library to only render the visible items in the list.

The answer we got works. It isn’t bad in any way, and it does what it’s supposed to do. There are several aspects the AI didn’t cover, but that’s alright: it answered our question. What’s interesting, is that Copilot suggests follow-up questions. For example, after we got our answer, a suggested question was “How can I use the useVirtual hook from the react-window library to optimize large lists in React?” It’s surely a great follow-up.

Reading Files in Java

Operating on files is a standard thing to do for back-end developers. Let’s see how well it will do with the simple operation of reading a CSV file:

How to read a CSV file in Java?

Answer:

Here's an example code snippet that shows how to read a CSV file in Java using the CSVReader class from the OpenCSV library:

import com.opencsv.CSVReader;  
 
import java.io.FileReader;  
 
import java.io.IOException;  
 
public class CsvReaderExample {  
 
    public static void main(String[] args) {  
 
        String csvFile = "path/to/your/csv/file.csv";  
 
        try (CSVReader reader = new CSVReader(new FileReader(csvFile))) {  
 
            String[] line;  
 
            while ((line = reader.readNext()) != null) {  
 
                // process the CSV data  
 
                // each element in the line array represents a column in the CSV file  
 
            }  
 
        } catch (IOException e) {  
 
            e.printStackTrace();  
 
        }  
 
    }  
 
} 

Make sure to add the OpenCSV library to your project's dependencies before running this code.

Let’s go a step further, and ask it to perform some straightforward operations on the data found in the columns.  

I have a csv file with two columns: number, and id. The number column has a hex number in it. How to convert the hexadecimal to decimal in Java?

Copilot responded with:

You can use the Integer.parseInt() method in Java to convert a hexadecimal string to a decimal integer. Here's an example code snippet that reads a CSV file and converts the hex number to decimal:

import java.io.BufferedReader;  
 
import java.io.FileReader;  
 
import java.io.IOException;  
 
public class HexToDecimalConverter {  
 
    public static void main(String[] args) {  
 
        String csvFile = "path/to/your/csv/file.csv";  
 
        String line = "";  
 
        String csvSplitBy = ",";  
 
        try (BufferedReader br = new BufferedReader(new FileReader(csvFile))) {  
 
            while ((line = br.readLine()) != null) {  
 
                String[] data = line.split(csvSplitBy);  
 
                String hexNumber = data[0];  
 
                int decimalNumber = Integer.parseInt(hexNumber, 16);  
 
                String id = data[1];  
 
                System.out.println(decimalNumber + "," + id);  
 
            }  
 
        } catch (IOException e) {  
 
            e.printStackTrace();  
 
        }  
 
    }  
 
} 

This code reads a CSV file and splits each line into two parts using the comma separator. It then converts the hex number to decimal using the Integer.parseInt() method with a radix of 16 (which indicates that the input string is in hexadecimal format). Finally, it prints the decimal number and the id to the console.

No issues with the response here. It did what we asked it to do.

Copilot Chat and the Cloud

When you’re a DevOps engineer or a Cloud Engineer, you must write a ton of config files. Let’s see if the new feature will help them. Let’s see how well our AI friend knows Terraform.  

Generate Azure Storage Account lifecycle policy after 30 days move everything from landing filesystem to cool tier and delete after 60 days.

The response was not great

resource "azurerm_storage_account" "example" {  
  name                     = "example"  
  resource_group_name      = "example-resource-group"  
  location                 = "eastus"  
  account_tier             = "Standard"  
  account_replication_type = "LRS" 

It tries to use outdated resource “azurerm_storage_account_management_policy.” Let’s nudge it in the right direction.

Use the latest azurerm provider and resources

Unfortunately, things got a bit worse:

resource "azurerm_storage_account" "lake" { 
  name                     = "datalake" 
  resource_group_name      = data.azurerm_resource_group.rg.name 
  location                 = data.azurerm_resource_group.rg.location 
  account_tier             = "Standard" 
  account_replication_type = "LRS" 
  tags = { 
    "project"     = "powerbi" 
    "environment" = "${terraform.workspace}" 
    "entity"      = "core" 
  } 
} 
resource "azurerm_storage_container" "lake" { 
  name                  = "data" 
  storage_account_name  = azurerm_storage_account.lake.name 
  container_access_type = "private" 
} 
resource "azurerm_storage_account_management_policy" "lake" { 
  name                = "datalake-policy" 
  resource_group_name = data.azurerm_resource_group.rg.name 
  storage_account_id  = azurerm_storage_account.lake.id 
  rule { 
    name = "datalake-rule" 
    enabled = true 
    type = "Lifecycle" 
    definition { 
      actions { 
        base_blob { 
          tier_to_cool { 
            days_after_modification_greater_than = 30 
          } 
          delete { 
            days_after_modification_greater_than = 60 
          } 
        } 
      } 
      filters { 
        blob_types = [ 
          "BlockBlob" 
        ] 
        prefix_match { 
          prefix = "landing/" 
        } 
      } 
    } 
  } 
} 
module "datalake" { 
  source = "Azure/datalake-gen2/azurerm" 
  resource_group_name = data.azurerm_resource_group.rg.name 
  storage_account_name = azurerm_storage_account.lake.name 
  file_system_name = "data" 
} 

People working with the cloud resources might need to wait a while before the completions get better.

Explanations

Another reason why we turn to our AI friends is for them to explain concepts we don’t quite understand. Let’s see how Copilot will handle our questions.

Reflection in Java

Reflection is an important concept in Java. That’s why we asked:

What is reflection and why is it useful in Java?

Reflection is a feature in Java that allows you to inspect and manipulate classes, interfaces, constructors, methods, and fields at runtime. It is useful in Java because it allows you to create more flexible and dynamic programs. With reflection, you can create new objects, invoke methods, and access fields dynamically, without knowing their names at compile time. This makes it possible to write generic code that can work with any class, and to create frameworks that can be extended by third-party code. However, reflection can also be slower and less type-safe than regular Java code, so it should be used judiciously.

Why Is Processing Sorted Arrays Faster Than Processing Unsorted Arrays in Java?

Another topic that could puzzle developers is why is processing sorted arrays faster than processing unsorted arrays. It would make sense that the processing speed was the same. As it turns out there is an explanation for that:

Processing a sorted array is faster than processing an unsorted one in Java because of the way modern CPUs work. When an array is sorted, the data is arranged in a predictable order, which allows the CPU to optimize its operations and take advantage of caching. This can result in significant performance improvements, especially when working with large datasets. Additionally, some algorithms are specifically designed to take advantage of sorted data, further improving performance.

We will take the opportunity to demonstrate how the AI wil suggest follow up questions (the blue text on the bottom.

Conclusion

The blog post discusses the features of GitHub Copilot Chat, a next-generation AI-powered software development tool that offers a more conversational interface. By integrating OpenAI's GPT-4 technology, it aims to bridge the gap between humans and AI, offering not only code suggestions but also problem-solving capabilities. The article provides examples of how Copilot Chat performs in various scenarios, such as rendering large lists in React, reading files in Java, and working with cloud resources. While the tool is useful, developers may need to wait for further improvement in some cases.  

The post also demonstrates how Copilot Chat provides clear explanations of concepts such as reflection in Java and the reasons behind the faster processing of sorted arrays. We plan to add more code examples in the future to make the tool even more useful. Our software development experts are already using AI to deliver high-quality software solutions.

Overall the AI completions from Copilot are not bad, and certainly quite often useful in most cases. Sure, when it comes to the Terraform example it wasn't particularly helpful, but let's give it time - the algorithms significantly improve over time.

Liked the article? subscribe to updates!
360° IT Check is a weekly publication where we bring you the latest and greatest in the world of tech. We cover topics like emerging technologies & frameworks, news about innovative startups, and other topics which affect the world of tech directly or indirectly.

Like what you’re reading? Make sure to subscribe to our weekly newsletter!
Relevant Expertise:
No items found.
Share

Subscribe for periodic tech i

By filling in the above fields and clicking “Subscribe”, you agree to the processing by ITMAGINATION of your personal data contained in the above form for the purposes of sending you messages in the form of newsletter subscription, in accordance with our Privacy Policy.
Thank you! Your submission has been received!
We will send you at most one email per week with our latest tech news and insights.

In the meantime, feel free to explore this page or our Resources page for eBooks, technical guides, GitHub Demos, and more!
Oops! Something went wrong while submitting the form.

Related articles

Our Partners & Certifications
© 2024 ITMAGINATION, A Virtusa Company. All Rights Reserved.