Improve your code search by 2x using Github Copilot!.

2022/05/29 | 1 minute read |

Hey there,

If you are a programming nerd, then you must have heard about the Github Copilot initiate. The project claims it as ‘Your AI pair programmer’. I had to wait a long to access to the technical preview. I use it regularly on my personal laptop as an extension for VS Code and so far, I have been enjoying it!

Those who don’t know, it is an AI pair programmer that helps to code faster. It draws context from comments and code to suggest lines of code . It is powered by OpenAI Codex and was trained on publicly available souce code and natural language. It does not write perfect code rather tries to understand intent and generate the best code it can.

A few of the peculiar use cases:

  1. Write a comment describing the logic you want and the copilot will assemble code for you. Consider a simple example of converting string to datetime. I wrote a comment in plain english and the copilot started suggesting the plausible options.

  1. Produce a boilerplate and repetitive code by feeding a few examples e.g. list of months, SQL CTE, code indentation, etc.

  2. Getting an alternative to the written code. There are a couple of options to get the next suggestion. We can see the alternative option or multiple suggestions using ‘Ctrl+Enter’.

  3. Writing unit tests using copilot suggestions is one of the most creative usages I found. Unit tests are time-consuming and hence mostly overlooked during MLOps. Copilot can be very handy in such scenarios. e.g., I have a read_params() function which takes config_path and returns a dictionary of parameters. Once I have the function defined, I wrote the comment for Copilot to suggest the unit test case(s) for the read_params() and the result is as below:

  1. Code without spending most of your time searching the web. It is one of my favorite options. It saves a lot of time. As shown below, we need to write draw_distribution_plot() to get the code along with docstrings.

GitHub Copilot X is adopting OpenAI’s new GPT-4 model. They are introducing chat and voice for Copilot, and bringing Copilot to pull requests, the command line, and docs to answer questions on your projects

I will keep adding the use cases if I come across any!

Thank you!!

Leave a comment