AI needs no introduction
In the recent past, we have seen an astonishing surge of interest in the field of artificial intelligence. I'm no different. I've been experimenting with tools to see how they might help my daily programming tasks. I won't waste your time with the background - you probably already know it as someone interested in software development.
How can we use AI to write better code?
Let's start by pointing out problems that current AI applications can't solve. Some YouTubers and journalists, even from the industry, claim (probably for clicks?) that everything is changing and sometimes even say developers won't be needed soon - this couldn't be further from the truth.
It is not the case that everything necessary for product delivery, including all the code, can be done by AI alone (in the short term). There will be a need for human input. And that does not seem to be going away any time soon. Some steps are not so easy to replace: the discovery of the product, the translation into the architecture, and then the crafting of the code itself to make it maintainable by engineers. These are all inherently very human tasks.
There is a translation that takes place from the real world to the code. Through the process of problem naming to the end product, which is the code that is delivered to the machines on which it will work. There is an ongoing need for people to do the work of translation from one abstraction to another for the ever-changing domain of the product. It cannot be done entirely by the machine (at the time) because of the nature and character of the software development process.
That doesn't mean that we don't have new powerful tools in front of us that will change the industry. It will leave its mark and I can say that it is already changing the field.
it's great for less experienced
I would like to share the tools that I use and my impressions of each. I will be happy to know yours by the way.
Perspective could be much different from the Junior Developer's point of view.
I'm recently writing some applications in Python, which is not my main language, to say the least. Up to now I just wrote some basic scripts here and there. I need to say that for basic usage it works well! The famous ChatGPT helped me to optimise my functions and make them a little bit more readable. So it looked like for a beginner it does the job. Without a need to spend much time in documentation and on different programming blogs, I can find solutions to problems like "how to add items to a list in a loop?".
For devs with experience
I'm writing from the perspective of a software engineer. I've been working in this field for more than a decade. After those years, maintainability and readability of the software is the most important thing for me for most business applications (except some performative ones). I think that there is no way that machines can do 100% of this work.
Not that AI cannot be helpful. I found it useful for suggestions, rephrasing, exploring ideas and explaining code. I mainly use the famous ChatGPT for these purposes.
I've used the chat to sketch out the skeleton of an application and generate basic content for it. It works well for exploring problems. In the end, to make the code clean, readable and maintainable, I still need to write it myself.
Downsides of the tools
Let's start with the main problem from my point of view. There is a known problem with LLM AIs. They give false information (it's called hallucinations). There is an interesting example pointed out to me by a novice programmer (prompts are mine):
I wrote a question on chatGPT:
what's the value of h ^ (h >>> 16) when h equals 2141794 in java
The answer from Java (jShell)
The answer from chatGPT:
the value of h ^ (h >>> 16) when h equals 2141794 in Java is 2130804.
"are you sure?"
the correct value of h ^ (h >>> 16) when h equals 2141794 in Java is 2154148.
You can ask it many times "are you sure?" and it will give you a different answer. So the thing to remember is that there is no trust in it - you have to do your checks.
Another problem with ChatGPT is that on some occasions it does not find the bugs in the code (you have to point the bug to the tool). Worst of all, it even introduced some new bugs and quirks. After some time, when I used it to write a small tool, it left me with code that was hard to understand. I imagine it will become a classic "spaghetti code" in no time. The other problem is that it discouraged me from learning the basics of the Python language. This could leave me without knowledge of its fundamentals. But that's a similar argument someone could make against Stackoverflow.
I've also tried the CodeWhisperer from AWS. It works quite well for simple things, but it has two major drawbacks for my use: Most of the time it is annoying and distracts me from writing the code I have in mind, and secondly it shares your code with AWS. Also, it was simply irritating to see the wrong suggestions when I didn't need them. But I see room for a better, more refined, intelligent code-suggesting tool.
Someone might say: You don't need to know how software is made to make an application, and you can't use code plus AI. If you are convinced, do it. For prototypes or simple cases, it might work. But the main problem with this way of thinking is: the code is for humans to read. For the machine, it is currently a binary version of it. This makes it possible to create software that is impossible to maintain. This often happens even when the software is written by humans - but that is another story. So to sum up, these tools have educational and quality disadvantages.
To sum up
My main takeaway is that it's a very good suggestion tool and the developer can make good use of these powerful tools. But it's not here to take over our jobs (yet).