- Learning objectives
- Success criteria
- 1. Setup your environment
- 2. Understand the code
- 3. Convert the code
- 4. Test the code
- 5. Add documentation
- 6. (optional) Convert the code into other languages
- Conclusion
👉🏼 Use GitHub Copilot to understand the code.
👉🏼 Convert the code to Python.
👉🏼 Test the code.
👉🏼 Document the code.
🎯 A Python program that covers the same functionality as the legacy code.
Follow this guide to configure your environment and login to GitHub.
Open app.asp and review the code. If you are not familiar with ASP.NET, don't worry. We will use GitHub Copilot to help us understand the code. Open GitHub Copilot Chat, select all the code to ensure GitHub Copilot uses the entire files as context and use GitHub Copilot Chat to explain the code to you.
💡 What the code is actually doing
The VBA script reads data from a CSV file and dynamically generates an HTML table displaying the company data.
As we now know what the code is doing, we can start converting it to Python. Again we will use GitHub Copilot Chat to help us. Select all the code and ask GitHub Copilot Chat to convert the code to Python.
Note
The results may vary. In the most cases GitHub Copilot will generate code using Flask
. If your result is different but still covers the same functionality, that's fine. You are in the driver seat. Decide what library and implementation you want to use :) Whatever libary you choose, make sure it is installed. GitHub Copilot usually gives you additional instructions on how to install the library with pip install
.
🟦 Create a new app.py
file and copy paste the code in it.
The next step is that we want to ensure that the code is working as expected. Use GitHub Copilot Chat to ask for a test that covers the functionality of the code.
💡 GitHub Copilot tip
@workspace /tests
or just/tests
add more context if you want to test something specific
🟦 Create a new test_app.py
file and copy paste the test in it.
🟦 Refine the tests until they all succeed, maybe you also need to adjust the code in your app.py
file.
The last step is to add some documentation to your code. Use GitHub Copilot Chat to generate documentation for both your app.py
and test_app.py
files. You can solve this however you like. You can create a new markdown file to describe your code and/or add comments where needed.
💡 GitHub Copilot tip
Please generate documentation for this code
orPlease add comments to this code
🟦 Add the generated documentation and/or comments to your code.
Python might not be the target language you want to convert the code to. You can repeat the steps above and convert the code to another language. You can also convert the code to multiple languages. The choice is yours.
Try to repeat the process and ask GitHub Copilot Chat to convert the code to:
- JavaScript
- C#
- Java
✨ Let's review! Generated everything needed with a single command? Assisted on testing the App? Generated good documentation?