Using Too Much AI Generated Code in Projects
Hi everyone, it’s Ked. As I was contributing to an open source project a few months ago, I ran across an interesting issue. The project, which was created by developers fresh out of college or bootcamp, ran well, but was heavily reliant on AI-generated code. At first glance, using AI for coding might seem advantageous, thanks to its ability to produce correct code. However, the real test came when I tried to solve a simple responsive design issue in the header, turning into an absolute coding nightmare.
The header was composed of over 15 components, completely ignoring the DRY (Don't Repeat Yourself) principle, and the code comments mirrored the style typically generated by AI. There was also no style guide / coding standards document / contributing file, and as they all graduated from different universities, it was safe to assume that AI was being used for creating these components. This resulted in a chaotic mix of class names across components, despite them targeting identical CSS rules, making the task even more complicated.
The file structure was messy as well, with related header components (some not even titled ‘header’) scattered across the 'components' folder rather than being logically grouped in folders. I had to physically make a list of all the components that pertained to the header (some were labeled ‘header button component’ but were still used outside of the header!) to make sure that I had all the components in question. This was an absolutely terrible experience, and I don’t wish this AI spaghetti code on anyone!
领英推荐
As you can see, using AI to generate code is helpful, but can cause many issues, due to the AI’s inability to view the project's code holistically. Relying heavily on AI generated code is also a possible security risk, as automatically generated code might introduce security vulnerabilities, especially if the AI suggests outdated libraries or patterns. It requires the developers to have a strong understanding of security best practices to implement the suggestions properly.?
Another issue with AI generating code is that it always understands a solution, but not always the problem. This can get you stuck in a never ending loop where the solutions it gives doesn’t solve the issue at hand. From my experiences tutoring other junior developers, this “AI loop” is due to the lack of understanding the issue in the first place by the developer, as the developer can’t successfully explain the issue to an AI model. AI can’t solve what it doesn’t understand!
As someone who works closely with AI models, here is my personal recommendation: Do not use AI to solve issues directly, but use it to give you suggestions for solving those issues. Once you understand the solution (and more importantly, the problem!), it’s now up to you to implement the AI’s suggestions.?
Data Design + Other Mischief
1 年Neatly written article about a thorny issue- bravo!
Software Engineer | lover of tacos | RPG player
1 年I couldn’t agree with this more! Thanks for sharing!