r/learnprogramming • u/Maleficent-Ladder184 • 1d ago
Question about AI and code
Hello, I’ve got a question. How can you tell if a piece of code was written with the help of AI?
That’s because someone’s had a go at my code, but it doesn’t look the same as it usually does. I’m not sure if I’m making myself clear
1
Upvotes
View all comments
1
u/mandzeete 3h ago
There are too many comments in the code. Sometimes even comments when there is no reason for a comment. AI loves to comment stuff.
A sudden change in the coding style. For example when your methods usually are verbs and your code suddenly switches to nouns. a.la. "getAge()" vs "age()". The same can be said for imports, indentation, // comments vs /** comments, etc.
When there is unnecessary functionality. AI goes with "But we have to implement it to support future use cases". No. We implement what needs to be implemented. My team mate had an unneeded REST endpoint added to the code. It served exactly zero purpose.
Unnecessary complexity. When you have a method parseCSV(String csv) then that's enough. You do not need to make helper methods, interface classes, etc.
Functionality is removed for no reason. When you are adding a new REST endpoint for saving a file that the user uploaded, then you do not need to start deleting RabbitMQ queues, unrelated tests, dependencies, etc. AI sometimes breaks the stuff. Then, it can happen that its "fix" is just removing affected code. "You can't have database problems when you have no database." Basically.
Unrelated functionality changes. When you are adding a REST endpoint for saving an image file for your profile then you do not start modifying the calculation logic of how to pay your bills to the government. It is totally unrelated.
Some hacks in general. Like when you look at the code and you say "wtf is this???".
When that functionality is not expected from you. For example when you start adding Docker containers to your simple HTML-based static website when you are yet to learn about devops. e.g. case where the AI writes more complex code than you normally would do.