Why use AI pair programmers?

I have been using Github Copilot for a few months now and have been blown away at how helpful it is when writing tests. These tools get a lot of bad rap, but I suggest you try them before you knock it. Tests are a great place to start.

Writing Tests for GeoAsteroids

I have this [2D spaceship game] I wrote in Typescript. It didn't have any tests, so I thought it would be an excellent place to try Copilot. 

Test moveShip

The following function fires whenever the user presses the up arrow on their keyboard.

/**
 * Move ship based on its x and y velocity
 */
function moveShip(ship: Ship): void {

  ship.centroid = new Point(
    ship.centroid.x + ship.xv,
    ship.centroid.y + ship.yv,
  );
}

Copilot cleverly suggests the following test without me typing anything! It's exactly what I was going to write anyway.

test.concurrent('Move Ship', () => {
  const testShip = new Ship();

  testShip.xv = 1;
  testShip.yv = 1;
  moveShip(testShip);
  expect(testShip.centroid.x).toBeGreaterThan(0);
  expect(testShip.centroid.y).toBeGreaterThan(0);
});

Conclusion

AI pair programmers are not perfect. Sometimes the suggestions are flat-out wrong, and I am always weary of mindlessly accepting the autocomplete. But tools like Copilot already deliver great value for low-hanging fruit like writing tests. I am excited to continue using it and look forward to Copilot taking more and more off my plate. This way, I can focus on the most creative aspects of programming (writing new features!).

Comments

Back to Home
John Solly Profile Picture
John Solly Profile Picture

John Solly

Hi, I'm John, a Software Engineer with a decade of experience building, deploying, and maintaining cloud-native geospatial solutions. I currently serve as a senior software engineer at New Light Technologies (NLT), where I work on a variety of infrastructure and application development projects.

Throughout my career, I've built applications on platforms like Esri and Mapbox while also leveraging open-source GIS technologies such as OpenLayers, GeoServer, and GDAL. This blog is where I share useful articles with the GeoDev community. Check out my portfolio to see my latest work!