Skip to content

Commit b7de825

Browse files
committed
initial commit
1 parent 1376275 commit b7de825

15 files changed

Lines changed: 544 additions & 27 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
13
# Byte-compiled / optimized / DLL files
24
__pycache__/
35
*.py[cod]

LICENSE

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
MIT License
1+
MIT License
22

3-
Copyright (c) Microsoft Corporation.
3+
Copyright (c) 2024 Alfredo Deza
44

5-
Permission is hereby granted, free of charge, to any person obtaining a copy
6-
of this software and associated documentation files (the "Software"), to deal
7-
in the Software without restriction, including without limitation the rights
8-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
copies of the Software, and to permit persons to whom the Software is
10-
furnished to do so, subject to the following conditions:
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
1111

12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
1414

15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 144 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,148 @@
1-
# Project
1+
<h1 align="center">Migrating a Python API to Rust with GitHub Copilot</h1>
2+
<h5 align="center">Perform a challenging migration to a completely different language</h3>
23

3-
> This repo has been populated by an initial template to help get you started. Please
4-
> make sure to update the content to build a great experience for community-building.
4+
<p align="center">
5+
<a href="#mega-prerequisites">Prerequisites</a> •
6+
<a href="#books-resources">Resources</a> •
7+
<a href="#learning-objectives">Learning Objectives</a>
8+
</p>
59

6-
As the maintainer of this project, please make a few updates:
10+
- **Who is this for**: Any tecnologist that is looking to apply AI pair-programming techniques with GitHub Copilot to perform challenging work like migrating or translating from one programming language to another.
11+
- **What you'll learn**: You'll use advanced GitHub Copilot techniques that are specifically useful when translating projects in different programming languages.
12+
- **What you'll build**: An HTTP API that uses Rust with full compatibility from the original HTTP API written in Python.
713

