Arkadiusz Krysik

Can ChatGPT Write Code?

The year 2023 marks the beginning of the artificial intelligence age, as countless AI-enabled tools and applications have finally achieved commercial success and widespread recognition.

One such innovation is ChatGPT – an AI language model that has garnered worldwide attention.

But can ChatGPT write code? In this article, we explore the capabilities, limitations, and practical applications of ChatGPT in the realm of programming. Can AI make a good software developer? Let’s find out!

What is ChatGPT?

ChatGPT is an advanced language model developed by OpenAI to facilitate human-like interactions through text-based conversations.

This cutting-edge AI model has been trained on a large corpus of text from the web, giving it a remarkable ability to generate coherent and contextually relevant responses to a wide range of questions and prompts. ChatGPT can perform a variety of tasks, from answering questions and providing information to engaging in natural-sounding conversations and, the focus of today’s post, generating code.

natural language processing

Its versatility has made it a valuable tool in many areas, including customer support, content creation, and even educational assistance.

As AI technology continues to advance, ChatGPT’s ability to generate human-like text represents a significant milestone in the evolution of human-computer interaction and offers a glimpse into the potential of AI-powered conversational agents.

Can ChatGPT write code?

Short answer: yes!

ChatGPT can certainly write code in various programming languages, ranging from C++ and C# to Python and Java. It can also find bugs in your code, suggest improvements, and help you convert from one language to another.

It all depends on what prompt you enter.

However, there are two important things to keep in mind: The first is that ChatGPT can generate code that can be useful. It is, after all, a large language model designed to work with text, which, fortunately for us, includes code.

The second is that it can sometimes get lost, fall down the rabbit hole and produce rather unusable snippets of code. So you have to be careful when using it. But we’ll get to that later.

Having said that, benefits of artificial intelligence are still appartent to software developers, and ChatGPT is still incredibly powerful and helpful, especially for simpler tasks like CRUD applications, API integrations, and front-end code.

ai development chat gpt

Let’s create a simple example application using ChatGPT and say I want to build a recipe website with a searchable database of recipes and the ability to save and organize favorite recipes.

ChatGPT can outline the entire software development process for us, suggest a suitable tech stack for the task, create a business development strategy, and help us write the code itself. Let’s ask Chat to start by writing some simple HTML code for our website.

deep learning techniques

That’s a good start, but it’s not exactly what I had in mind. Let’s ask Chat to make some adjustments.

existing code

Great! Our basic HTML is done. Now let’s ask Chat to generate some CSS to go along with the HTML we just generated in the prompt. Note that I didn’t include the entire generated response in the screenshot because it was way too long.

Chat gpt write code

Not surprisingly, using ChatGPT is much faster for developers than googling and setting up all these basic website components.

And that’s just the beginning.

If you want to make some style adjustments, that’s no problem! Just explain briefly what you want to accomplish and wait for Chat to generate code with your desired changes.

If you want to set up this site as a demo or MVP, you will need some mock-up data. Luckily, you can just ask Chat to generate some mock JSON data, and then write JavaScript code to pull data from the JSON file and display it on our site. Pretty incredible.

can chatgpt write code

Will ChatGPT replace programmers?

By now, we can clearly see that ChatGPT and other large language models are extremely powerful when it comes to writing code.

So is this the end of the road for software developers? Should programmers start thinking about changing their career paths?

Not so fast.

Human programmers are still and will continue to be invaluable in software development.

Right now, ChatGPT is already quite useful for tasks such as front-end development, writing automated tests, API integrations, and CRUD application development. With time, the level of sophistication will undoubtedly increase and it will be able to handle even more complex tasks.

This process will also evolve from the other side. Application developers will create their solutions in such a way that GPT will use them more efficiently. After some time – when some standards are created – it may turn out that certain areas are actually dominated by GPT.

However, experienced senior developers needn’t worry. ChatGPT can only go so far because it works with existing data. It lacks the creativity and innovative thinking that human programmers bring to solving complex problems and creating new software solutions.

Programmers who have a deep understanding of their craft and are familiar with various languages and programming paradigms don’t need not fear. Those who are code tappers, without any solid programming knowledge, and don’t do much beyond any current tasks – well, they’d better start learning.

generate code

How to use ChatGPT to write code?

Writing code using ChatGPT or any similar large language model is quite simple. Since it is designed for natural language processing, it requires a clear and specific programming task or question.

ChatGPT can help you with programming tasks by generating code snippets, explaining programming concepts, or assisting with debugging. Here’s a step-by-step guide to writing code with ChatGPT:

ai language model developed

Choose the technology

If your task involves a specific programming language, be sure to mention it in your prompt. ChatGPT can generate code snippets and explanations for various programming languages, including Python, Java, JavaScript, C++, C#, etc.

Write a prompt

Now it’s time for the most important task: writing a prompt.

The ChatGPT prompt is a description of the code you want to generate. It should be written in natural language and include the desired functionality of the code snippet or the thing you want Chat to explain to you:

  • Write a Python function that calculates the factorial of a given number.”
  • “Explain the concept of object-oriented programming in Java.”
  • “Debug this Python code that is causing a ‘NameError.'”
  • “Write a function that sorts an array of integers in ascending order.”

How to write a good ChatGPT prompt for code generation?

Imagine you’re paying a human software developer to do this job. Do you give this person enough information to complete the assignment? Maybe you are too vague, and the programmer is more likely to either ask questions or create something completely different from what you envisioned.

First and foremost, you need to clearly state your programming task or question in a specific and concise manner. Avoid vague or ambiguous language. Provide context or background information when necessary. Explain what you’re trying to accomplish, the problem you’re facing, or any other relevant details.

The more specific you are, the better the results you will get.

[Read also: AI Insurance: The Impact of AI on The Insurance Industry In 2024]

Iterate and refine

After receiving code snippets or explanations from ChatGPT, review them carefully. Make sure they meet your needs and expectations. Test the code in your development environment to make sure it works as intended.

ChatGPT may not always provide the perfect code or explanation in its first response. Don’t hesitate to iterate and refine your questions or prompts. You can ask follow-up questions to clarify or expand on the information you need.

Generate code and paste it to the IDE of choice

Once you’ve provided the prompt, ChatGPT will generate code snippets that match your description. You can then copy and paste the generated code into your project.

While ChatGPT can be a valuable resource for coding assistance, it’s important to use its output as a starting point and not rely solely on it for critical coding tasks. Always review the code and consider best practices and security concerns.

[Read also: Unlocking the Power of Data: A Comprehensive Guide to Database Management Systems]

Limitations in ChatGPT’s ability to write code

Let’s be clear. Unless you are writing a very small function, ChatGPT will not be able to write your perfect final code.

While these AI models can automate certain aspects of programming and assist developers in various ways, they have several limitations that prevent them from completely taking over the role of programmers. Here are some key reasons why ChatGPT is not expected to replace programmers anytime soon:

code generated

  • Limited understanding of context – ChatGPT generates responses based on patterns in the text data on which it has been trained. It may lack a deep understanding of the specific programming context and constraints, resulting in code that is syntactically correct but not semantically meaningful.
  • Difficulty in handling complex issues – Coding tasks involving complex algorithms, niche libraries, or specialized domains may be challenging for ChatGPT. It may not have the expertise to provide accurate solutions or explanations in such cases. ChatGPT may also generate code that is syntactically correct but semantically incorrect or irrelevant to the specific problem. It also often lacks a deep understanding of the broader context and goals of a software project.
  • Problems with quality assurance – Programming involves not only writing code, but also extensive testing, debugging, and quality assurance. While AI models like ChatGPT can assist with code generation, they cannot fully replace the rigorous testing and debugging processes required to ensure the reliability and security of software.
  • Lack of domain-specific expertise – Many software projects require domain-specific knowledge and expertise that AI models may not have. Programmers often need to understand the unique requirements of a particular industry or application domain beyond code generation.
  • Issues related to problem-solving and design – The process of problem-solving, architectural design, and system planning in software development is a human-intensive task. While AI can help generate code, it can’t replace the critical thinking and decision-making skills required for these tasks.

Five popular AI tools for software developers in 2023

We’ve seen a rise in the creation of AI tools to assist and speed up the software development life cycle. While this is exciting news, it also means that things are about to get very competitive.

ChatGPT code interpreter

code snippet

The ChatGPT Code Interpreter is a powerful plugin for ChatGPT that allows it to write and execute computer code to provide answers to more advanced prompts. This feature, introduced by OpenAI, allows the chatbot to perform tasks it couldn’t do before, such as performing complex calculations, generating graphs based on user-uploaded data, and more, all through the execution of code.

Key features:

  • Offers data analysis and data visualization capabilities,
  • Converts files into different formats,
  • Allows for faster, AI-enabled code development,
  • Is able to solve various mathematical problems.

Openkoda

natural language programming

Openkoda is an open-source, AI-powered low-code platform that enables developers to build scalable and secure enterprise software and SaaS applications faster. One of its key features is an AI companion – a coding assistant designed to streamline the coding process with easy-to-use prompts.

Key features:

  • Offers ready-made components for rapid application development,
  • Works with popular integrated development environments (IDEs),
  • Offers great scalability while maintaining full code ownership,
  • Act as a solid foundation for application development rather a just a small tool,
  • Provides integrated multitenant database architecture.

GitHub Copilot

boilerplate code

GitHub Copilot is considered one of the best AI coding assistants on the market today. It is designed to help developers create high-quality code more efficiently. GitHub Copilot is powered by the OpenAI Codex language model, which is trained on natural language text and draws insights from a large pool of public code.

Key features:

  • Works with popular IDEs,
  • Offers Extensions for Visual Studio Code, Visual Studio, JetBrains, and Neovim,
  • Offers code suggestions while writing code and cycle through multiple auto-complete suggestions,
  • Helps to identify and fix code errors and bugs,
  • Finds potential security vulnerabilities in your code.

Tabnine

chatgpt solve coding problems

Tabnine is another AI-powered coding assistant that increases productivity by enabling programmers to write code quickly and effectively. It offers compatibility with a wide range of programming languages, including Python, Java, JavaScript, PHP, Go, and Rust. TabNine harnesses the power of a neural network and leverages insights from an extensive repository of open source code.

Key Features:

  • Offers smart code suggestions based on a massive dataset of open-source code,
  • Introduces code linting feature to identify and suggest fixes for potential errors and bugs,
  • Offers assistance with code refactoring to enhance readability, efficiency, and maintainability of the application’s codebase.

Replit

generate code based

Replit is a web-based coding platform that provides an interactive environment where users can code and learn together. Its differentiator is its web-based Integrated Development Environment (IDE), which supports real-time collaborative coding and provides native hosting capabilities. Replit also offers Ghostwriter, an AI-driven code assistant designed to streamline and simplify the coding experience.

Key Features:

  • Speed up coding with advanced in-line AI-enabled suggestions,
  • Enables novice developers to learn how to code from inside the document,
  • Offers functionalities that spot mistakes and help you correct them,
  • Explains and comments your code.

Future of LLMs – statistics

We all heard about gloomy preditions for the future of work in the AI era.

A report by Accenture estimates that 40% of all working hours could be impacted by LLMs such as ChatGPT-4, which can generate text for various purposes. Another report by Goldman Sachs predicts that AI could replace the equivalent of 300 million full-time jobs globally by 2025.

In the software development industry it’s the same story.

In one of the latest studies approximately 73.3% of respondents expect to see fewer coders in the future due to the automation capabilities of LLMs, suggesting a shift towards more automated coding tasks and potentially a reduction in the need for manual coding labor.

So how much truth is there in these predictions?

We think they are a bit of an overreaction. As we’ve said before, LLMs will put the jobs of junior developers at risk, since the creativity and analytical thinking of senior developers will still be needed.

On the bright side, the same research we’ve quoted above says that nearly 90% of respondents believe that LLMs will bring positive developments to companies, and 66.7% of respondents believe that LLMs will lead to the creation of new roles in software development.

Using ChatGPT as a Programming Companion – Conclusion

Let’s be clear – AI transformation is inevitable and its role will only become more pronounced.

While not perfect, ChatGPT offers great benefits for software developers, greatly speeding up their work, especially in simple, mundane tasks. As programmers harness the potential of AI-powered tools they find themselves better equipped to conquer the challenges of tomorrow’s digital landscapes.

