Tips & Tricks: Get the Most Out of GitHub CoPilot | DevReach 2023
TLDRIn a session at DevReach 2023, Todd England from Microsoft's Cloud Advocacy team introduces and explores GitHub CoPilot, an AI pair programmer designed to enhance coding efficiency. The talk covers the basics of how CoPilot functions using large language models to predict code completions. It emphasizes the importance of providing context for CoPilot to offer accurate suggestions and discusses its limitations, such as not being a compiler and not having real-time updates for live previews in code spaces. England demonstrates CoPilot's capabilities in various coding scenarios, including writing basic code, extending and refactoring existing code, explaining unfamiliar code, understanding error messages, and adding tests. He also highlights the iterative process of refining code with CoPilot, using comments and chat for clarification. The session concludes with a live coding example in Visual Studio 2022, showcasing CoPilot's assistance in debugging and understanding exceptions. The key takeaway is that while CoPilot is a powerful tool, developers remain in control, guiding the AI to achieve desired outcomes effectively.
Takeaways
- π **GitHub CoPilot as a Pair Programmer**: It acts like a virtual pair programmer, assisting with code predictions and suggestions based on your prompts and context.
- π **Understanding Large Language Models (LLMs)**: CoPilot uses LLMs to predict code completions, which are based on patterns identified from vast amounts of training data.
- π **Accelerating Workflow**: It helps in accelerating the coding process by providing suggestions for code completions, which can be particularly useful for less commonly used languages or new developers.
- π **Context is Key**: The better the context provided to CoPilot, the more accurate the suggestions. This includes open files, comments, and code structure.
- π§ **Iterative Improvement**: Developers should trust but verify the suggestions given by CoPilot, and iterate on them to refine the code to their needs.
- π§ **AI's Limitations**: CoPilot has its limitations; it does not compile code, cannot read your mind, and is dependent on the quality and context of the input provided.
- π‘ **Using Comments Effectively**: Including specific comments in the code can guide CoPilot to provide more relevant and accurate code completions.
- π οΈ **Refactoring and Extending Code**: CoPilot can assist in refactoring and extending existing code, adhering to the coding standards and practices of the project.
- π **Integration with IDEs**: CoPilot integrates with various IDEs, including Visual Studio Code and Visual Studio, allowing developers to use it within their preferred development environment.
- π **Documentation and Testing**: It can help in generating documentation for code and even assist in writing tests, thus improving code quality and maintainability.
- β‘οΈ **Future Capabilities**: CoPilot is set to introduce more features, such as assisting with pull requests, indicating continuous development and improvement of the tool.
Q & A
What is the main topic of the session presented by Todd England?
-The main topic of the session is tips and tricks for getting the most out of GitHub CoPilot, an AI pair programmer tool.
What is Todd England's role at Microsoft?
-Todd England is part of the Cloud Advocacy team at Microsoft, which is a developer-led team working across the entirety of Microsoft Cloud and AI.
How does GitHub CoPilot utilize large language models to assist in coding?
-GitHub CoPilot uses large language models to understand large sets of data and predict what comes next based on a prompt or sequence, providing code completions or suggestions based on pre-existing code patterns.
What are some limitations of GitHub CoPilot that developers should be aware of?
-Some limitations include that it is not a compiler, cannot perform actions, does not learn or remember, and cannot read the developer's mind. It requires good context to provide accurate suggestions.
How does GitHub CoPilot's performance vary depending on the programming language?
-GitHub CoPilot's performance is better for languages with lots of open-source code available for training, such as JavaScript, Java, and Python. For less common or emerging languages, the suggestions may not be as accurate.
What are some ways to provide better context to GitHub CoPilot for improved suggestions?
-To provide better context, developers can use the open file in the editor, top-level comments, meaningful names for variables and functions, specific comments, and sample code or existing code in the project.
What is the purpose of the 'explain this' feature in GitHub CoPilot?
-The 'explain this' feature allows developers to understand why a particular code completion or suggestion was provided, helping them learn and verify the suggestions given by GitHub CoPilot.
How can GitHub CoPilot assist in writing tests for a project?
-GitHub CoPilot can generate test cases for a project based on a command or prompt given by the developer, assisting in creating a more comprehensive test suite.
What is the significance of the token limit in GitHub CoPilot?
-The token limit in GitHub CoPilot affects how much context the tool can process and how many characters it can generate in a response. It is important for efficient use of the tool and to avoid generating excessive or irrelevant content.
How does GitHub CoPilot help in refactoring code?
-GitHub CoPilot can assist in refactoring code by suggesting changes based on natural language prompts or by using inline chat to make specific changes, such as converting function names to camel case.
What additional capabilities are coming to GitHub CoPilot?
-Upcoming capabilities for GitHub CoPilot include features for pull requests to help accelerate the process of doing quality pull requests, and more functionalities will be announced on github.com/features-preview.
Outlines
π Morning Greetings and Introduction to GitHub Co-Pilot
The speaker, Todd England, starts the session by welcoming the audience and sharing a personal anecdote from a past DevReach event. He introduces himself as part of Microsoft's Cloud Advocacy team and invites attendees to connect with him on social media. Todd then segues into the main topic of the talk, which is about GitHub Co-Pilot, an AI pair programmer. He engages the audience by asking about their experience with GitHub Co-Pilot and emphasizes the tool's ability to enhance workflows through discovery and collaboration.
π€ Understanding GitHub Co-Pilot's Functionality and Limitations
Todd explains how GitHub Co-Pilot operates using large language models to predict code completions based on existing code patterns. He highlights the importance of training data and its impact on the suggestions provided by the tool. The speaker also discusses the limitations of GitHub Co-Pilot, such as its inability to compile code or understand new programming languages with fewer examples. He stresses the need for good context when using the tool to get the best results.
π Providing Context to GitHub Co-Pilot for Better Suggestions
The speaker outlines several ways to provide context to GitHub Co-Pilot to improve its suggestions. He emphasizes the importance of having the right files open, using top-level comments to set goals, including in-line comments for specific guidance, and utilizing meaningful names for variables and functions. Todd also touches on the value of sample code in guiding the AI's responses and concludes with a recap of the key points discussed.
π» Practical Uses of GitHub Co-Pilot in Development
Todd discusses various practical applications of GitHub Co-Pilot, such as writing basic code faster, aiding in memory recall for experienced developers, extending and refactoring existing code, explaining unfamiliar code, understanding and fixing errors, and even adding tests to a project. He encourages the audience to explore these capabilities and provides live demonstrations of GitHub Co-Pilot's functionalities.
π Trust but Verify: Iterating with GitHub Co-Pilot
The speaker shares a live demo of using GitHub Co-Pilot to create a function that sanitizes HTML from a string. He emphasizes the importance of iterating with the tool, refining prompts, and verifying the suggestions given. Todd also demonstrates how to use the 'explain' feature to understand the code suggestions and the inline chat for further clarification.
π Auto-Documenting Code with GitHub Co-Pilot
Todd demonstrates how GitHub Co-Pilot can automatically generate documentation for code methods. He uses a command to prompt the tool to document a method's parameters and return types. The speaker also shows how to add tests to a project and interact with the GitHub Co-Pilot chat for troubleshooting and guidance on installing testing frameworks.
π Live Preview and CSS Development with GitHub Co-Pilot
The speaker discusses a tip for live previewing code in code spaces and addresses a quirk related to real-time updates. He then moves on to creating a CSS stylesheet for a simple HTML page using GitHub Co-Pilot. Todd illustrates how to provide goals and context to the tool to generate appropriate styles and how to correct its course when it goes down an incorrect path.
π Iterative Code Refactoring with GitHub Co-Pilot
Todd shows how to use GitHub Co-Pilot for iterative code refactoring. He demonstrates using the tool to make a main content area scrollable while keeping the footer at the bottom of the page. The speaker also uses the inline chat to ask for specific CSS features, like a linear gradient, and discusses the importance of providing the right context for the AI to generate accurate results.
π Extending Existing Code Bases with GitHub Co-Pilot
The speaker discusses how GitHub Co-Pilot can be used to add new services to an existing code base while adhering to the project's coding standards. He shows how having relevant files open provides the tool with better context, resulting in more accurate suggestions. Todd also demonstrates the tool's ability to refactor code to follow camelCase naming conventions.
π‘ Debugging and Exception Handling with GitHub Co-Pilot
Todd demonstrates using GitHub Co-Pilot within Visual Studio to understand and handle exceptions during the debugging process. He intentionally crashes an application and then uses the tool to get an explanation of the unhandled error exception. The speaker highlights the integration of GitHub Co-Pilot in Visual Studio for a more productive development experience.
π Recap and Future of GitHub Co-Pilot
In the final segment, Todd recaps the key tips for using GitHub Co-Pilot effectively, emphasizing the importance of specific, short prompts, trusting but verifying the AI's suggestions, and the critical role of context. He also teases upcoming features, such as GitHub Co-Pilot for pull requests, and invites the audience to explore new capabilities on the GitHub Features preview page. Todd concludes by encouraging developers to see the tool as an assistant rather than a threat to their jobs, highlighting the human role as the expert pilot in the coding process.
Mindmap
Keywords
GitHub CoPilot
Large Language Models (LLMs)
Code Completion
Context
IDE (Integrated Development Environment)
Token Limit
Refactoring
Debugging
Stack Overflow
Code Testing
Pull Requests
Highlights
Todd England shares tips and tricks for maximizing the use of GitHub CoPilot, an AI pair programmer.
GitHub CoPilot assists by predicting code completions based on large language models and existing code examples.
The importance of providing context for GitHub CoPilot to enhance the accuracy of its suggestions is emphasized.
GitHub CoPilot is not a compiler and cannot verify the correctness of the code it suggests.
The AI cannot read the user's mind, thus clear and specific prompts are necessary for effective use.
GitHub CoPilot integrates with various IDEs, including Visual Studio Code and Visual Studio 2022, allowing it to work within a developer's preferred environment.
The tool can help write basic code faster, remember coding details, and extend or refactor existing code.
GitHub CoPilot can be particularly useful for explaining unfamiliar code and generating documentation.
The session includes live demos of GitHub CoPilot's capabilities, showcasing its real-time interaction and learning process.
Todd England demonstrates how to use GitHub CoPilot to create tests for a project, even when no tests are present initially.
GitHub CoPilot can help understand and fix errors, providing explanations and guidance within the IDE.
The use of descriptive variable and function names can guide GitHub CoPilot to provide more accurate code suggestions.
GitHub CoPilot's chat feature allows developers to ask questions and receive coding assistance directly within the IDE.
The tool can automate the addition of documentation to code, improving maintainability with simple commands.
GitHub CoPilot can help refactor code to follow certain patterns, such as converting function names to camel case.
Visual Studio 2022 now includes GitHub CoPilot, enhancing the debugging process by explaining exceptions and aiding in code analysis.
Upcoming features for GitHub CoPilot are available for preview, and users can sign up for waitlists to gain early access.
CoPilot Adventures is a new initiative offering coding puzzles and challenges to help developers learn new skills and techniques.
GitHub CoPilot is positioned as a tool to assist developers, not replace them, aiming to make programmers more effective and efficient.