Giving the right prompt!

Giving the right prompt!

In this short article I want to show how GitHub Copilot can help you refactor your code.?

Let’s start with this code:

https://github.com/ansarmuhammad/GitHub_Copilot/blob/main/integration_test_v1.py

We have a method which is slightly difficult to read and understand, it shown below:


We would like to break it up into smaller methods.

If we just select the method and say “Refactor this code”, GitHub Copilot does nothing.? So, it is important to give the right prompt, do some hit and try if are you are not getting what you want.? The prompt which got me what I wanted is given below

Prompt: Break this method down to smaller methods

Here is the resulting code recommended by GitHub Copilot, you can see that now we have 3 easy to read methods instead of 1 large method.


You can find the new code file here:

https://github.com/ansarmuhammad/GitHub_Copilot/blob/main/integration_test_v2.py

A lot of times we can reduce technical debt by doing such small refactoring.? Having unit tests or at-least some integration tests help build confidence that this code will run as expected in production.

Do share how you are using GitHub Copilot to improve your productivity?

要查看或添加评论,请登录

Ansar Muhammad, PMP, PSM-1的更多文章

  • Join Us as a SME – USA Health Insurance! ??

    Join Us as a SME – USA Health Insurance! ??

    Are you passionate about transforming the health insurance domain with innovative software solutions? ?? Do you thrive…

  • AI Convergence Conference

    AI Convergence Conference

    It was a pleasure to speak at the conference! Met many interesting people, very nice to see a well executed AI…

    2 条评论
  • 3rd Code Quality Awards

    3rd Code Quality Awards

    “?? Celebrating Excellence in Code Quality Quarter 3 ?? Today, we come together to recognise and celebrate the…

  • Agile frameworks and MVP approaches

    Agile frameworks and MVP approaches

    Presenting Agile and MVP concepts to the receptive JazzCash team was a great experience! The way the training was…

    2 条评论
  • Using Machine Learning / Decision Trees to understand your data

    Using Machine Learning / Decision Trees to understand your data

    Sometimes it is hard to understand your data without the help of some Machine Learning tools, one very useful open…

    1 条评论
  • Synthetic data generation for email summarization tool testing

    Synthetic data generation for email summarization tool testing

    Currently I am working with some students on a project (let's call it tool-1), it is being designed to have the…

    2 条评论
  • Data Insights through GenAI

    Data Insights through GenAI

    Some of you already might be using GenAI for your data analytics. In this article I just wanted to walk you through a…

  • How Integration Tests reduce developer fatigue?

    How Integration Tests reduce developer fatigue?

    Some stakeholders who are not familiar with the value of unit and integration tests might not fully appreciate the…

  • GitHub Copilot in Action

    GitHub Copilot in Action

    I see a lot of developers still considering this powerful tool more as a toy rather than a production level tool…

  • Teaching high school students how to program and build logic

    Teaching high school students how to program and build logic

    Most of us know some young very smart person, who is convinced that they can’t learn to program. Maybe they tried it at…

社区洞察

其他会员也浏览了