FAQ

What programming language does ChatGPT use?

ChatGPT can generate code in numerous programming languages, encompassing popular languages like Python, JavaScript, Java, C++, Ruby, HTML/CSS, PHP, Go, Swift, SQL, and more. Its versatility in supporting multiple programming environments makes it a valuable tool for programmers seeking assistance across various language domains.

How to get ChatGPT to write code

To get ChatGPT to write code, you need to provide it with a clear and specific programming task as a prompt. Specify the programming language and any relevant details and let ChatGPT generate your code based on the prompt that you can then refine if needed.

Can ChatGPT write Python code?

Yes, ChatGPT can write Python code. When provided with a clear prompt or question in Python, it can generate Python code snippets or provide explanations related to Python programming.

We are Stratoflow, a custom software development company. We firmly believe that software craftsmanship, collaboration and effective communication is key in delivering complex software projects. This allows us to build advanced high-performance Java applications capable of processing vast amounts of data in a short time. We also provide our clients with an option to outsource and hire Java developers to extend their teams with experienced professionals. As a result, our Java software development services contribute to our clients’ business growth. We specialize in travel software, ecommerce software, and fintech software and AI development. In addition, we are taking low-code to a new level with our Open-Source Low-Code Platform.

Testimonials

The developed software product was built from scratch with solid quality. We have had a long-term engagement with Stratoflow for nearly 10 years. We look at them as partners, rather than contractors. I'm impressed by their team culture and cross-team support.

Nathan Pesin

CTO, Legerity Financials

Stratoflow was a great partner, challenging as well as supporting our customer projects for the best outcome. They have a great pool of talent within the business - all very capability technologists, as well as being business-savvy and suitable for consultancy engagements.

Chris Goodall

Managing Consultant, CG Consultancy (UK) Limited

The bespoke metal exchange platform works great, it is easily accessible and richly functional. Stratoflow managed deadlines capably, meticulously documented their progress, and delivered a complex project at an affordable cost.

Bartlomiej Knichnicki

Vice Chairman, Supervisory Board

We are very pleased with our partnership with Stratoflow and, as we continue to grow, we expect to increase the numbers of developers that work with us on our projects. They have proven to be very skilled and flexible. They're extremely reliable, and they have a very good company culture of their own, which gives them a real edge compared to other providers that serve more as production shops rather than thought partners and creative problem solvers.

Andrew Kennedy

Founder & Managing Director, Tier 2 Consulting

Stratoflow successfully customized the system according to the specific functionalities and without bugs reported. The team was commended for their adaptability in the work process and for their responsiveness.

Joshua Blavins

Tech PM, Digital Agency

The features implemented have received overwhelmingly positive feedback from end-users. Stratoflow has an incredible technical expertise and a high degree of flexibility when it comes to changing project requirements.

Adam Hill

Chief Technology Officer, Legerity

They have impressively good knowledge of AI issues. Very responsive to any amendments and findings. Very good communication. We received a finished project which could be implemented into production shortly after testing.

CO-Founder & CTO

Circular Fashion Company

They provided superb service with seamless communication and a highly professional, technical approach. The team displays impressive technical expertise and are willing to share information and engage in constructive feedback.

Filip Stachnik

Operations Manager, Otwarte Klatki (part of Anima International)

They're very skilled technically and are also able to see the bigger picture. Stratoflow can actually think about solutions, not just the technical task at hand, which they've been assigned.

Arnd Jan Prause

Chief Operating Officer, musQueteer

Stratoflow delivered the website successfully within the timeframe and budget. They assured that the output met the set requirements. Overall, the team's performance was excellent and recommended for their exceptional technical business expertise. They've been able to deliver all of their work on time and within budget, which has been very impressive.

Lars Andersen

Founder & CEO, My Nametags

Travel sector rebound after the pandemic is complete. We have fantastic global coverage of travel data distribution due to mutual agreements and data exchange between aggregators. Competition for the best price of limited resources degradates margins.

How to win? Provide personalized experience and build your own products in the front-office. The missing bits: a traveller golden record collecting past activities and a AI/ML recommendation technology.

Michał Głomba

CEO at Stratoflow