Giter Site home page Giter Site logo

yuhattor / copilot-patterns Goto Github PK

View Code? Open in Web Editor NEW
252.0 3.0 32.0 38.65 MB

This document is a compilation of best practices for AI-Native development, curated by our community. Discover useful tips and tricks for leveraging tools to improve your AI development process.

Home Page: https://www.ai-native.dev/

License: Creative Commons Attribution Share Alike 4.0 International

Python 72.00% Shell 0.77% SCSS 22.16% HTML 5.07%
github ai chatgpt development github-copilot githubcopilot gpt3

copilot-patterns's Introduction

GitHub Copilot Patterns and Exercises

Welcome to the GitHub Copilot Patterns & Exercises documentation! ๐Ÿ‘‹ This community-driven opensource guide is dedicated to providing best practices for GitHub Copilot. Our aim is to make it straightforward for you to understand, evaluate, and integrate these practices into your projects. ๐Ÿš€

This document is brought to you by GitHub's Customer Success Architect @yuhattor to help developers better use GitHub Copilot and other AI-Powered tools.

Some of these patterns have been tried and proven effective in individual environments, but others are idea-based and have not yet been tested for effectiveness in actual team environments. Please feel free to leave comments on GitHub Issues. We look forward to various discussions and the sharing of knowledge about AI Powered development.

This documentation is not yet in its final version, and there may be broken links, typos, and other errors. Your help in improving it is much appreciated. Please see how you can contribute to this document.

Contribute

We believe in the power of community. If you find this project useful, please consider giving our GitHub repository a star:star2:. Your contributions, no matter how small, can make a big difference! Whether it's improving the documentation, adding new patterns, or just fixing a typo - every bit helps.

To get started with contributing, check out our contribution guidelines CONTRIBUTING.md or open an issue or pull request. Let's work together to pave the way for GitHub Copilot Patterns & Exercises!

We hope this guide will serve as a starting point for you to enter the world of GitHub Copilot Patterns & Exercises.

What are Patterns & Exercises

Patterns are a way of describing repeatable solutions to problems within a specific context. In GitHub Copilot Patterns & Exercises, patterns provide ideas for how developers and teams can use AI to achieve rapid product development.

  • Patterns: These are tried and true solutions to common problems and scenarios you might encounter when developing with GitHub Copilot. Each pattern is categorized by its level of maturity. Static Badge Static Badge Static Badge Static Badge
  • Exercises: Practical hands-on tasks that can help reinforce your understanding and application of the patterns.

Patterns that are still in development or have not been fully evaluated. Many have been discussed in the community and their usefulness established, but each is at a different level of maturity. See GitHub Projects for the status of each.

Authorship and Acknowledgements

This document is lead authored by Yuki Hattori, a Customer Success Architect at GitHub. Throughout its evolution, various community members have reviewed and enriched its content. Dive deep into our contributors' graph to see the passionate individuals who have shaped this project. Please join us. Let's explore the wild GitHub Copilot Patterns together.

LICENSE

This document is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.


Thank you for being a part of this journey. Together, we can shape the future of AI Powered Development!

copilot-patterns's People

Contributors

ducdongmg avatar eichisanden avatar gitstua avatar harasho avatar kawakamimoeki avatar koheikanagu avatar kuniyoshikamimura avatar martin-wanerskar avatar metonym avatar milkcaramel avatar nizi24 avatar nobuyo avatar parroty avatar rayuron avatar ry0y4n avatar s2mr avatar shoito avatar yokawasa avatar yuhattor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

copilot-patterns's Issues

Pattern: Object generation from structured data

Description

Working with structured data is an everyday task for developers. Transforming data from formats like JSON into objects within your programming language allows for more robust and maintainable code. Imagine you have a list of users, and you want to convert this data into user objects within your application. GitHub Copilot can help you in this transformation process, turning a tedious task into a seamless exercise.

https://www.ai-native.dev/docs/general/object-generation-from-structured-data

Pattern: AI Friendly Naming Convention

AI Friendly Naming Convention

{% hint style="info" %}
This document is still under review. We encourage active discussion on GitHub Issues.
{% endhint %}

