Prompt crafting with GitHub Copilot!

The year 2024 is a year full of AI and AI-driven tools and technologies. Every business/sector is talking about implementations of AI and how it is helping them to evolve. Specifically in our IT industry, we are focusing on Gen AI and how this technology can empower our product teams. Writing faster code, delivering quality products at a lightning speed, verifying compliance and security, etc are all expected to be the default behavior of the product teams. Engineers are expected to learn the new ways of development, especially the practice of pair programming. Earlier, this method involved two software engineers working side by side; two human pair programmers. Now, with Microsoft’s GitHub Copilot; one of these programmers is an AI-driven programmer; but yes we do need one human programmer !!

GitHub Copilot (GHCP) is like an assistant that is embedded in your IDE and provides suggestions and helps you to write code faster. For example, if you were delivering 150-200 lines of code every day; now with GHCP you can deliver more than 400 lines of code. If you find unit testing challenging, then now you can generate unit test cases for the selected code quickly. If onboarding new engineers is a time consuming task then now you can shorten this process by receiving instant easy to understand explanations to your project. Interesting, isn’t it? But, this is possible only with effective Prompt Crafting also known as Prompt Engineering.This refers to the way we communicate with AI systems smartly to get optimal results. It is like asking the right questions to receive the right recommendations; and yes if the question is vague then do expect vague answers. This refers to the concept of GIGO – garbage in, garbage out!!

As teams get started with GHCP, they need to experiment and evolve with prompts. Prompts are simple English based statements that are passed to GHCP server, that in turns sends it to OpenAI’s LLM. The more specific we get with our statement/question, the more accurate results we may receive from GHCP. And this art is something that engineers/developers learn over a short timespan. Another important thing to remember is that the prompts are related to the open files or the selected code in the IDE. Also, prompts can be typed directly in the editor starting with a “#” or can be typed in the Copilot Chat window. So, how should teams plan for upskilling on GHCP? Few quick tips for teams that are getting started with prompt engineering using GHCP-

a. Week 1: Experiment to understand with simple prompts to first understand your code – open Copilot Chat and type in the prompt “/explain“, do ensure that the file is opened in the editor. GHCP will provide explanation to the opened file/selected code. Next step, explore more prompts – like “how to optimize this function“, “how to fix error“, “provide comments“, etc. Let the teams get comfortable with Copilot and consolidate the initial experience.

b. WEEK 2 & 3 : Evolve with the right context – as the team gets comfortable, they should start developing new code with Copilot. They should start writing prompts to get help from Copilot and now be very specific in their ask. Prompts like “generate unit test cases“, “write a Terraform script to deploy an Azure instance“, “how to refactor this code“, “create a next.js file that uses react hooks“, etc. While GHCP shares suggestions, lengthy lines of code, but do remember that we still need to review the code as we accept the suggestions.

c. WEEK 4 & onwards – conduct a retrospective meeting with your team to discuss their learnings and experiences. Monitor and track few metrics like lines of code, accepted prompts, time to resolve defects, etc; before and after using Copilot. And this is just the beginning…. continue on this journey. As teams experiment and explore; they will become experts in leveraging Copilot.

To summarize, writing effective prompts is the new science in software engineering. Providing the right context, asking questions with specificity, providing examples, are all different ways to maximise the benefits with GitHub Copilot. So, thats my experience so far… …what is your journey !