8-
- Improving this README.MD file to provide a great experience
9-
- Updating SUPPORT.MD with content about this project's support experience
10-
- Understanding the security reporting process in SECURITY.MD
11-
- Remove this section from the README
14+
> [!NOTE]
15+
> Looking for the workshop? Head over to [the workshop directory](./workshop)
16+
17+
## Learning Objectives
18+
19+
In this workshop, you will:
20+
21+
- Use advanced GitHub Copilot interaction techniques to deal with a legacy project
22+
- Iterate, validate, and refine answers to upgrade the legacy project and validate its correctness
23+
- Apply generic concpets that can improve suggestions and select from different strategies that can yield better results.
24+
- Build a thorough testing strategy to help you identify potential issues and
25+
validate the project in its final state after upgrading.
26+
27+
## :mega: Prerequisites
28+
29+
Before joining the workshop, there is only one prerequisite: you must have a public GitHub account. All resources, dependencies, and data are part of the repository itself. Make sure you have your GitHub Copilot license, trial, or the free version.
30+
31+
32+
## Main takeaways
33+
34+
### 1. Define Clear Objectives and Requirements
35+
36+
*What needs to be achieved?*
37+
38+
Start by understanding the end goal clearly. What is the result you're after? For migrating a project from one programming language to another, you must ensure a thorough testing strategy that can help you validate correctness and completion when making critical changes.
39+
40+
*What are the constraints?*
41+
42+
Identify limitations or exclusions. For example, large language models (LLMs) can have (or lack) enough context to provide the right suggestions. It is up to you, the driver, to make decisions that achieve your goal. Certain business logic might prevent you from adding other external libraries or functionality. For example, if you are migrating a project that is used in a production environment, you might not be able to add new libraries or functionality that could break the existing code.
43+
44+
> [!TIP]
45+
> Focus on being precise with the scope of the problem. If you're unsure, start broad and then progressively narrow down the details.
46+
47+
### 2. Break Down the Problem into Components
48+
49+
Decompose the migration process into smaller, manageable pieces. For example, start with the core application components and then test a single API endpoint or library function. This makes it easier to understand and solve the problem step-by-step:
50+
51+
- Identify and migrate single public, exposed functions, or API endpoints from Python to Rust
52+
- Develop and run tests, set up test environments, and create validation scripts to ensure correctness
53+
- Handle configuration and installation processes for the new Rust environment
54+
55+
Ensure you're applying each condition step-by-step. In programming, breaking down a complex function into smaller helper functions can make it easier to write, debug, and migrate.
56+
57+
> [!TIP]
58+
> Decomposition is a great way to deal with complexity, as it allows you to focus on one small task at a time.
59+
60+
### 3. Leverage Domain-Specific Vocabulary and Context
61+
62+
Use the appropriate terminology for the migration process. Whether you're translating Python code to Rust, working with APIs, or designing algorithms, being familiar with the domain vocabulary helps you form more accurate instructions for tools like GitHub Copilot or while communicating with others.
63+
64+
For example, understanding terms like "borrow checker" in Rust or "decorators" in Python can help you better navigate the migration process and communicate effectively with others involved.
65+
66+
> [!TIP]
67+
> The more precise the vocabulary and context you use, the easier it is for both humans and tools to understand and generate solutions.
68+
69+
### 4. Iterate and Refine the Solution
70+
71+
Start simple, then refine. In complex problems, initial attempts are rarely perfect. Start by generating a basic solution and progressively build on it.
72+
73+
In this workshop for migrating an application from Python to Rust, you might want to start with a single function or piece of functionality and then isolate it, while subsequently adding complexity. For example, begin by translating a simple Python function to Rust, then incrementally add more complex features and integrations.
74+
75+
> [!TIP]
76+
> With every iteration, test and verify against expected outcomes to ensure the result is moving in the right direction.
77+
78+
### 5. Use Examples to Clarify Requirements
79+
80+
When creating prompts for AI models or explaining problems, provide examples. An example can illustrate your expectations, making the task clearer for anyone or anything (including tools like GitHub Copilot) involved in solving the problem.
81+
82+
For instance, with migration code, you could explain what the inputs and expected outputs can be while including the logic to accomplish the task.
83+
84+
> [!TIP]
85+
> Example-driven problem-solving helps align understanding. It's especially useful for ambiguous tasks.
86+
### 6. Identify Patterns and Reuse Solutions
87+
88+
Recognize common patterns in your migration process and reuse solutions where applicable. For example, when migrating from Python to Rust, you might notice recurring patterns such as handling data structures, managing memory, or implementing similar algorithms. Once you identify these patterns, you can reuse and adapt these building blocks for different parts of your project.
89+
90+
In code migration, identifying reusable functions or logic can save time and reduce errors. For instance, if you have a common way of handling API requests in Python, you can create a similar reusable function in Rust.
91+
92+
> [!TIP]
93+
> Recognizing patterns is a hallmark of experience. As you encounter similar migration challenges repeatedly, you'll start to see similarities that can speed up your process and improve consistency.
94+
95+
### 7. Use Constraints and Edge Cases for Robustness
96+
97+
Think about edge cases and exceptions. Complex problems often involve handling not just the "ideal" data, but also the "edge" or "outlier" cases that might break a naive solution. Ensure that your prompt or solution accounts for these edge cases.
98+
99+
In migration code, this might mean considering how the code behaves with unexpected inputs which would guide you to write new tests or modify existing ones.
100+
101+
> [!TIP]
102+
> Thinking through edge cases helps you build more resilient, generalized solutions.
103+
104+
### 8. Use Tools Effectively
105+
106+
Whether you’re using GitHub Copilot, your editor auto-completion, or another form of automation, leverage the tools at your disposal but make sure you're guiding them with the right context. Tools are great for speeding up the generation, but they still need well-structured inputs and validation from you.
107+
108+
For GitHub Copilot, ensure that your prompts are detailed, but concise. Tools often work best when given structured input that leaves little ambiguity.
109+
110+
> [!TIP]
111+
> Be specific with your tools, but also check results, as tools might not always fully understand context unless properly guided.
112+
113+
### 9. Seek Feedback and Collaboration
114+
115+
When tackling a complex task, especially one that involves code or queries, collaboration and feedback are crucial. Don’t hesitate to ask peers or communities for insights or review.
116+
117+
For example, when rewriting complex functions or code blocks, having a second pair of eyes can help catch mistakes or suggest improvements. This is especially true in migration projects where the original intent might not be clear.
118+
119+
> [!TIP]
120+
> Collaboration often brings new perspectives, reducing blind spots.
121+
### 10. Test and Validate
122+
123+
Testing and validation are key to ensuring that your solution works as expected. In the case of migrating code to another programming language, this is even more critical, as you want to ensure that the new code behaves similarly (or exactly the same) as the old code.
124+
125+
Testing ensures that both the expected and unexpected situations are handled correctly, and that the migration has not introduced any new issues.
126+
127+
> [!TIP]
128+
> Always have a validation step built into your process to catch mistakes early and ensure the migrated code meets all requirements.
129+
130+
Generalization for Other Use Cases:
131+
For writing code or algorithms: The same concepts apply when generating functions, classes, or workflows. Clearly define input, expected output, edge cases, and iterate to refine.
132+
133+
For AI model prompts: When asking for something complex (like generating code, text, or designs), give clear objectives, break down the problem, provide context, and iterate.
134+
135+
For design or content generation: Define the purpose, break down design elements, and provide examples or inspiration, then refine based on feedback.
136+
137+
Final Thoughts:
138+
Complex generation problems often involve a balance of clarity, decomposition, iteration, and validation. Whether it's a migrating from one programming language to another or any other task, keeping these concepts in mind will allow you to generate more accurate, efficient, and reliable results.
139+
140+
## :books: Resources
141+
142+
Although not required, some of the features this workshop covers are in these Microsoft Learning modules:
143+
144+
- [Code with GitHub Codespaces](https://learn.microsoft.com/training/modules/code-with-github-codespaces/)
145+
- [Using advanced GitHub Copilot features](https://learn.microsoft.com/training/modules/advanced-github-copilot/)
12146

13147
## Contributing
14148

@@ -26,8 +160,8 @@ contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additio
26160

27161
## Trademarks
28162

29-
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
30-
trademarks or logos is subject to and must follow
163+
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
164+
trademarks or logos is subject to and must follow
31165
[Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
32166
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
33167
Any use of third-party trademarks or logos are subject to those third-party's policies.

0 commit comments

Comments
 (0)