Description

This document explains naming convention patterns that can be useful when writing code with AI coding assistance tools. By using these patterns, code can be written in a way that is more readable and understandable by AI.

Problem

When writing code, it can be difficult to decide what to name variables and functions. Also, if one tries to provide context only through comments, the code can become difficult for the reader to understand. This readability issue can also affect the accuracy of GitHub Copilot's suggestions. Ultimately, it can lead to not receiving accurate suggestions from GitHub Copilot.

Context

GitHub Copilot, the representative of AI coding assistance tools, uses an engine called Codex, which is based on the GPT3 model. The GPT3 model can understand natural language, and Codex can also understand natural language in the same way. By using variable expressions similar to natural language, more readable and understandable code can be written.

Solution

If you are struggling with naming variables and functions when writing code, you can create a common naming convention with your team in advance, assuming that AI coding assistance tools will read it, so that you can write code that is more readable and understandable by AI. Instead of providing context only through comments, AI coding assistance tools can make more accurate suggestions by using variable expressions similar to natural language.

The following are examples of naming convention patterns:

  • Use lowercase or camelcase
  • Use variable expressions similar to natural language
  • Use short names
  • Use descriptive names

Resulting Context

By using this naming convention pattern, code can be written in a more readable and understandable way, and AI can make more accurate code suggestions.

Pattern: AI Friendly Documentation

AI Friendly Documentation

Description

Creating documentation in a format that can be understood by AI, not just engineers who write code, can improve team productivity as a whole. For example, database table definitions can be written in Markdown and managed as documentation in Git, rather than in PowerPoint or Excel.

Problem

Various documents are necessary for product development, including requirement definitions, design documents, architecture overviews, infrastructure configuration specifications, and test case documents. While formats like PowerPoint and Excel are commonly preferred, AI cannot read those documents. Additionally, managing binary files in Git repositories is not a best practice.

Story

Your team has introduced GitHub Copilot for Business, and the engineers are pleased with the shortened work time. The team feels like it has doubled in size with the help of AI. However, the problem is that AI can only do what the engineers instruct it to do, and it does not understand the context that the engineers have. Therefore, the engineers need to input a lot of natural language to convey context to the AI. As a result, there has been an increase in copying and pasting text from articles provided by the PM or converting PowerPoint slides and complex Excel files created by bosses to Markdown or CSV format that AI can read.

"If it were written in CSV or Markdown from the beginning, it would be much better!"

Context

Many projects are managed with documentation in formats like PowerPoint or Excel. People other than engineers are communicating outside of GitHub, and final decisions are not being saved in the repository. While the documents are summarized in a way that is easy for AI to read, they are not being managed centrally.

Solution

The team should strive to create text-based documents, such as Markdown or CSV. Documents containing context that should ultimately be passed on to the engineer and AI should be stored in Git repositories. The repository should be easy to call from outside the workspace, using Git Submodule and other methods. If necessary, copy the text of the file to the comments section and pass it on to AI as a prompt.

Known Instance

  • Prepare a table definition file in CSV or Markdown format and associate it with the creation of migration files and interfaces.
  • Convert infrastructure definitions summarized in natural language into configuration files for Infrastructure as Code, such as Terraform.
  • Convert test case documents to test files. This works more effectively for certain patterns, such as API tests. This makes test-driven development easier.

Resulting Context

  • Engineers can create more code with less effort, leading to reduced workload.
  • Project owners and product managers can obtain results from engineers more quickly.
  • Members who do not normally write code can use GitHub to collaborate and become accustomed to judging the context that engineers need and the context that should be provided to AI, allowing for appropriate development using AI.
  • Since changes to documents are tracked, it is possible to track everything, including when decisions were made, beyond just the code.
  • There will be no discrepancy between documents and implementation.

Note

  • Currently, GitHub Copilot has limited capabilities for reading files. If you are writing in Python, only the Python code in the open tab will be read and passed on to the prompt. Therefore, copy the necessary text from AI-friendly documents and paste it into the comments section of the .py file.
  • This pattern is not effective for all documents. Misjudging which documents should be stored can result in a large amount of unnecessary documents in the repository, reducing search performance. Try to prioritize writing implementation-related text in Markdown.
  • There is a limit to the number of tokens that can be passed to AI. Try to make each section of the text concise and with as few dependencies as possible between previous and subsequent sentences.

