Post

GitHub Copilot | Part 1 - Staying in the Flow

The rise of GenAI in 2023 has had a profound impact on many people, including myself. In my case, it led me to start the exploration of how GenAI affects the design and implementation of the applications that we create today, which inspired one of my earliest blog posts on this topic. At that time, AI engineering using Python was the most popular. The challenge was that I did not know Python! And so I started from the very basics — by reading one of my child’s Christmas presents, Coding for Kids: Python! 😅

GitHub Copilot to the rescue! I was fortunate to get timely access to GitHub Copilot which super charged my Python learning journey. I will say it again, it feels like Christmas whenever I use GitHub Copilot! 🎄

Original LinkedIn Post My original LinkedIn post

Since then, I have experimented with multiple Azure OpenAI applications using Python, NodeJS/TS, and C#. In this post, I am sharing my experience and top tips after using GitHub Copilot for almost a year. Satya Nadella’s words at GitHub Universe 2023 really resonated with me. He said, ‘… since I’ve been using GitHub Copilot, my weekends have changed… You know, I can code again! The joy of coding is back!’

Personal Experience: I spent most of my development career using C# and developing classic ASP.Net and SharePoint applications. While learning languages like Python and Javascript is easy, I do not write code as fast as I want to. There are always those little things that require a quick search here and there.
GitHub Copilot changed things as it helps me translate thoughts into code as fast as possible. Since using GitHub Copilot, I have been able to code with only VS Code open and nothing else, significantly minimizing distractions. Even with messaging applications closed, incorrect search engine results and distracting advertisements from online references can be disruptive to my on-going flow of thought. This has enabled me to be “in the zone” almost every time I code.

What is GitHub Copilot?

GitHub Copilot is “an AI pair programmer that helps you write code faster and with less effort. It uses machine learning trained on billions of lines of public code to suggest whole lines or entire functions right inside your editor” (This description is generated by GitHub Copilot itself!) Practically speaking, GitHub Copilot is an IDE extension that communicates with the GitHub Copilot service to help the developer write code. It currently supports VS Code, Visual Studio, NeoVim, and the JetBrains IDEs (Rider, IntelliJ IDEA, PyCharm, etc).

“But developers can generate code for free using OpenAI’s ChatGPT!” While this is true, developers will have to always have a browser open and manually switch between the browser and your IDE to copy-paste code. This can be very disruptive to developers’ flow of thought. GitHub Copilot, however, is integrated into the IDE and can be used without leaving the IDE. This is a huge productivity boost for developers.

GitHub Copilot was available even before ChatGPT became popular (since June 2022). This is the reason why there are already a good number of studies out there about the impact of GitHub Copilot on developer productivity. Due to the popularity of ChatGPT, GitHub Copilot Chat was released in preview sometime mid-2023 and made generally available in December 2023. The studies on GitHub Copilot Chat are still ongoing, but the good news is that both GitHub Copilot and GitHub Copilot Chat are available as a single license/service — known as GitHub Copilot.

Staying in the Flow, or, should I say “In the Zone”

Flow state is a mental state of operation in which a person performing an activity is fully immersed in a feeling of energized focus, full involvement, and enjoyment in the process of the activity (source). Cal Newport describes flow state as a state of mind that allows you to work at your highest level of productivity and creativity. He also suggests that we can learn to achieve flow state on-demand by focusing on one task at a time and eliminating distractions.

What a description that resonates very well with developers! We (developers) often call this being “in the zone”. Many will agree that when we are “in the zone”, a task that is estimated to take 2 days to code may be completed in half-a-day instead. The opposite is also true, if we have 2 hours of work left to complete a task and are interrupted in the middle of coding, it may take us another 4 hours before we complete the task. Say, for example, because of an “urgent” 30 minute meeting.

Developer Interruption Comic Strip The Cost of Interruptions for Software Developers (source)

The good news is that helping developers achieve flow state is one of the main goals of GitHub.

