What is ChatGPT and Can it Replace a Programmer?

ChatGPT is an artificial intelligence(AI) platform that allows you to ask a question and gives you an answer. ChatGPT is an AI chatbot trained to effectively have dialogue. It keeps dialog with you knowing the previous answers. The knowledge database filled by the end of 2021. At the moment there is a free preview available and I decided to test this platform. To learn more about ChatGPT and try the preview, you can visit the OpenAi.com website. And now let’s check what it can do for me as a C# developer.

Asking ChatGPT to write Bubble Sort Function in C#

Let’s see how the chatbot handles the bubble sort task. I typed the next question: “write a function that sorts an array of numbers using the bubble method”. Here is the result:
ChatGPT sort bubble method
I got the expected code as well as a usage example with explanations of the code. But I was a little mistake and forgot to indicate that I need an example written in C#. Let’s ask him to rewrite it in C#. I just typed “rewrite code in C#” and after a few seconds I received the next result:
chatGPT bubble sort method in C#
For me, this was the expected result. You may notice that the ChatGPT used the template from the console application, which is good.

ChatGPT writes Unit Tests

In the next step, I asked to write unit tests using the xUnit framework:“write xUnit tests”.
chatGPT writes unit tests
I liked that all three cases were covered: a regular sort check, an array with one value, and an empty array. I am pleasantly surprised by this. In my opinion, the ChatGPT is quite accurate. But you might ask what’s so amazing about it? Let’s ask for more complex tasks and check how it will deal with them.

Asking to Refactor C# code

Here is an example of the code I wrote and pasted into ChatGPT:

using System;
using System.Collections.Generic;
namespace ConsoleApp1
{
    internal class Program
    {
        static void Main(string[] args)
        {
            var vehicleList = new List<Vehicle>() {
                new Vehicle() { Type= VehicleType.Bicycle },
                new Vehicle() { Type= VehicleType.Tractor }
        };
            foreach (var vehicle in vehicleList)
            {
                Console.WriteLine(vehicle.GetMaxSpeed());
            }
        }
    }
    public enum VehicleType
    {
        None,
        Bicycle,
        Motorbike,
        Car,
        Tractor,
        Airplane
    }

    class Vehicle
    {
        public VehicleType Type { get; set; }
        public int GetMaxSpeed()
        {
            switch (Type)
            {
                case VehicleType.Bicycle:
                    return 25;
                case VehicleType.Motorbike:
                    return 150;
                case VehicleType.Car:
                    return 120;
                case VehicleType.Tractor:
                    return 80;
                case VehicleType.Airplane:
                    return 800;
                default:
                    throw new InvalidOperationException("Invalid Vehicle Type");
            }
        }
    }
}

The main idea is that this code can be refactored using polymorphism. It became interesting to me that if I just ask ChatGPT to refactor this code, without making hints that Enums can be presented as separate classes. And to my surprise, the code was refactored as I wanted:
ChatGPT C# refactoring example

You may notice that a base class with an abstract method GetMasSpeed has been created. And from the base class, two classes are inherited with an indication of the max vehicle speed. This is exactly what I wanted to see. I wanted to avoid using the switch statement. Perhaps for some it may seem simple, but I understand that behind this decision is a complex work in the field of artificial intelligence.

Can ChatGPT Replace Programmer?

This is quite a provocative question. At the moment, I think that artificial intelligence will not be able to completely replace the programmer. With the skillful use of ChatGPT, it can become your mentor and suggest real options for solving programming problems. And even despite the fact that ChatGBT coped with my tasks with a solid five, I recommend watching Tim’s Corey video where he tests ChatGBT in more detail. Let me quote a few phrases from the video:

  • Knowing how your code works is extremely important
  • ChatGPT provides a conclusion and Google provides you an authority. It’s a key difference
  • Don’t use this tool to replace your brain
  • Use ChatGPT to help you
  • Validate the code produced by ChatGPT

Question to ChatGPT: Will Software Developers Loose Their Jobs Because of ChatGPT?

Will Software Developers Loose Their Jobs Because of ChatGPT?

Leave a Comment