Pattern: Quick Q&A

Description

In the collaborative coding environment, quick interactions and clarifications are often key to efficient development. While GitHub has the "GitHub Copilot Chat" product for more structured and extensive conversations, the "Quick Q&A" technique serves as a lightweight alternative. It enables developers to rapidly engage with Copilot in the code editor for brief one-liner answers and insights. It's not a distinct feature but a method that leverages commenting for quick interactions with Copilot, making it an agile and handy tool for on-the-spot guidance.

https://www.ai-native.dev/docs/general/quick-qna

Pattern: Type hinting

Description

In the world of dynamic typing programming languages, developers often face challenges in understanding code, especially when working on complex systems. Type hinting adds a layer of clarity by explicitly declaring the expected data types. With GitHub Copilot, the integration of type hinting can increase the accuracy of code suggestions, empowering developers and GitHub Copilot to write code more efficiently.
Imagine you're working on a project where functions are deeply nested, and tracking the types of variables becomes convoluted. Integrating type hinting also makes the code more readable for your fellow developers.

https://www.ai-native.dev/docs/general/type-hinting

Pattern: Writing test code before refactoring

Description

In the modern world of software development, refactoring can be seen as a fun and engaging task, especially with tools like GitHub Copilot at your disposal. It's so easy to dive in and make changes, but without proper tests, even the most promising code modification can lead to unexpected results. This pattern emphasizes the importance of writing tests before refactoring code to ensure that the functionality remains consistent. Think of tests as your safety net; they catch the problems before they become catastrophic.

https://www.ai-native.dev/docs/refactoring/writing-test-code-before-refactoring

Tasks to be done before v2 announcement from Alpha to Beta

Tasks

Pattern: Context Directory

Context Directory

Also known as a snippet directory for snippet inclusion.

Description

By collecting the context of the entire codebase in the context directory within the repository, it is easier to provide GitHub Copilot with accurate context during development.

Problem

  • Inaccurate suggestions:
    GitHub Copilot may make inaccurate suggestions if it cannot obtain the context of the entire codebase, which can lead to lower code quality and increased time spent by developers on fixing or adjusting code.
  • Reduced efficiency:
    If developers do not have related files open in adjacent tabs, GitHub Copilot cannot obtain information from those files. This can result in inaccurate suggestions and force developers to manually search and reference related files while writing code, potentially decreasing their productivity.
  • Loss of code consistency:
    If GitHub Copilot cannot obtain the context of the entire codebase, the code it suggests may lack consistency with existing code. This can negatively impact code readability and maintainability, and slow down the development speed of the entire team.

Story

One day, an engineer on a project team decided to use GitHub Copilot to develop a new feature. She was excited about GitHub Copilot and believed it would help her write code quickly.

However, as development progressed, she realized that GitHub Copilot occasionally made inaccurate code suggestions. Even though she manually corrected them and continued development, she became increasingly tired of the task. Furthermore, other team members also pointed out that GitHub Copilot's suggested code lacked consistency.

She wondered why GitHub Copilot was not making accurate suggestions, and upon investigation, found that one reason for inaccurate suggestions was not having related files opened correctly. On the other hand, leaving all files open was not realistic, and since GitHub Copilot only sends adjacent tab data as tokens, it did not make sense to open too many files. She also realized that the Codex model used by GitHub Copilot had limits on the number of tokens that could be passed.

Therefore, she decided to introduce the context directory pattern. By keeping related files open, she expects GitHub Copilot to make more accurate suggestions.

Context

GitHub Copilot, a representative product of AI coding support tools, currently makes suggestions based on information from the currently open file or files with the same extension open in tabs. The number of tokens that can be passed to the Codex model used by GitHub Copilot is limited. Therefore, GitHub Copilot extensions such as VS Code do not send all information from the open files as reference information to the GitHub Copilot server, but prioritize sending data from files with high similarity to the currently open files. Including snippets is called "snippet inclusion". Therefore, it is necessary to open only an appropriate number of related files in adjacent tabs.

