ChatGPT seems to be the buzz of the world (or so it seems). It has been tried by all, for fun or for play, but the real question is whether it can be used to accomplish our tasks, and if so, in what capacity. This is why we gave our developers a job – to find out how to use ChatGPT to help you write code faster

If you’re coming from the software development world (and even if you aren’t) there’s a high chance you’ve heard of ChatGPT. Nevertheless, we’ll explain a little bit about it. And for those of you who are already using ChatGPT for writing code we will do a deeper dive and explore the 5 best ways ChatGPT can help developers write code faster and more efficiently.

Here is a brief description of ChatGPT

Let’s quickly define what ChatGPT is.

ChatGPT is an artificial intelligence language model created by OpenAI, based on the GPT-3.5 architecture. It is designed to generate human-like responses to natural language inputs, allowing it to carry out conversations with people on a wide range of topics. ChatGPT is trained on a massive corpus of text data, enabling it to understand the nuances of language and generate coherent and relevant responses. Its abilities include answering questions, completing sentences, generating text based on prompts, and much more.

While ChatGPT is a very powerful language model, it still has some limitations. Some of them are as follows:

  1.     Contextual understanding: ChatGPT can generate responses based on the words and phrases in its input, but it may not always fully understand the context or underlying meaning of what is being said. This can lead to responses that are technically correct but miss the mark in terms of relevance or appropriateness.
  2.     Bias: Like any machine learning model, ChatGPT can be subject to bias in its responses. This can be a result of biases in the data it was trained on or in the way it was programmed. While efforts have been made to mitigate this, it remains a challenge for AI language models.
  3.     Creativity: While ChatGPT can generate text based on prompts and has some ability to come up with novel responses, it is not truly creative in the way that humans are. It lacks the ability to truly understand and appreciate art, music, humor, and other forms of creativity.
  4.     Domain-specific knowledge: ChatGPT’s knowledge is based on the data it was trained on, which may not always be comprehensive or up-to-date. It may also lack specific knowledge in certain domains or fields, making it less useful for specialized tasks or topics.
  5.     Empathy: ChatGPT is not capable of empathy or emotional intelligence, which limits its ability to engage in emotionally complex or sensitive conversations in the same way that humans can.

(Source: ChatGPT)

So ChatGPT will replace developers, right?

Your first question when you heard about ChatGPT or started using it is probably this one. Your answer was probably yes.

Immediately followed by a no.

As we’re still in this phase of AI development where things change almost daily and new technologies are being developed, it’s impossible to predict something like that.

However, we will make a prediction, but we are aware that throughout history people made many wrong predictions about technology, so take this with a grain of salt. Some of the tasks that programmers do (especially repetitive ones) can be automated with ChatGPT, resulting in greater productivity, and, ultimately, a reduction in the number of programmers needed. To give you some perspective, below is a picture of an architecture studio from the 1970s. In today’s world, tech solutions like ArchiCAD allows one person to do the same job as all of these people back then in just a few hours. But did ArchiCAD replace architects?

Architect drawing blueprint

How to use ChatGPT to write code

Now that we have put our fears aside, let’s explore 5 best ways to write code with ChatGPT. As a developer, writing code is a significant part of your daily routine. However, coming up with the right code can be challenging and time-consuming. ChatGPT is a large language model designed to understand natural language and provide relevant responses. As a result, it makes it easier for you to write code faster. We’ll examine the 5 most common use cases of ChatGPT when writing code. We are using ChatGPT to show you realtime examples and are including screenshots.

1.    Generating code snippets

When writing code, this will probably be the most common use case for ChatGPT. Whether you’re a web developer, a mobile developer, or any other type of developer, you’ll probably have to write some boilerplate code. This is where ChatGPT comes in handy.

With ChatGPT, you can request a code snippet for a particular task or language and get a response within seconds. It can also assist with syntax and formatting, ensuring that your code is clean and readable.

For instance, let’s see how ChatGPT can help us create a starter code for a full-stack MERN (MongoDB, Express, React, Node) application.

ChatGPT prompt for generating starter code for MERN stack app

ChatGPT output for generating starter code for MERN stack app

chatGPT output for generating starter code for MERN stack app

chatGPT output for generating starter code for MERN stack app

chatGPT output for generating starter code for MERN stack app

It took ChatGPT a few seconds to generate the response, and all we have to do is copy-paste these code snippets into files already created in our project. Also included was a note about installing and configuring the dependencies.

Not to mention that we wrote a very non-specific ChatGPT prompt (“Generate a starter code for MERN stack application”). ChatGPT’s response would also be more specific and detailed if we wrote a more specific prompt.

To expand our prompt, let’s ask it to add a form to our React app for adding new users:

asking ChatGPT prompt to add a form to our React app for adding new users

ChatGPT output on prompt to add a form to our React app for adding new users

ChatGPT output explanation on prompt to add a form to our React app for adding new users

When we made the prompt more specific, we didn’t just get a more detailed code snippet, we also got a more detailed explanation of what this code does.

We focused on our front-end application, but we can also use ChatGPT to develop our back-end application.

