As a developer, I am always trying to use current tools that can make my life easier. And with all the buzz around ChatGPT, it's difficult not to wonder how well it can handle coding tasks. Naturally, I had to give it a try.

However, many examples of coding with ChatGPT that I saw weren't as useful as I'd hoped. That is why I've prepared a list of 7 sample use cases to help you in your daily work.

Let's dive in 🚀

What Are the Best Use Cases for Coding?

Before we start, remember that although ChatGPT is able to do many things, including generating code snippets or explaining complex concepts, it can often be wrong. Think of it more like a starting point for your projects, and do not entirely rely on this AI tool.

Here are some of my favorite use cases that showcase ChatGPT's potential in coding:

1. Constructing Regex Expressions

Regular expressions are a way to find specific patterns in text, making it easier to search, match, and manipulate strings in programming. ChatGPT can be a lifesaver when constructing these complex expressions, helping you quickly generate accurate and efficient patterns for your code.

Let's say we want to generate a regex that checks if a string is a valid URL 👇

Creating Regex with ChatGPT

ChatGPT will not only generate a regular expression for us. It will also provide an explanation so you can understand the full expression.

ChatGPT generating Regex

Then, we can quickly check if regex works for different inputs, for example, by using Regex101 or other regex testers.

Testing regular expression
Image credit: Regex101

In this example, it works as it should. But remember that AI sometimes tends to hallucinate, meaning it can give you the wrong answers.

So, test your regex for different use cases, and if anything is wrong - remember you can always give feedback to ChatGPT and ask the chatbot to debug your expression.

Of course, this can be done even quicker with AI coding assistants like GitHub Copilot, but in this article, we will only focus on ChatGPT.

2. Explaining the Code

Understanding someone else's code or even your own after a while can be challenging. ChatGPT can help by generating clear and concise explanations of code snippets, making it easier to understand the logic and purpose behind specific functions.

We can simply paste the code snippet and ask ChatGPT for an explanation.

Asking ChatGPT to explain code snippet

The explanations are really detailed. As you can see below, the chatbot explains literally every aspect of the code.

ChatGPT explaining code

3. Naming CSS Colors

ChatGPT can be incredibly useful when it comes to naming CSS variables. You can ask it to create a random color palette or simply provide your own colors. AI will generate proper variable names for you, making the process much quicker.

Here is an example where I ask ChatGPT to generate a color palette for me and ask him to create CSS variables:

Generating colors with ChatGPT

And the chatbot answers with CSS code:

ChatGPT creating color variables

Here is what the palette generated by AI looks like:

Color palette generated by AI

4. Explaining Difficult Technical Concepts

ChatGPT can explain complicated technical concepts for developers by breaking down complex ideas into simpler terms, providing analogies, and offering step-by-step explanations.

Let’s ask ChatGPT what “this” is in JavaScript 👇

Asking ChatGPT to explain difficult technical concept

The chatbot will provide you with a comprehensive answer:

ChatGPT explaining "this" keyword in JavaScript

The problem with AI is that it can create fake answers, which makes it difficult to rely on as a primary learning resource. However, it can be a great help when you're stuck on a concept, as you can ask it to break things down for you in a more understandable way.

5. Generating Simple Code Snippets

ChatGPT cannot build complex apps on its own yet, but it is great for generating simple code snippets. I like to use it for generating util functions. Take a look below - it works really great 👇

ChatGPT generates code snippet

ChatGPT created a whole JavaScript function in this example that converts time (passed as a string) into minutes. AI is really effective for tasks like these.

6. Summarize the Article

As developers, we must stay up-to-date with different programming concepts, which often involve reading articles or watching educational videos on YouTube. However, if you're short on time and can't read a full article or watch an entire video, keep in mind that you can always ask ChatGPT to provide a summary for you.

ChatGPT can effectively summarize both blog posts and video transcripts. It does this by analyzing the text, identifying the main ideas, and offering a condensed content summary. To use this feature, simply paste the text from the article or transcript for ChatGPT to read and analyze.

7. Refactor the Code

ChatGPT can help refactor your code by suggesting improvements or showing you different ways to tackle a problem. It's great for making your code easier to read, maintain, and perform better. However, keep in mind that the suggestions you get might be wrong, depending on how complex your code is.

ChatGPT helping to refactor the code
Don't forget to double-check its suggestions to make sure they're right and follow the best practices for your programming language.

ChatGPT can be a helpful buddy in pointing out things you could improve, but it's not a substitute for the know-how of an experienced developer.


Should you code with ChatGPT?

As a programmer, I've found that including ChatGPT into my coding workflow has opened up a few new possibilities. It can be an incredibly powerful tool that can save you time and inspire you in many ways. I like to use it for simple functions or generating boilerplate code.

But, relying too heavily on ChatGPT is a bad idea. As an AI, it can generate code that can be inefficient or insecure(or just doesn’t work). So, it's essential to review and understand the suggestions that ChatGPT provides. It's also worth noting that ChatGPT can't replace the creativity and deep understanding that experienced developers bring to the table.

Besides, in most cases, it is more convenient to use AI coding assistants like GitHub Copilot or Amazon Code Whisperer.

What programming languages does ChatGPT know?

ChatGPT is a language model that has been trained on a vast amount of text data from various sources, including programming languages. It knows many programming languages, including popular ones like Python, Java, C++, JavaScript, and many more.

However, it's worth noting that ChatGPT's understanding of programming languages is limited to the text data it has been trained on. It may be unable to understand some of the more complex aspects of programming languages, such as performance optimization.

Wrapping Up

Now you know that ChatGPT has several great use cases that can save you time, improve code quality, and inspire new ideas.

As a developer, integrating ChatGPT into my coding routine has been a game changer, and I believe you'll feel the same way.

Thanks for taking the time to read this!

Happy coding ✌

Table of Contents
Great! Next, complete checkout for full access to Kajetan Domagała.
Welcome back! You've successfully signed in.
You've successfully subscribed to Kajetan Domagała.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info has been updated.
Your billing was not updated.