Solution

  1. Create a context directory: Create a directory where personal or team files that you want to collect as context or rules that you want to memorize with GitHub Copilot can be collected.
  2. Close files unrelated to the current development.
  3. Open files related to the current development in VSCode and keep them open in tabs. While GitHub Copilot does not have a feature to obtain the context of the entire codebase, it can read the current file and files opened in the editor. By keeping related files open, GitHub Copilot can provide more accurate suggestions.

Resulting Context

Using the context directory allows GitHub Copilot to provide more accurate suggestions. By keeping related files open, effective code completion can be obtained.

Note

  • The files that GitHub Copilot currently reads are limited. If you are writing Python code, it is desirable that the snippet files and reference files are also Python code.
  • If necessary, you can write these directories in .gitignore to avoid pushing the contents.
  • You can also use Git Submodule to separate the context directory from other directories.

Pattern: Test only what is necessary

Description

In the era of rapid software development, writing efficient and useful tests is more important than ever, and when using GitHub Copilot, developers may generate a lot of test code to increase coverage. However, unnecessary test code generation can lead to maintenance burdens and technical debt, so it is important to test only what is necessary when writing test code using GitHub Copilot.

https://www.ai-native.dev/docs/test/test-only-what-is-necessary

Pattern: Consistent coding style

Description

Consistent coding style is crucial in software development, as it not only enhances code readability but also leads to better suggestions from GitHub Copilot. Indentation, tabs, naming conventions, comment writing, language-specific abbreviations, and many other areas of coding style. By adhering to a uniform coding style and pattern, developers find it easier to follow excellent coding practices.

https://www.ai-native.dev/docs/design-patterns/consistent-coding-style

Pattern: Go to definition

Description

When working with a complex codebase, jumping between files or searching through layers of code to find the definition of a particular symbol can be cumbersome. "Go to Definition" is a useful feature in Visual Studio Codethat allows developers to quickly navigate to the definition of a symbol in the current file. This not only enhances productivity but also enables better understanding of the code structure. GitHub Copilot will read open tabs. So, you can also pass relevant code snippets related to the symbol definition to GitHub Copilot

https://www.ai-native.dev/docs/client-side-tips/go-to-definition

Pattern: Code completion

Description

One of the simplest uses of GitHub Copilot is code completion. Code completion enhances developer productivity by offering potential code snippets as the developer is typing. For example, imagine defining a function in JavaScript. As you input the code below, GitHub Copilot will suggest potential code that could be used inside the function, such as the following code.

https://www.ai-native.dev/docs/general/code-completion

Pattern: Making the calculation part independent

Description

In the rapidly evolving world of software development, relying on tools like GitHub Copilot can enhance the development process. However, current versions of large language models may have limitations when handling complex calculations. To address this, developers can refactor their code by moving the computation part to another function. This improves code maintainability, readability, and makes it easier to test and develop with AI tools. Imagine a developer building a financial software system who needs to separate interest calculations from the user interface logic. Every time GitHub Copilot rewrites a particular piece of code, verifying that the logic is correct is a very cumbersome task. By separating this complex computation, you create a codebase that can work with a flexible and more durable AI.

https://www.ai-native.dev/docs/refactoring/making-the-calculation-part-independent

Pattern: High-level architecture first

Description

When developing a complex system, it is common to dive into the details of the code and lose sight of the overall architecture of the program. When this happens repeatedly, GitHub Copilot also loses sight of its overall architecture. This can lead to misunderstandings and errors. By designing the high-level architecture of the program first and commenting on the function and purpose of each piece of code during development, GitHub Copilot can better understand the context and make more precise suggestions.

https://www.ai-native.dev/docs/design-patterns/high-level-architecture-first

Pattern: Eliminating a tiny OSS dependency

Description

Do you know about the left-pad issue? In 2016, the left-pad library was suspended from npm, causing well-known libraries that depended on it to cease working. left-pad is a simple JavaScript library that only fills the left side of a string with a specified number of characters, or spaces if not specified. Excluding blank lines, it's a simple code with only about 10 lines.

