DEV Community

Cover image for AI Series Part II: Tips for using GPT and Copilot as a Developer
Tiago Souto
Tiago Souto

Posted on

AI Series Part II: Tips for using GPT and Copilot as a Developer

Previously, I wrote a bit about how I started working with LLMs and some shallow and basic AI concepts I understood so far.

Before we move forward to the code, let’s talk about something I believe is very important nowadays and that will probably change forever how we do coding.

The usage of generative AIs reached an unexpected spot really fast, as it’s very intuitive and can help people in many ways we can’t even imagine. But speaking from a software engineer/developer perspective, I can visualize on not so far future we look back in time and wonder “how did people used to write code without AI assistance?” because the benefits and performance boosting are so huge that will feel odd to work without it, just like it’s odd to someone used to work with strongly typed languages starts working with a non typed language.

Many people are afraid of AI and others say it’s going to steal our jobs or software engineering is condemned to fade. Recently, the Devin project made a lot of noise in the community as it’s claimed to be the solution to replace human developers. To be honest, I don’t believe in anything of that. AIs are tools, and tools are made for a purpose. For a software engineer, AI can be used to automate repetitive tasks, help troubleshooting a problem, find a quick solution, and many other cases that we’ll explore a bit more in this post. But at the end of the day, there’s one main purpose: boost productivity.

Image description

A Misconception

People are used to thinking that the economy is related to hard work. So the harder people work, the richer they get. But that’s wrong. The economy is related to productivity. That’s why the Industrial Revolution changed the world. Not because everybody worked harder, but because they could make things faster. What do the top highest GDP countries have in common? They all are highly productive. And, a similar concept can be applied to individuals. You’ll get richer (and understand that as monetary, freedom, free time, or as you want) as more productive you are. So fighting against the solutions that will help you get more productive is a mistake.

Some companies may start firing people as their crew productivity increases in a way costs can be reduced. However, opportunities will also be created as the barrier to starting a business is reduced. As long as the demand in the market keeps growing, the need for solutions will also grow. So those who are prepared to deliver high-quality work with high productivity may be compensated.

Let’s use the tools we have available to us to our advantage so we can focus on what we’re good: solving problems.

Tips

There are some patterns I like to use when working with GPT and Copilot that help me to instruct the tools to get the results I want other than just letting it guess. Here are a few tips for you to get started.

GPT

Let's start by mentioning a few things that GPT can help you with and a prompt example to achieve that goal:

Brainstorming: GPT can be a great tool for brainstorming ideas or generating content
Prompt example: What are some resources or tutorials to learn {specific technology/framework}

Learning: You can use GPT to learn about new topics or concepts.
Prompt example: Can you explain how to implement {specific algorithm or data structure} in {specific programming language}?

Code generation: You can ask GPT to generate a piece of code for you.
Prompt example: Can you provide a code snippet to connect to a database using {specific programming language}?

Code explanation: You can ask GPT to explain a piece of code to you.
Prompt example: Can you explain what this code is doing {specific algorithm or data structure} in {specific programming language}?

Debugging: You can describe a bug you’re experiencing and ChatGPT may be able to suggest possible solutions.
Prompt example: Can you help me understand the error message {specific error message} in {specific programming language} and give me an example of how to fix it?

You can use it as many other ways you can imagine, like asking it to write unity tests for your code, rewrite a given programming language script using another programming language, ask it to review your code and suggest improvements, write documentation to your code, and many others. A few other tips you may find helpful:

  1. Be clear on your prompt and provide context as much as possible
  2. Ask a single question per request; avoid asking subsequent questions on the same prompt
  3. Use triple quotes to indicate the context/code content (i.e """context""", context ) 4. Make it clear what programming language you’re referring to. You can do it in the context like this javascript \n console.log(‘foo bar’) \n
  1. Give a role to the GPT. If you want it to write a code, start the prompt telling the GPT it’s an experienced software engineer with sharp Python knowledge; or it’s a professor teaching a student about algorithms; or anything else that matches how you want the GPT to behave It’s good to keep in mind the GPT limitations. GPT is a powerful tool, but it’s not perfect. It doesn’t understand context in the same way humans do and can sometimes provide incorrect or nonsensical responses. So your reasoning over the responses is crucial. Always double-check if the responses make sense and be prepared to fix any misinformation the GPT may provide.

Copilot

Copilot is another great tool for boosting your performance as you write code. I used to use 2 main ways to directly ask it to generate codes instead of passively waiting for it to guess:

  1. Add a comment to your code as something like “function to calc 2 ints and return the result”. Then in the next line start writing the function and Copilot will complete the code for you

Image description

  1. Write a non-typed function and use it to generate the TypeScript types. It can recognize how every argument is used, look for similar approaches in the code, and create the full Type object.

Image description

Using strategies similar to those above, you can do really lots of things with Copilot support, such as:

  1. Code generation
  2. Learning new language
  3. Use it for code reviews
  4. Use it for writing tests
  5. Use it for documentation

Conclusion

Image description

The advent of AI in the software development landscape is not a threat but an opportunity. It’s a tool that can significantly enhance our productivity, streamline our workflow, and help us deliver high-quality work more efficiently. The fear of AI replacing human developers is unfounded. Instead, AI tools like GPT and Copilot are here to assist us, automate repetitive tasks, and help us troubleshoot problems more effectively.

GPT can be a great tool for brainstorming, learning, code generation, code explanation, and debugging. On the other hand, Copilot can boost your performance as you write code. It can help with code generation, learning new languages, code reviews, writing tests, and documentation. The trick is to actively instruct it to generate codes instead of passively waiting for it to guess.

There are many other ways of using AI to our advantage, those are just a few examples to give you insights. Now it’s up to you to use a human capability that AI doesn’t have: your creativity.

Hope this can be of any sort of help. Next, we’ll start writing some code.

Top comments (0)