With GitHub Copilot, we’re enabling developers to reach that magical flow state — which includes delivering fast, accurate vulnerability prevention right from the editor. This, combined with GitHub Advanced Security’s vulnerability detection and remediation capabilities, provides an end-to-end seamless experience for developers to secure their code. (Source: GitHub Blog)

IDE Capabilities before and after GitHub Copilot

I saw this TikTok from Scott Hanselman who described it really well. These are the IDE capabilities that we are all familiar with:

Autocomplete Autocomplete

Intellisense Intellisense

Intellicode Intellicode

GitHub Copilot takes these capabilities to the next level by using GenAI to give coding suggestions. GitHub Copilot GitHub Copilot

GitHub Copilot has several capabilities, including:

  • Code generations: from a few lines to whole functions, this includes generating APIs, classes, unit tests, etc.
  • Code documentation: generate inline comments, OpenAPI YAML specifications, and Markdown Mermaid diagrams.
  • Code understanding: help understand unfamiliar code through explanations, improving variable names, interpreting RegEx, etc.
  • Code translation: translate code from one language to another.
  • and more.

Using GitHub Copilot

In this section, I will share the top prompts for how I personally use GitHub Copilot. (NOTE: I am primarily using VS Code when using GitHub Copilot. Some of the tips here may not be applicable to other IDEs.)

1. Start with a Comment for New Files

When creating a new file, start with a comment describing its purpose. This helps GitHub Copilot provide better suggestions. For example, if it is a new class, start with a comment like // Controller class for the Customer model. This will help GitHub Copilot understand what you are trying to do and provide better suggestions.

For files that do not support comments (e.g..json or .yaml files), I use Copilot chat directly to help me generate an initial draft of the file.

2. Use CTRL+I more than the Copilot Chat Panel

CTRL+I is the keyboard shortcut for opening a Copilot Inline Chat from within the text editor. At times, I would wait for Copilot to suggest the next line(s) of code and get nothing. When this happens, I would quickly hit CTRL+I and enter a prompt and get it to generate an initial code for me. I find this to be faster than clicking the Copilot Chat panel, typing a prompt, and clicking another button to copy-paste the code into the text editor.

Know when to use the Copilot Chat Panel. Personally, I use it for the following:

  • When asking questions about the code: usually when trying to understand other people’s code.
  • When asking non-English questions (i.e. Filipino, Chinese, Thai, etc.). At least in my experience, I seldom see non-English language in code comments.
  • When generating code for another file: For example, in generating unit tests, the active window should be the main class file. Chat Copilot will take the active file as the main context, while the generated unit tests are meant to be copy-pasted for another file. Other scenarios include generating OpenAPI specifications, language translations, etc.
  • When writing complex or multi-line prompts: See here for examples (more on this in the next post.)
  • When using agents: See tip #4 below.

3. Learn the slash / commands

The slash / commands are pre-prompt engineered shortcuts to help developers code faster. For example, instead of typing generate a unit test for this code..., you can simply type /test. Similarly, instead of typing explain this code..., you can simply type /explain. See here for the full list of slash / commands supported by VS Code.

4. Get to Know the @workspace Agent

As of this time, there are 3 agents available in GitHub Copilot for VS Code: @workspace, @vscode, and @terminal. @workspace, is the agent that specifically deals with code. Here are some samples for using @workspace:

  1. @workspace /new _python flask application_ scaffolds a new VS Code workspace with a recommended file structure according to your prompt.
  2. @workspace /newNotebook _use the OpenAI SDK and call a chat completion_ generates a new Jupyter notebook with initial code generated according to your prompt.

Pro Tip: You can use the @workspace agent together with the slash / commands. See here.

Conclusion

In conclusion, GitHub Copilot is a powerful tool that can help developers quickly translate their thoughts into code, thereby helping them enter the zone, and stay in the flow. With slash / commands and agents, GitHub Copilot offers a range of capabilities to accelerate developer velocity.

In this post, I have shared my personal experience on how I use GitHub Copilot, and I would love to hear how others use it as well. Feel free to share your tips in the comments below.

This post is licensed under CC BY 4.0 by the author.