There are many ideas to avoid reinventing the wheel, On the other hand, we must also pay attention to external code that can have a significant impact. If the provided code's scope is very limited, it might be better to contain it internally rather than depending on an external source.

https://www.ai-native.dev/docs/design-patterns/eliminating-a-tiny-oss-dependency

Pattern: Creating unit tests

Description

Testing is a fundamental part of the software development process, ensuring that the code meets its design and behaves as intended. The creation of unit tests, which test individual components of the system, can be both challenging and time-consuming. With GitHub Copilot, this process becomes more streamlined. Let's explore how a developer named Alice leverages GitHub Copilot to write unit tests for her application, reducing her workload and boosting her efficiency. This pattern is also applicable to functional and API testing.

https://www.ai-native.dev/docs/test/creating-unit-tests

Pattern: Code to comment

Description

GitHub Copilot can generate comments from code. When existing code lacks sufficient comments, or to assist other developers in understanding the code, GitHub Copilot can automatically generate explanations in comment form. The following sample demonstrates the Sieve of Eratosthenes algorithm to list prime numbers less than a given number. While this code does not contain comments, GitHub Copilot can create comments to describe the code's functionality.

https://www.ai-native.dev/docs/general/code-to-comment

Pattern: Writing failure case first

Description

In a development cycle, writing test cases is an essential aspect. When working with GitHub Copilot, it becomes even more convenient as it reads your implementation and generates test cases accordingly. While GitHub Copilot is very effective in generating success cases, it's vital not to overlook the failure cases. Considering failure cases first can lead to more robust code.

https://www.ai-native.dev/docs/test/writing-failure-case-first

[Pattern Candidate] Go to Definition

GitHub Copilot does not make suggestions based on my code base. Even if it does, it is limited and requires you to have the file open. You need to clearly indicate how to open the file to get suggestions based on your codebase.

Specifically, the process should be as follows

  • Close all other files.
  • Go to definition to open more and more code that may be referenced.
  • Write your code

Pattern: Prompt Knowledge Sharing

Prompt Knowledge Sharing

{% hint style="info" %}
This document is still under review. We welcome active discussion on the GitHub issue.
{% endhint %}

Description

Sharing prompts for generating code and using them as learning resources for team members is important.

Problem

Working with AI such as GitHub Copilot can help write high-quality code, but for senior engineers, whether great code or high-performance code is good code for code reading is a different story. When programs are represented by excessively abbreviated code or language-specific advanced expressions, collaboration among engineers in a specific area may become difficult.

Story

You are exploring what prompts to write to master GitHub Copilot. As a senior engineer, you collaborate with GitHub Copilot to produce great code through trial and error in implementing a certain feature. Another engineer on the same team who was watching you next to you said, "So you always write like that! I feel like I understand a little now how you always come up with great code."

You realize that the prompts you used to reach the best output through trial and error, as well as the process of trial and error itself, are important resources for team members to learn. At the same time, you discover the problem that prompts are not included in the output files, and you begin to think about how to share them.

Context

GitHub Copilot has been introduced, but how to use it has not been shared as each engineer uses it individually. In addition, the prompts written by each engineer in GitHub Copilot are not shared.

Solution

Discuss how to share prompts and write comments as a team and establish rules. It is desirable to make comments that also function as a document so that the prompts do not become noise.

The following patterns can be considered for sharing prompts:

  • Directly write in the file
    By leaving the prompts in the file for the team to learn, team members can learn from each other's prompts. It is important to leave prompts in an appropriate balance so that they do not become noise. Additionally, some prompts can be converted into document or explanatory comments rather than in prompt form. Furthermore, prompts can be reviewed along with code reviews, promoting the development of engineers.
  • Passive documentation
    Include some prompts in comments in pull requests or issues. This improves the readability of files containing code, but prompts cannot be referenced in the editor.
  • Mob programming
    Host mob programming sessions to experience the development environment of senior engineers without leaving prompts in files or PR/issues. It is important to share what is learned here as a separate document.

