![](/style/images/good.png)
![](/style/images/bad.png)
Pros and Cons Of Using AI for Coding
source link: https://code.tutsplus.com/articles/pros-and-cons-of-using-ai-for-coding--cms-107112
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Pros and Cons Of Using AI for Coding
To build software, you'll need to first conceptualize the app, then plan how to build it, before starting the development process. You're also going to do a lost of testing and debugging before releasing the final app or website for public use.
This whole process of development takes time and resources. It can be difficult to make everything work even with a your best attempts and committed work. This is where AI-assisted coding comes in.
You can use AI algorithms to build well-functioning applications and websites quicker than you would by yourself. Companies and organizations can use AI to streamline their software development process. Let's dive deeper into AI-assistive coding and its pros and cons.
How Can You Use AI for Coding?
AI-assisted coding is all about software developers using AI algorithms to build applications faster and more efficiently. We're talking about tools that use machine learning algorithms and language processing technologies to identify patterns in code, spot errors and recommend fixes and improvements.
An example of such technology is GitHub Copilot. Copilot is cloud-based AI tool used for pair programming. The tool turns English prompts into coding suggestions across dozens of programming languages. It comes in the form of an extension that works in Visual Studio Code and JetBrains.
To receive coding suggestions from GitHub Copilot, you either start to write the code you want to use, or write a natural language comment describing the code you want to generate.
Other AI tools relevant to programmers include ChatGPT and OpenAI codex. Like Copilot, OpenAI codex translates natural language to code. ChatGPT is more text-based, so you can also use it to get answers to technical questions. This make ChatGPT quite handy if you're preparing for a technical interview.
Pros of Using AI for Coding
There are many benefits to using artificial intelligence for software development. Here are some of them:
Better Productivity
Imagine you're in need of a function that converts time from one format to another. You can spend a few minutes looking up the relevant string and time manipulation functions on Google search, then write and debug your code. Or you can just generate the function with just a single prompt to GitHub Copilot.
![Function that formats the date](https://cms-assets.tutsplus.com/cdn-cgi/image/width=630/uploads/users/2776/posts/107112/image-upload/Screenshot_of_VS_Code_with_a_function_that_formats_the_date_object.png)
Function that formats the date
Of course you'll still need to test the code to make sure it works properly and does what you want it to. AI can produce buggy code, and oftentimes it might be because your prompt isn't clear enough on the code you want to generate. Make your prompts as clear and specific as possible, and include all the necessary parameters.
Here's an example of a problematic code generated by GitHub copilot:
![Screenshot of Copilot generated function](https://cms-assets.tutsplus.com/cdn-cgi/image/width=630/uploads/users/2776/posts/107112/image-upload/Screenshot_of_problematic_codes.png)
Screenshot of Copilot generated function
Based on the code above, if you had 10 input elements on the page, clicking any of them would show "This is element #10". This is because the for loop will have completed and i
will already be 10 (for all inputs) by the time onclick
is called on each of the elements.
Here's how you can correct the above code problems:
var elements = document.getElementsByTagname("input") |
|
2 |
var n = elements.length |
3 |
|
4 |
var clickHandler = function(num) { |
5 |
return function() { |
6 |
console.log("This is element #" + num) |
7 |
} |
8 |
} |
9 |
|
for(var i=0; i<n; i++) { |
|
elements[i].onclick = clickHandler(i+1) |
|
} |
In this revised version of the code, the event hander (clickHandler
) is instantly invoked each time we pass through the loop. The inner function uses the scoped num
variable and the element's onclick
property is set to that function. This ensures that each onclick
receives and uses the appropriate i
value.
With the assistance of AI, you can improve productivity by delegating the repetitive and time-wasting tasks. This gives you more time to focus on the more challenging and creative parts of software development. For example, you can use AI algorithms to automate code testing and optimization, freeing more time to focus on writing new code.
Improved Accuracy
AI algorithms are more effective and efficient than human developers at finding errors in software code. While it'll take a human developer hours (or days) to debug a large codebase, an AI algorithm can do it within seconds.
Thanks to machine learning, AI tools can identify erroneous code and bad coding practices. Furthermore, most of these tools can provide solutions for the error and suggestions aimed at helping you adhere to standard coding practices. It does all of these in the fraction of the time it takes the average human developer to debug.
More Scalability
One of the best part about AI algorithms is that they can scale to handle large projects. Provided you have the processing power, you don't need to do anything extra to enjoy the power of AI. Contrast this to the lack of scalability of human developers.
AI algorithms don't just scale in size, but also in complexity. Most AI tools can work with a wide variety of programming languages. This is a massive advantage to companies that use a large tech stack for development. Imagine how much it'd cost to hire developers for each stack or programming language.
Access for Those With Limited Knowledge of Coding
AI-assisted tools can be quite helpful to new programmers who aren't very competent at writing code. These tools are also helpful in situations where developers want to implement certain code (especially complex ones) but don't know how.
Of course, the developers often have to be specific when supplying the parameters for generating the code. This means that the developers more or less need to know how they would write the code, even if they use AI-assisted tools to write it for them.
Cons of AI-Assisted Development
Despite it's many advantages, there's another side to AI-assisted software development that you need to know. Here are cons of using AI as a software developer:
Limited Creativity
One of the biggest downsides of using AI for coding is limited creativity. If you've ever used ChatGPT to generate content, you most likely noticed how bland some of the sentences were. This can also be the case for software development.
Programming requires creativity. You must be able to conceptualize your application before building it. You need to consider the framework to use, and how to go about designing the various components. This is an area where AI-assistive technologies fall short.
Dependence on Algorithms
Using too much of AI can lead to a dependence on algorithms, which isn't a good thing. For one, it can lead to a lack of innovation and critical thinking among software developers.
Developers might rely on machines instead their own imagination. This ultimately could leads to a decrease in the overall quality of the software. Furthermore, the entire software development industry could be negatively affected.
Legal and Ethical Issues
Another main issue involving the use of AI for programming is legal and ethical issues. Because AI-powered programming tools are trained using open source code, they basically use the code written by other developers.
This raises legal and ethical questions whose answers are unclear at this time. What happens if your AI-assisted coding tool generates code that is identical to the code in another repository? Does it make you a plagiarizer or license violator?
The answers are unclear at this point, but we'll probably gain more perspective as people start engaging each other over these issues.
Bias and Inaccuracies
The output an AI-assisted coding tool provides is dependent on the data they were trained on. As a result, AI algorithms can be biased, and they might not always be able to predict the correct outcome. Basically, if the data is biased, so will the AI algorithm.
Suppose you created an application that sends prompts to the ChatGPT API and displays the response on the UI. The accuracy of your application will be based on ChatGPT's algorithm, which is dependent on the data is was trained with.
Thus, some sensitive topics (eg. health, politics, medicine) might return inaccurate or biased answers.
Conclusion
There's no doubt that AI-assistive technology is here to stay. No one knows how much AI will impact software developers for now. But it will surely help developers to work more efficiently and be more productive.
AI tools will surely assist us build applications faster. But there's a high risk of developers becoming dependent on AI algorithms, which isn't a good thing. The solution is to find a balance between what AI should take care of and what developers should do.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK