DEV Community

Viet Anh Le
Viet Anh Le

Posted on • Updated on

How does GitHub Copilot help me code faster?

Sometimes I cannot remember why I typed my codes orprecisely what is wrong with my members’ coding lines.

I am tired of coding after typing comments. Is there a way to help me do both at once time? I used to code with Tabnine. However, it uses a ton of memory used, and it did not make me truly satisfied.

After using GitHub Copilot for only one day, it had me first when using it. Believe me or not, it is the best recommendation AI platform at this time.

Here are things I am going to share with you in this blog post:

  1. What is it, and how it helps?
  2. The effects of its suggestions?
  3. Test in a (ReactJs, ExpressJs) project sample
  4. Some problems of Copilot and suggestions for resolving them
  5. Small compare: Memory used between Copilot and Tabnine

What is it, and how it helps?

GitHub Copilot is a product of the partnership between Microsoft and AI research and deployment company OpenAI.

"OpenAI Codex was trained on publicly available source code and natural language, so it understands both programming and human languages." (copilot.github.com).
Many open-source repositories on GitHub or public forums (including stackoverflow.com) are the data of Copilot. It is based on the context codes (They may be in a docstring, comment, function name, or the code itself). The AI will index ten suggestion solutions on your editor. By doing that, you do not need to switch between Google and your editor for searching the sample exams. As a result, you will save a lot of time looking, which means code faster and less work.

How good are the suggestions?

Base on my experience using it while working with my team at Jslancer. I would like to share with you some great highlights.

In order to use Copilot, your code and your comments must follow a specific rule. These rules can be defined by yourself or your technical leader. Therefore, your variable names, function names will be consistent. Everything will focus on its purpose.

Junior developer: can view and understand at least ten ways to write their codes. The most important thing is that all of those coding lines suggested by GitHub Copilot should be carefully tested, reviewed, and vetted, like any other code (copilot.github.com).

Senior developers or team leaders will be easier to understand what their team members wrote.

For example:

A leader can create name rules:

  • Request API: method + Type API + Api ( getUserApi, delUserApi…)
  • Some hooks functions: use + hook name (useForm, useFetch…)

Test in a project sample:

Let’s get started with some simple functions. Suppose that you are creating a signup form, and you are going to write some input validation functions. So I make a file called validationHelper.ts and write a function to validate an email address.
I wrote the first line:
image

, and waited for 3 secs, it shows a suggestion, and I just need to press the “tab” or “enter” to apply that suggestion to my code.
The suggested regex pattern is correct. It is also tested against my variable name “input,” which is exactly what I want.
I also write another function: validateWebsite, and it also works well. It also suggests a function: validatePhoneNumber even before I write the third function.
image
Second example:

Trigger file download in the browser is a reasonably common frontend task. We usually create a hyperlink element, set the href to the download URL, insert it into the document, and then simulate clicking on that link.
The first suggestion is not really what I want because the hyperlink element is not removed from the document after the downloading has been triggered. Fortunately, Copilot can provide some other suggestions if the first suggestions don’t match your goal.
image

Third example: Create Login Form

Let’s create a login form using react-hook-form. This is my favorite form library due to its popularity, ease of use, and performance.

So I started by write 2 lines:
image
This time, the suggestions are not correct anymore since Copilot fails to recognize the react-hook-form and shows hints of formik. So we can not use any of these suggestions.
Maybe in the future version, Copilot will evaluate the coding context better.
image
The barrier(s) or problem(s) that you may face

  1. The technical preview is restricted and not available to everyone
    => You have to register with the developing team to use it (it is elementary).

  2. The Copilot suggests code lines base on the context. Unfortunately, that means users have to write clear variable names, function names, or comments. It is a difficult task for a junior developer.

=> In my opinion, the Copilot team should give some advice for users while declaring functions, variables by their features (e.g., request API, sort array, upload file, etc.). By doing that, users know how to use Copilot in the most effective ways and learn more about the coding style (at least for beginners). The more using Copilot, the more juniors will be familiar with the formal methods.

  1. Sometimes I merge its suggestion into my code lines, there is an error from the braces or brackets

A small comparison between Copilot and Tabnine.

If memory used is what you concern about, I strongly recommend you should try Copilot. It uses Ram less than Tabnine.

Conclusion

Currently, GitHub Copilot supports five languages such as Python, TypeScript, JavaScript, Ruby, and Go.

Suppose you are developing an app with one of those coding languages; you should try it right now. If not, you have to wait for a new update. As a ReactJS front-end developer, I will continue to use it as much as possible.

For me, Tabnine helps me auto-complete, write code faster. Copilot helps me RESOLVE MY PROBLEMS in FEW SECOND on my EDITOR.

The commercial product of Copilot may be launched soon. However, before doing that, the Copilot team needs to prove that some sensitive codes cannot be public.

See you in the following article,

Happy coding, and thank you for reading.

Copywriter: Felix Le

Any comments, please send to: mc.vietanh@gmail.com.

Top comments (1)

Collapse
 
tabnine profile image
Tabnine

Hi Viet, interesting article! We are glad to hear that Tabnine makes you code faster. As for memory consumption, you may enable cloud-mode through Tabnine Hub to reduce resources consumption.
Tabnine.com