Resulting Context

The skills of the entire team will improve, and effective learning will be promoted through prompt sharing. The readability of the code will improve, and understanding of the code will be facilitated by comments that function not only as prompts but also as documents.

Pattern: Context-less Architecture

Description

Contextless architecture is a design pattern that limits coding to smaller, well-defined contexts within a system. By breaking complex programs into loosely coupled, independent components, this architecture improves maintainability, scalability, and flexibility.

When working with AI tools like GitHub Copilot, it is essential to understand their nature and limitations. Currently GitHub Copilot is not AGI (Artificial General Intelligence) and therefore works best within a limited and precise context. By focusing on specific needs, developers can maximize Copilot's accuracy and efficiency.

The key is to create a loosely coupled system where each component serves a specific purpose. This approach is consistent with the limitations of GitHub Copilot and allows developers to use the tool more effectively to build modular, robust software.

On the other hand, you should not design a system to fit the tools. This pattern is intended to more effectively speed up development by additionally considering the use of AI in development when it makes sense to be loosely coupled in real-world projects and products.

https://www.ai-native.dev/docs/design-patterns/context-less-architecture

Pattern: AI readable naming convention

Description

The AI readable naming convention focuses on the way we name variables and functions in our code to make them more readable by AI tools like GitHub Copilot. By avoiding generic and common programming names and embracing specific, descriptive names, we create code that both human developers and AI models which powers Copilot, can easily comprehend.
For example, an engineer creating a library system may use generic words such as "dictionary", "library", and "stack" for system variable names and function names. But what if the real type of the variable named "dictionaries" was an array? This is just an example, but GitHub Copilot may give the wrong answer when these things pile up. If you need to provide more context, it's a good idea to type hint or use comments to add context.
By following this pattern, we enhance the effectiveness of GitHub Copilot, leading to more accurate suggestions and increased developers' velocity.

https://www.ai-native.dev/docs/design-patterns/ai-readable-naming-convention

Pattern: Language translation

Description

Sometimes, developers may need to translate code from one language to another, such as from Python to JavaScript or HTML to Markdown. This is where GitHub Copilot shines as a virtual aide. Imagine a scenario where a team is working on a multi-platform project, and they need to quickly convert a Python algorithm into JavaScript for web integration. GitHub Copilot's Language Translation ability can save hours of manual translation, enabling seamless cross-language development.

https://www.ai-native.dev/docs/general/language-translation

Pattern: Regular expression

Note

Currently, LLMs like GitHub Copilot do not have the ability to properly represent complex regular expressions. What would you do if you want to represent a complex regular expression?

Description

GitHub Copilot can create a draft of regular expression patterns. Below, we'll explain how to use regular expressions to search or extract strings. Two examples illustrate how GitHub Copilot can generate regular expressions through both input-output pattern and natural language pattern.

https://www.ai-native.dev/docs/general/regular-expression

Pattern: Copilot snnipet handling

Description

GitHub Copilot, which utilizes OpenAI's Large Language Models (LLM) to generate code, has a limitation on the number of tokens it can process. As of 2023, it doesn't see all of the code that's open in the editor and doesn't receive every token. This means that users must carefully limit the context provided to GitHub Copilot. Notably, Copilot doesn't have access to external repositories or source code placed in GitHub Enterprise Cloud.

The files that GitHub Copilot uses for suggestions are primarily the currently open file and other tab files adjacent to it (basically with the same file extension). To make accurate suggestions, it's essential to have only the relevant files open. The following is a checklist as of August 2023. The types of files that GitHub Copilot includes as snippets may change in the future, but practices such as "closing unnecessary files" will likely have a positive impact on your coding even if you were not using GitHub Copilot.

  • Open the files you need to refer to
  • Close unnecessary files
  • If there is an .md file you want to refer to, copy it and comment it out

If your first language is not English, it's worth noting that English is a very token-efficient language. Expressing the same concept in Japanese or other languages might consume more tokens. Writing comments in English could save tokens, but be mindful of your team's language preferences as it might hinder development speed. Then it's putting the cart before the horse.

