←Back

Getting The Most Out Of Github Copilot

GitHub Copilot is an AI-powered coding assistant developed by GitHub and OpenAI, designed to enhance the coding experience by suggesting code snippets in real-time. We will explore how to leverage GitHub Copilot effectively to boost productivity and improve code quality. We will focus on utilizing powerful comments, writing readable code, and making the most of Copilot-enabled extensions. What does it boil down to? Comments and prompts.

Understanding the Power of Comments in GitHub Copilot

Comments are not just annotations for code; they serve as vital communication tools between developers and machines. GitHub Copilot’s ability to understand comments can be a game-changer. Here’s how you can make the most of this feature:

Using comments you’re able to ask Copilot to generate a simple function that determines if a number is divisible by n and return a list of divisible numbers from the provided list

Natural Language Prompts: Start your comments with plain English descriptions of the task or function you need. Copilot will use this context to generate relevant code snippets.

I find you’re able to remove copilot generated code and ask it to do something else and it seems to have the right context to follow your comments and suggestions

In-line Clarifications: Add comments to complex or tricky code areas. This helps Copilot understand your intentions better and generate more accurate suggestions.

Comment-Driven Refactoring: Use comments to outline the desired code changes, and let Copilot handle the heavy lifting, making the process of refactoring smoother and quicker.

Writing Readable Code with GitHub Copilot

Readable code is essential for collaboration, maintenance, and debugging. With GitHub Copilot, you can produce clean and consistent code:

Giving a function a self explanatory name often helps copilot understand what that function is trying to accomplish even before you can start to write comments about it.

Naming Conventions: Use descriptive variable and function names. Copilot will often generate code based on the provided names, leading to more contextually relevant suggestions.

Focus on Code Structure: Create well-organized code with appropriate indentation and logical groupings. Copilot is more likely to produce code that follows similar patterns.

Utilize Helper Functions: Comment your code with remarks on what helper functions or modules are needed. Copilot can then assist you in writing reusable and modular code.

Repetition

Do you need to perform a task over and over again as a programmer? For example, defining a list of all the states in the USA. By leveraging comments and starting the list, Copilot can understand your objective and complete it for you.

Hot Keys

In order to really leverage Copilot you should get familiar with it’s hotkeys:

  • Accept inline code suggestion — Tab
  • Dismiss inline code suggestion — Esc
  • Show next suggestion — Alt + ] or Option (⌥) + ]
  • Show previous suggestion — Alt + [ or Option (⌥) + [
  • Trigger suggestion — Alt + \ or Option (⌥) + \
  • Open ten suggestions in a separate pane — Ctrl + Enter

Leveraging Copilot-Enabled Extensions

I regularly use two extensions in VSCode that help with bug fixes, documentation, generating E2E tests and more:

Copilot chat which can be found in VS Code insiders edition
By Right clicking on a problematic error in your IDE, you can ask Copilot to Debug for you. This is built into VS Code insider edition along with Copilot chat

Copilot Labs

You can use Copilot labs VS Code extension to apply preset or custom “brushes” to selected code. I find this feature useful when generating unit tests and occasionally Cypress E2E tests

GitHub Copilot is a powerful tool that can significantly boost your productivity as a software engineer. It’s not perfect and will make mistakes but it’s able to generate the bulk of the task you ask it to. By using powerful comments, writing readable code, and leveraging Copilot-enabled extensions, you can make the most out of this AI-powered coding assistant. Embrace the collaboration between human and machine, and let Copilot enhance your software development journey with smarter suggestions and efficient code generation.

Remember, while GitHub Copilot is an incredible aid, always review the generated code and ensure it aligns with your project’s requirements and best coding practices.

Happy coding!

Leave a Reply

Your email address will not be published. Required fields are marked *