r/learnprogramming • • 43m 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

2 Upvotes

6 comments sorted by

•

u/lfdfq 35m ago

You're not really making yourself clear, no.

In general, you cannot tell if an AI wrote it, or an AI told a human who typed it manually, or a human wrote it. Even the style might not tell you, since it was trained on code written by humans it writes code that looks like it could have been written by a human. The best way is to ask the person who supposedly wrote it how they wrote it and what it does.

•

u/bestjakeisbest 5m ago

I will say you can kindof get a feel for it if you work with the code base for a bit, i know a few of my teachers use ai to design their projects and assignments just by how it feels to use their tests.

•

u/Beginning-Seat5221 32m ago edited 4m ago

AI tends to write more code, use more complex pattern, and add more guards for edge cases. It's sometimes over clever compared to humans that try to keep code simple and readable - but humans vary a lot so some people surely write AI-like code. There's also variance between AI models and prompting can change their output.

•

u/xpusostomos 6m ago

That's a good answer, the AI is very rigorous in accounting for edge cases, which is not a bad thing, but it can be a give away.

•

u/betarage 23m ago

They use too many comments and very generic names for functions and text.

•

u/pixel293 16m ago

It could be written by AI, it could be that they ran a code beautifier on it, so the indentation, spacing, and what not was consistent in the the way they like it, it could have been edited with an editor that used tabs instead of spaces or spaces instead of tabs. There is really no way to tell if AI was involved or not.