https://www.ai-native.dev/docs/client-side-tips/copilot-snippet-handling

Pattern: AI friendly documentation

Description

In the era of GitHub Copilot, an AI powered coding assistance tool, having easily accessible documents in text format becomes crucial. In the AI era, files such as Infrastructure as Code, database table specifications, test requirements, and more have the potential to be instantly transformed into actual code. Rather than dealing with complex Excel, PowerPoint files, PDFs, or image formats, AI will be able to assist your coding efforts collaboratively through text-based documents.

Let's check if the following files are text-based or AI friendly:

  • Infrastructure definitions
  • Database table definitions
  • Test specifications

Pattern: Writing test cases in natural language first

Description

When working with AI-powered code generation, like GitHub Copilot, expecting comprehensive test coverage without providing clear context to the AI is challenging. Instead of trying to write the test cases in code at that point, create natural language descriptions first. This will focus on improving the test coverage, ensuring that the generated code meets all the necessary criteria.

https://www.ai-native.dev/docs/test/writing-test-cases-in-natural-language-first

Pattern: Asking with open-ended questions

Description

Refactoring is often a complex process. It is not necessarily about what is right and what is wrong, but about understanding the basic concepts and potential improvements. using open questions in GitHub Copilot, developers can work on improving code in a more thoughtful way with the help of GitHub Copilot GitHub Copilot can help developers work on code improvements in a more thoughtful way.

https://www.ai-native.dev/docs/refactoring/asking-with-open-ended-questions

Pattern: Specify how to generate test code

Description

When it comes to testing, specific instructions can be a great way to make sure you're covering all the necessary scenarios. Instead of giving vague instructions like "add unit tests," you can provide concrete details about the testing frameworks and the number of cases you want to generate. This can be helpful in utilizing tools like GitHub Copilot, where specifying "use Junit and Mockito to add unit tests, testing at least 10 variations of valid and invalid input combinations" can yield a more accurate and comprehensive result.

https://www.ai-native.dev/docs/test/specify-test-valiation

Pattern: Coaching on prompts

Description

Using an AI tool like GitHub Copilot can make the output look cleaner than it should. Code that looks perfect when you review it may actually be inefficient in the generation process or missing something important. Coaching on the generative process becomes essential to ensure that developers are aware of potential pitfalls and can create efficient and accurate code.

In modern software development, coaching is more than just a review; it's an opportunity to guide, inspire, and improve. This pattern emphasizes coaching peers on the quality of prompts used in code generation, particularly with AI-driven tools like GitHub Copilot. Coaching aims to enhance not only the prompts but also the understanding of the generative process.

https://www.ai-native.dev/docs/collaboration/coaching-on-prompts

Pattern: Pin the files you need

Description

The effectiveness of GitHub Copilot depends on the context provided to it. GitHub Copilot searches through open tabs by text similarity, sending snippets to the Large Language Model (LLM), which itself is a complete black box. Therefore, we must be mindful of the context we want to provide. In programming, files such as declaration files (d.ts), test files, and interface files contain a wealth of context information. By using Visual Studio Code's pinning feature, you can easily access these files when needed and provide information to GitHub Copilot more efficiently.

https://www.ai-native.dev/docs/client-side-tips/pin-the-file-you-need

Pattern: Working on small chunks

Description

Working on small chunks of code with less context can lead to improved Copilot's output. Imagine you're building a complex application with several interconnected components. Instead of trying to generate everything in one go, you break down the task into smaller parts, providing a confined context for Copilot. This approach not only streamlines the development process but also enhances the quality of the generated code.

Some ideas consider context-less architecture in the design phase, but it is difficult to apply a loosely coupled architecture to every project.
Also, changing the architectural design to improve the accuracy of AI tools is not the way to go. This pattern aims to improve GitHub Copilot's proposal by at least working in small chunks so that the context is as small as possible in the working environment, so that GitHub Copilot does not become overwhelmed by the complexity of the overall project. more controlled, accurate, and efficient code generation that allows you to understand the specific tasks of the clues.

https://www.ai-native.dev/docs/design-patterns/working-on-small-chunk

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.