Let’s extend our request even further by asking it to add styling using Tailwind CSS and placeholders for input fields:

asking ChatGPT to add styling using Tailwind CSS and placeholders for input fields

ChatGPT adding styling using Tailwind CSS and placeholders for input fields

ChatGPT adding styling using Tailwind CSS and placeholders for input fields and explaining its code

Now, ChatGPT added Tailwind code to our form, making it responsive and styled to our needs. Also, same as in the previous examples, it gave us a brief but detailed explanation of the code it generated.

2.    Debugging code

There is an inside joke that developers often use: Coding is 1% writing code; The other 99% is debugging. On a serious note, debugging is really a crucial (and often less fun) part of the whole development process. Luckily, ChatGPT can help us here, too. Let’s try to intentionally add a bug to a code snippet and ask ChatGPT to find it. We will use a function for flattening JSON objects, but will define a “result” variable as an array, whereas expecting an object in that place:

ChatGPT finding a bug in the code snippet

 

Now, let’s see ChatGPT’s response:

chatGPT code debbuging response

Even though this was pretty much an obvious bug and could easily be avoided using some VS Code extensions or even better – TypeScript, ChatGPT did a good job finding it and giving us an explanation of our bug along with the solution for it. In the case of more complex bugs and errors, you’ll probably need to spend some time figuring it out on your own, but what better way to learn?

3.    Code Review

Code review is an essential step in the coding process. It involves reviewing code to ensure that it is readable, maintainable, and efficient. With ChatGPT, you’ll be able to receive great help with code review. It can definitely help identify potential issues with code and provide recommendations on how to fix them.

For example, if you want to ensure that your code is readable, you can ask ChatGPT for a code review. It can provide feedback on the code’s readability, suggesting ways to simplify or optimize the code. ChatGPT can also review code for maintainability and efficiency, providing recommendations on how to refactor the code to improve its performance.

Let’s try one basic example of using React’s useEffect hook. We will define a function inside this hook, which will work fine by itself (we won’t get any errors), but as our codebase grows and becomes more complex, it may cause some issues.

chatGPT code review prompt

Let’s see if ChatGPT catches this:

chatGPT code review output

ChatGPT reviews code

Here we can see ChatGPT gave us some feedback on our code snippet, and it also gave us a changed code snippet with some of its suggestions applied. In other words, it did not follow suggestion #2, which said to “Use meaningful variable names”. This is one of the examples where you should be careful when using ChatGPT for writing code.

4.    Learning New Programming Languages

When it comes to learning a new programming language, it can be a daunting experience. However, ChatGPT can help make the process easier. ChatGPT can provide resources and tutorials on different programming languages, making it easier for developers to learn and understand the language’s syntax and features.

It provides resources on new programming languages, for instance. By providing tutorials, documentation, and examples, it can make it easier for developers to learn and write code faster.

Asking chatGPT to provide useful resources for learning Python

5.    Natural Language Processing

Developers can communicate their ideas and code-related questions more easily with ChatGPT, which understands natural language. It can understand complex queries and provide relevant responses, saving you a lot of time and effort.

For instance, if you want to know how to implement a particular algorithm, you can ask ChatGPT to provide a code snippet for the algorithm. It can understand the query and provide a relevant response, ensuring that you quickly get the information you need so that you can write the logic for your application or project.

Asking ChatGPT how to sort an array in JavaScript

Our bottom line on coding with ChatGPT

The screenshots don’t lie. ChatGPT provides developers with a valuable tool for writing code faster. You can use it to generate code snippets, provide debugging assistance, review code, learn new programming languages, and understand natural language queries. Developers can save significant time and effort using ChatGPT, enabling them to focus on other critical tasks instead.

But here’s the catch. If you are a developer, you are aware that your job is much more than writing code – there’s constant communication within the team or between different teams and clients, a creative process that goes into it, coming up with solution depending on the circumstances, all of which ChatGPT is currently unable to do. Also, developers are the ones that are programming AI, so there’s that. 

That’s why we would argue that there is no need reason to worry about ChatGPT replacing developers. But there definitely is a reason to try it out – it can be a valuable tool once you learn how to make the most of it. Especially if you are a junior or mid-level and don’t have a senior mentor by your side. It is a great way for a developer to be more independent and learn faster. Try it out and feel free to share your experiences in the comment section.  

Recommended ➜ Learn how to adapt to Web 3.0 and decentralized future.

The Lumen Spei development team is here for you

Interested in hearing more about this topic? Let us know by leaving a comment. We would also love to hear from you if you are an experienced developer wanting to join our team or if you are a client seeking to work with our developers on your next project. 


Adem Koca

Frontend Developer with experience in designing and developing cutting-edge web and mobile apps. Skilled in utilizing different libraries and state management tools. Well-versed in developing full-stack commercial apps using various backend technologies, including Node.js, Express.js, PHP, MongoDB, MySQL, SQL Server, and frontend technologies such as HTML, CSS, and JavaScript. In addition, has a lot of experience in content marketing, having served as a Marketing Tech Sr. Analyst and Content Marketing Specialist.
Tags: