Top 10 GitHub CoPilot Hacks that Every Java Developer Should Know

Top 10 GitHub CoPilot Hacks that Every Java Developer Should Know
Published on

This article features the top 10 GitHub CoPilot hacks for numerous languages like Python and Java

In June 2020, OpenAI released a language model called GPT-3. This model is really good at understanding natural language and surprisingly, it has some coding capabilities even though it wasn't trained in code. After this discovery, OpenAI developed Codex. Codex is another GPT language model that has fewer parameters – runs faster and is not as flexible as GPT-3, has more memory – can read more and grasp context better, and lastly, it was trained and fine-tuned with code examples from GitHub and Stack Exchange. GitHub Copilot provides suggestions for numerous languages and a wide variety of frameworks but works especially well for Python, JavaScript, TypeScript, Ruby, Go, C#, and C++. The following samples are in Java, but other languages will work similarly. In your JetBrains IDE, create a new Java (*.java) file. This article features the top 10 GitHub CoPilot hacks that every Java Developer should know.

Use Copilot for initial API discoverability

Copilot understands common open-source APIs exceptionally well. Using the AWS SDK and don't know what the SendMessage signature is for SQS? Forget how to instantiate a client? Copilot can be a quicker first touch to an API than the documentation. It might even suggest helpful flags or parameters that you missed. It is one of the top 10 GitHub CoPilot hacks that every Java Developer should know

Assisting non-native English speakers

GitHub Copilot can understand other languages beyond English! This is helpful for developers of all backgrounds because programming languages are based on American English. For example, the CSS property color is based on American English, so it is unfamiliar for native British-English or Canadian-English speakers who use the spelling 'colour'. Forgetting the correct spelling and syntax can often result in typos, unexpected errors, and lost time.

It's a pair programmer

When Microsoft and GitHub talk about Copilot, they refer to it as a "pair programmer." Maybe this is a way to calm the fears of developers worried about being rendered obsolete, or maybe it's just a descriptive title: rather than writing code itself, Copilot is meant to work alongside devs, to help them reduce tedious tasks, and to speed up their work — so they can get on to more important, interesting, conceptual work. When you prompt it, it completes your thought.

Creating dictionaries with lookup data

Martin Woodward, Vice President of Developer Relations at GitHub, shared this tip with us! GitHub Copilot is great at creating dictionaries of lookup data. Try it out by writing a comment instructing GitHub Copilot to create a dictionary of two-letter ISO country codes and their contributing country name. Writing a comment and the first few lines of code should help GitHub Copilot generate the desired results. It is one of the top 10 GitHub CoPilot hacks that every Java Developer should know

Write the interface first, then the auto-generate the implementation

Another best practice that is enhanced by Copilot. Writing an interface or function signature first usually primes Copilot sufficiently well. Then, for utility functions, it can generally autogenerate the entire block.

Doesn't compile, doesn't test

What GitHub Copilot is, right now: a great source of potential. What it isn't: everything a dev does. For example, Copilot doesn't compile code, and it doesn't test it — it just suggests solutions for code based on prompts or requests a dev types out. Copilot may produce up to ten suggestions, but human intelligence is still required to identify, implement, test, and choose the best solution.

Exiting Vim

Developers who are new to Vim frequently wonder how to exit the editor. Struggling to exit vim is so common that it's a meme on the internet! Since GitHub Copilot is available in Visual Studio Code, JetBrains, and Neovim, a forked version of Vim with additional features, you can exit NeoVim using GitHub Copilot. It is one of the top 10 GitHub CoPilot hacks that every Java Developer should know

Not just for code, but static data

Copilot is great for generating protobuf definitions, YAML configuration, repetitive constants, and other types of data. While we might want to reduce repetition, DRY isn't always the best way. Schema definitions should adhere to a somewhat strict style, which makes them perfect for Copilot.

Search less, produce more

As GitHub CEO Nat Friedman explains in a blog post introducing Copilot, the technology is poised to "help developers quickly discover alternative ways to solve problems, write tests, and explore new APIs" without having to search on sites like Stack Overflow.

Prefer a little copying over a little dependency

Instead of vendoring in left-pad as a dependency, use Copilot to generate the function. There are benefits to using battle-tested generic libraries but also benefits to bringing simple code in-tree. It is one of the top 10 GitHub CoPilot hacks that every Java Developer should know.

Join our WhatsApp Channel to get the latest news, exclusives and videos on WhatsApp

                                                                                                       _____________                                             

Disclaimer: Analytics Insight does not provide financial advice or guidance. Also note that the cryptocurrencies mentioned/listed on the website could potentially be scams, i.e. designed to induce you to invest financial resources that may be lost forever and not be recoverable once investments are made. You are responsible for conducting your own research (DYOR) before making any investments. Read more here.

Related Stories

No stories found.
logo
Analytics Insight
www.analyticsinsight.net