ChatGPT- Can it code
Mahesh Krishnan
Leader AI driven Innovation & SaaS Product on Cloud , Senior Software Architect @Conga Contract Intelligence , Negotiation & Lifecycle Management
Recently came across some news & videos on latest version of ChatGPT, as advanced AI chat bot.
The question was - could it code. Hmmmmm...Short answer - "Yes"!! It could write code in C# given a problem statement. It could write sample code and could optimize it further and here is the most interesting bit -- It could write unit tests!!!!! Now that is every coders dream :). Something that piqued my interest to give a try myself.
Was this the coding assistant I always wanted (to do the routine work) !!!
I for one never liked writing routine unit tests for simple CRUD operations. Writing unit tests for tricky logic is a different story. It is as challenging and as interesting as coding the logic itself.
Logging into ChatGPT was easy with integrated google sign in. Initially I tested it to generate code to perform some arbitrary operations on json string manipulation. It did give me a solution which solved 50% of my work. Which is great though !! Some of the syntax did not work, which needed manual fixes. But still it might have saved me a lot of time, which I originally spent on my own googling different sites for a solution.
Now comes the interesting part. I am setting up on new C# project based on Clean Architecture with MediatR library. I wanted to write unit tests with a xUnit along with FluentAssertions library - both of which I unfamiliar with. I had kept aside at-least a day or two to get familiar with these frameworks. This is where things get really interesting.
I just copied and pasted my CommandHandler code into the ChatGPT window along with instructions to generate a unit test for the same and Voila - I got the unit test code generated from this along with mocks using Moq framework !! This was a super bonus..working with any mocking framework is a pain.
领英推荐
Whats better, I instructed it to use FluentAssertions and it gave me the code with the correct assertions using this framework!!!
Did the code work - Yes and a small no...It kept returning null from the mocked repository layer. That is where the experience developer kicks in. I figured out the issue a minor problem with the mock repository setup. But I spent only 10 minutes to figure this and fix it, as against multiple hours of googling syntax/trial & errors with frameworks alien to me.
Is this a replacement for google - Kind of at-least for me !! I would first try and find a solution here before opening google.
Will this replace developers. Definitely not (yet) :). I look at it as a major "productivity tool". So much potential. A smart user will find multiple uses for this not just restricted to coding tasks. If used correctly it can shorten development times drastically.
I would give it a BIG thumbs up.
Humbled and in awe of the creators behind this AI engine !!!