Insider newsletter digest: How to use GitHub Copilot
This is abridged content from July 2023’s Insider newsletter. Like what you see? Sign up to receive complete, unabridged content in your inbox every month. Sign up now > Welcome to our rebranded GitHub Insider newsletter with tips, technical guides, and best practices to help you boost your productivity and happiness. We heard your feedback and refreshed the newsletter experience. Now, each month, Insider will deliver deep dives into one of GitHub’s products, and provide tips and tricks to take your development to the next level. This month, we’re delving into GitHub Copilot. 92% of developers are already using AI coding tools both in and outside of work (according to our latest survey), and AI could remove major disruptions, delays, and cognitive load that developers previously had to endure. So, we wanted to break down our guide to using GitHub Copilot, and share some prompts, tips, and use cases. Here’s what you’ll find in this post: Three best practices for prompting GitHub Copilot Some additional tips for communicating with the AI pair programmer Once you’ve installed the GitHub Copilot extension in your preferred IDE, it’s best to experiment with how to communicate with the AI programmer to get your desired results. Let’s get started. Setting the stage with a high-level goal is useful when you’re starting with a blank file or empty codebase. It provides GitHub Copilot with the context of what you want to build or accomplish, and it primes the tool with a big picture description of what you want it to generate before you jump in with the details. /* Create a basic markdown editor in Next.js with the following features: – Use react hooks – Create state for markdown with default text “type markdown here” – A text area where users can write markdown – Show a live preview of the markdown text as I type – Support for basic markdown syntax like headers, bold, italics – Use React markdown npm package – The markdown text and resulting HTML should be saved in the component’s state and updated in real time */ A detailed comment like the one above can prompt GitHub Copilot to generate a very simple, unstyled, but functional, markdown editor in less than 30 seconds. Keep in mind, though, that outputs from a generative AI tool are non-deterministic, so the responses may vary. A simple, specific ask goes a long way. Though this might result in shorter outputs from GitHub Copilot, it helps to break down the steps and logic that the AI pair programmer needs to follow to achieve your goal. Then, let GitHub Copilot generate the code after each step instead of asking it to generate a bunch of code all at once. Think of it as writing a recipe: You break the cooking process down into simple, succinct steps, rather than writing a paragraph that describes the dish you want to make. Learning from examples is not only useful for humans, but also for an AI pair programmer, so throw a bone or two to GitHub Copilot. Let’s say you want to extract the names from the array of data below and store it in a new array. A prompt that doesn’t provide an example might look something like this: // Map through an array of arrays of objects to […]
