Tips & Tricks: Get the Most Out of GitHub CoPilot | DevReach 2023

Progress Telerik
22 Nov 202359:42

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

00:00

πŸ˜€ 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.

05:00

πŸ€– 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.

10:02

πŸ““ 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.

15:03

πŸ’» 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.

20:05

πŸ” 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.

25:06

πŸ“ 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.

30:07

🌐 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.

35:09

πŸ”„ 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.

40:10

πŸ“š 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.

45:12

πŸ’‘ 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.

50:14

πŸ”‹ 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

GitHub CoPilot is an AI-powered programming assistant that works alongside developers to write code, suggest solutions, and enhance the coding process. It is designed to understand the context of the code and provide relevant suggestions, making it an accelerant to the developer's thought process. In the video, it is used to demonstrate how it can help with various coding tasks, from writing basic code to refactoring and understanding unfamiliar code.

Large Language Models (LLMs)

Large Language Models are AI models that have been trained on vast amounts of text data, enabling them to predict and generate human-like text based on given prompts. In the context of the video, GitHub CoPilot utilizes LLMs to understand code patterns and suggest the next likely piece of code, making it a powerful tool for developers.

Code Completion

Code completion refers to the feature of automatically completing code snippets as a developer types. GitHub CoPilot excels at providing code completions by predicting what code should come next based on the current context. It is highlighted in the video as a way to accelerate coding and improve efficiency.

Context

Context is critical when using GitHub CoPilot as it informs the AI of the current coding goal or problem. Providing good context helps the AI give more accurate and relevant suggestions. The video emphasizes the importance of keeping relevant files open, using top-level comments, and including meaningful variable and function names to provide context.

IDE (Integrated Development Environment)

An Integrated Development Environment is a software application that provides comprehensive facilities for coding, debugging, and source code management. In the video, it is mentioned that GitHub CoPilot integrates with various IDEs like Visual Studio Code and Visual Studio, allowing developers to use CoPilot's capabilities within their preferred development tools.

Token Limit

Token limit refers to the maximum number of tokens (words or phrases) that a language model can process at one time. In the context of GitHub CoPilot, the token limit affects how much context the model can consider when providing suggestions. The video script discusses the token limit in relation to generating large amounts of content, such as Lorem Ipsum text.

Refactoring

Refactoring is the process of restructuring existing computer code without changing its external behavior. In the video, GitHub CoPilot is shown to assist with refactoring by making suggestions for code improvements, such as converting function names to camel case, which adheres to a more standard coding convention.

Debugging

Debugging is the process of identifying and removing bugs or errors from a computer program. The video demonstrates how GitHub CoPilot can aid in debugging by explaining exceptions that occur during runtime and guiding developers towards solutions.

Stack Overflow

Stack Overflow is a platform where developers can ask and answer questions related to programming. In the video, it is humorously mentioned as a place developers might resort to when they forget certain coding details, with GitHub CoPilot presented as an AI alternative that can provide similar assistance without leaving the IDE.

Code Testing

Code testing involves the verification of the correctness, completeness, and quality of software code. The video showcases GitHub CoPilot's ability to help developers write tests for their code, which is crucial for ensuring code functionality and identifying defects early in the development process.

Pull Requests

Pull requests are a way for developers to submit changes to a project's repository for review by other members of the team. The video hints at upcoming features of GitHub CoPilot that will assist with pull requests, potentially making the process of code review and integration more efficient and streamlined.

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.