Will ChatGPT replace .NET developers?
Published: Sunday 18 December 2022
ChatGPT is a new free artificial intelligence model from OpenAI.
Build an ecommerce system
The first thing we asked ChatGPT to do is to build an ecommerce system with orders, customers and products in ASP.NET Core Web API.
- Installing .NET Core SDK
- Creating a new ASP.NET Core Web API project in Visual Studio
- Defining models for orders, customers and products
- Set up a database
- Configuring Entity Framework
- Implementing logic for controllers
- Testing the API endpoints
Build an .NET ecommerce system with ChatGPT
A good start! But what about writing code?
Writing the classes for the models
Next, we asked it to write the code for the classes of the model. This included a class for Order, Customer and Product.
Order class.
ChatGPT writing code for a .NET class
Let's see if we can separate the order items into a separate class.
Separate order items into it's own class
The results were a lot better when we asked it to separate the order items out to it's own class.
OrderItem class, and added the ProductId, Quantity and Price into that class.
Order class then had a list of order items so it was able to have that relationship between the two.
ChatGPT rewriting code for a .NET class with better properties
We noticed it created the order items as a List. We asked it why it didn't use an IList?
Why use List over IList?
It gave us a very detailed explanation on the benefits of using List over IList.
IList interface, and storing the elements internally. This means that element access is faster and memory overhead is lower compared to other implementations.
IList, such as using it for a mock implementaiton, or passing a list to a method that expects an IList interface.
ChatGPT answering why you should use List over IList
Writing controllers
With the entities created, the controllers was the next thing we got it to code.
Order entity, it wrote a controller with common CRUD methods needed, such as reading all orders, or a single order, as well as creating, updating and deleting an order.
IUnitOfWork seemed to have methods that supplies the input and output of the order data.
Writing an ASP.NET Core Web API controller in ChatGPT
Another thing was when it started to write the controller for the Customer, it suddenly stopped half way through.
ChatGPT stops half way through writing a .NET controller
We did ask it to try it again, but it stopped at the same place. So there are definitely some limitations there.
Writing tests
We asked it to write unit tests using XUnit.
IUnitOfWork interface. Afterwards, it went through and wrote some good unit tests for our controllers. It called the endpoints in the controllers and set an assert as to what type should be returned.
ChatGPT gets stuck when writing XUnit tests
Server issues
At this point, we were getting a number of errors when asking it questions. Errors ranged from the server experience an error while processing the request, to us sending it too many requests.
Server issues with ChatGPT
At this point, we decided to conclude our experiment.
See ChatGPT in action
Watch our video where you can see us using ChatGPT to build an ecommerce application with ASP.NET Core Web API.
In-addition, we created an ASP.NET Core Web API in Visual Studio and see if the code that ChatGPT generates actually compiles.
Is a .NET developer's job at risk?
At the moment, ChatGPT can only really be used as a guide. It takes a .NET developer to question the code quality that it writes.
IUnitOfWork interface which would never compile.
Related articles