Leveraging AI Assistance as a Software Developer

When and when not to use ChatGPT

Daniel Moreno
6 min readJul 23, 2024

With the surge of Generative AI and AI Coding Assistants, developers have increasingly turned to these tools to enhance their performance. However, like any technology, there are trade-offs, particularly when these tools are overused. While AI can be incredibly beneficial in certain scenarios, it’s important to consider a few key points, especially if you’re new to the software development field.

One key consideration is that AI tools, including Large Language Models (LLMs) like ChatGPT, can sometimes produce “hallucinations” — erroneous or misleading information that can lead to wasted time and frustration. These inaccuracies can sometimes be transferred to developers, making it even more important to be cautious and discerning when using AI-generated content.

After using Large Language Models (LLMs) like ChatGPT for two years, I’ve identified the scenarios where they shine and where they fall short. Spoiler: sometimes it’s better not to use them at all. The following paragraphs delve into the details of when and when not to use these powerful tools.

When not to use ChatGPT ❌

Critical or sensitive code 🔐

This is probably the most crucial scenario where you should avoid using AI coding assistants. Sharing code that contains sensitive data or proprietary algorithms with an AI can lead to legal and security issues. Even if your company’s policies allow the use of these tools, it’s vital to be discerning about what you share. For example, avoid entering proprietary encryption methods or confidential business logic into AI systems to prevent potential risks.

Complex problems 💡

ChatGPT excels at solving simple problems and generating trivial code. However, when it comes to more complex challenges, like competitive programming tasks, it often requires additional guidance. To optimize ChatGPT’s output in these situations, one effective approach is to provide the solution yourself. After all, the real problem-solving happens in our minds and on whiteboards; writing and testing code is usually the easy part.

I’ve found ChatGPT useful for brainstorming ideas on how to approach a problem. However, this can be a double-edged sword, as it might sometimes lead you away from the optimal solution. Ultimately, the best way to use ChatGPT in these scenarios is to devise the solution yourself and then have the AI write the code. You’ll still end up solving the problem, but with the added benefit of streamlined coding.

Learning a new language 📖

Or learning basically anything. I used ChatGPT some time ago to study for my master’s degree test. Feeling a bit rusty in Calculus, I decided to use ChatGPT as a tutor. I would ask ChatGPT to create an exam for me, and then I would solve each problem and provide my answers. Sometimes I was incorrect, and ChatGPT would correct me; other times, I was right but ChatGPT mistakenly told me I was wrong.

When learning new languages, it’s important to remember that ChatGPT can make mistakes and produce “hallucinations,” which is where real problems can arise. As you’re learning a new language (or any new subject), there’s a risk that you might absorb incorrect information. The thing is, ChatGPT or any LLM doesn’t differentiate between true and false information. It generates responses based on its training data, and if it hasn’t been trained on a particular topic, was trained with incorrect data, or has inherent biases, it’s likely to produce hallucinations. Since LLMs provide answers based on probability, there is always room for mistakes.

Creating UI 🎨

You might disagree with me just by reading the subtitle, but don’t get me wrong — ChatGPT is really good at generating code for UI, and there are other tools that enhance this capability even further. However, when it comes to creating pixel-perfect UI, it can be hard to give ChatGPT a good prompt that creates exactly what you want in terms of colors, margins, paddings, text format, etc, sometimes, it’s just easier to ask only for the components and some basic style, then customize those based on your needs.

Especially if you’re using a declarative UI framework like React, Compose, SwiftUI, or Flutter, it might be easier to customize the style. You’ll use fewer characters to achieve what you want than by telling it to ChatGPT.

When to use ChatGPT ✅

Creating trivial code ✨

This is where ChatGPT truly excels, saving you hours of time on simple code tasks that anyone can write. Some examples are generating a model from JSON, autocompleting functions, and creating simple UI components. Essentially, for any task that requires more time than effort, ChatGPT is a great tool to delegate those tasks.

Creating boilerplate code 📝

Especially when starting a new project, there’s a lot of boilerplate code you need to create. This includes setting up project structures, configurations, and basic functions. Instead of spending your time on these repetitive tasks, let ChatGPT handle them for you. It can quickly generate the necessary code, allowing you to focus on the more complex and unique aspects of your project. This not only saves time but also ensures consistency and reduces the chance of errors if you’re doing manual setup.

Unit Tests 🧪

Although ChatGPT is a good option for writing unit tests, it can become tricky when your classes have dependencies. You’ll need to provide all these dependencies so ChatGPT can create mocks (assuming you’re following the Dependency Inversion Principle). This poses a risk of sharing too much code.

Instead, I recommend using ChatGPT to create simple unit tests for classes or functions without dependencies or sensitive code. You can also leverage it to make your code more testable. If you’re practicing Test Driven Development (TDD), you can write the test cases first and then ask ChatGPT to generate the minimal code needed to pass these tests. If the generated code isn’t perfect, you can refine it yourself, but you’ll likely have a solid foundation to continue the development cycle. However, always consider the other points we’ve discussed before sharing your code.

Refactoring 🛠

You might prefer handling refactoring yourself, but there are times when you might not have much time, and technical debt starts to build up. In these cases, you can use ChatGPT to help with refactoring instead of letting that debt snowball. Remember to consider the same aspects we’ve discussed about sharing code, but ChatGPT can definitely assist, especially if you’re refactoring regularly. By doing so, you’ll only need to share small chunks of code rather than an entire module.

For large-scale refactoring, you might still have to get hands-on, but ChatGPT can provide valuable strategies and ideas on how to approach the task.

Always validate LLMs output 🔍

ChatGPT simple mistake

Don’t get caught in the hallucination cycle. ⚠️

As illustrated in the ‘Hallucination Cycle’ image, validating the data is an optional step, but skipping it can lead to misinformation. LLMs can propagate these ‘hallucinations’ like a disease, affecting both seasoned and new developers. It’s crucial to validate the output from ChatGPT to ensure its accuracy.

Providing feedback to ChatGPT about errors isn’t necessary, but it can help prevent the spread of inaccuracies. Your feedback contributes to improving the model and reducing these issues. Personally, I only provide feedback in cases where it might impact beginners or students, such as when I encountered false positives while studying for my calculus test.

Conclusion

While ChatGPT and similar AI tools offer remarkable support for coding tasks, from generating boilerplate code to providing refactoring strategies, their effectiveness is contingent on careful usage and validation. Leveraging ChatGPT for straightforward and repetitive tasks can save time, but for complex refactoring or unit testing involving sensitive dependencies, manual oversight remains crucial. Always validate the AI’s output to avoid the propagation of inaccuracies.

When using ChatGPT for studying, it’s essential not to rely solely on it. Complement your learning with other resources such as books, blogs, articles, and reputable educational materials. This multi-source approach ensures that you get a well-rounded understanding and helps you verify that you’re on the right track. By integrating various sources of information, you can deepen your knowledge and enhance your learning experience.

--

--

Daniel Moreno

Staff Software Engineer specializing in mobile dev, architecture & team leadership. Skilled in iOS/Android, CI/CD, System Design and web development.