r/learnpython • u/ZSJJ • 2d ago
For any python professionals, can you tell if something has been coded with AI?
As the title asks, what differences (if any) do you get from an AI output vs human input. I would imagine that with most high effort AI models now they write purely pythonic code if a prompt is well written.
If you also use python in your job, how often do you use AI to write or plan your code and applications as a whole?
33
u/neums08 1d ago
When left unchecked, an LLM will solve problems in the code by writing more code.
Usually an application will have a decently clean initial implementation. As the user iterates and builds out the functionality, the LLM will always add more code to cover new use cases, new edge cases, new functionality.
The LLM almost never reevaluates its approach holistically. It never simplifies or deletes code.
Granted, bad developers behave the same way, but a codebase that is clean, has proper abstraction boundaries, and doesn't contain a ton of logical branches is usually a good indicator that it was written by an experienced human.
2
u/Mammoth_Reach_6366 1d ago
True but if you directly ask it to refactor and simplify, it can do that easily. It just rarely does it on its own.
42
u/MediumKoala8823 2d ago
It is extremely obvious when something is coded by an AI.
Ai generated code has good documentation.
32
u/tangerinelion (C++ Software Eng.) 1d ago
Plentiful commentary, not necessarily good nor documentation.
0
8
u/eW4GJMqscYtbBkw9 1d ago
Haha, before reading the comments, I was going to say the code? Probably not. The comments? Absolutely.
If you see my code with more than 4 lines of comments, it was written by AI.
3
u/jesster114 1d ago
One of my biggest uses for LLMs is writing docstrings for my classes/functions/methods/whatever. Use a pre commit hook with the ruff DOC and D rule sets and if the ruff check doesn’t pass, have an LLM fill in the blanks and then I’ll check its output before committing again.
2
u/immaculate_plum 1d ago
It does not. It has a lot of documentation, but most of it tends to be useless fluff.
2
1
u/Wild-Kitchen 1d ago
This made me chuckle out loud
3
u/MediumKoala8823 1d ago
It’s a joke but it’s also extremely true. Not just in line code (where it can be excessive) but also beautiful markdown readmes with diagrams and what not.
1
u/baltarius 23h ago
I add a lot of documentation in my codes, but I don't do it the same way that AI does.
10
u/friendlytotbot 1d ago
AI loves to create functions within functions, which is not how ppl typically write functions in Python.
1
13
u/simonhunterhawk 2d ago
Not a professional just an autistic person with good pattern recognition in the final year of my CS degree. The biggest things for vibe coded programs is over engineering and if there are comments they often have tidbits directly from the prompt in them and are way more verbose and detailed (often not in a helpful way) than most comments written by a developer.
2
u/ZSJJ 2d ago
I would imagine that you have learnt the standard for comments, can you explain that? Would most developers just use comments to describe what functions do what or should a function ideally be self explanatory?
6
u/simonhunterhawk 1d ago
There's really not a standard imo, what I try to follow generally, with most of my code written for web development:
- Comments that act as headers or split up sections of my code in the same file -- for example, Getters and Setters, or in a global CSS file I'll create headers for reusable variables, fonts, etc. This just makes it easier for me to find specifics when making changes later. In larger programs this is also where separation of concerns and using multiple files to call each other can be more helpful than header comments.
- There's very little need for comments that state exactly what the code is doing in detail. A brief is fine - "driver that manages input from menu" vs "output prompt and get input from user, input determines next steps, if input is x then ... else input is y then ..." is too much because your code should ideally be clear enough that someone reading it can tell what it is doing. Explain the why not the what.
- Cite your sources. If you copied a section of code from a github repo or StackOverflow, link back to it and cite the author.
- For solo projects, most of the comments I write are TODOs, headers, citations, explanations for specific scenarios (ex. patched issue specifically for a specific browser, OS, or type of device) and clarifications. For languages I've done 1-2 projects in like C++ I'm not going to remember why I used these two lines so the comments make sense to have for me, but in a enterprise level project you likely don't need them:
cin.clear(); // clear fail state if non-numericcin.ignore(numeric_limits<streamsize>::max(), '\n'); // drain leftover inputI do think there's benefit to explaining yourself more when you're learning, especially when you reference back to your code in the future. One of my C++ classes wanted comments that explain every code block which included a brief explanation of what the code block does, the parameters it uses, and what it returns, if relevant.
You can also Google Python comment best practices and that will give you a lot more detail than I can.
9
u/ekchew 1d ago
I've noticed there is a tendency for AI to brute force its way through anything when a human programmer would likely pause and think, ok this obviously not working. Let's step back for a moment and see how else to approach the problem.
I'm trying to think of an analogy. Let's say you were building a railroad and came up to a lake. A person would likely see that and go all right, we need to go around the lake, while an AI would say let's go through the lake. Then you tell it yeah, but the train can't get wet. Well, we'll build a tunnel around the track then. Oh no, the tunnel is leaking! There's too much water pressure! Let's patch it up here and here, and reinforce it over there. Etc etc. It will not give up and the engineering will get more and more complex.
In coding terms, you get a giant program no sane human would want to write. It may actually produce an amazing result. The train is taking a more direct route to the other side, after all. But wow, good luck making sense of what's going on or maintaining it some point down the line.
4
u/Diapolo10 I write code for a living -- https://github.com/Diapolo10 2d ago edited 2d ago
Not with certainty, no. There are some "quirks" that hint at AI usage, such as certain kinds of comments or commit messages, but there's fundamentally nothing different between hand-written and AI-generated code.
Personally I mostly try to avoid AIs for coding. My personal projects are completely devoid of any AI usage, unless you count Dependabot as AI (I don't, and as far as I know Dependabot doesn't use any LLMs). At work I'm strongly incentivised to use AI, so I've dabbled here and there to get a rough understanding of its capabilities, but outside of something dead simple such as fixing a few accessibility bugs I don't like using it, as the output doesn't satisfy me for other work.
0
u/ZSJJ 1d ago
Interesting, so you wouldn’t see yourself using it even for the repetitive tasks that would be easier to prompt? I have very little experience with programming since I did GSCE CS but even using LLMs for refactoring and debugging has been a massive help
4
u/Diapolo10 I write code for a living -- https://github.com/Diapolo10 1d ago
Interesting, so you wouldn’t see yourself using it even for the repetitive tasks that would be easier to prompt?
My work projects don't really tend to have any "repetitive tasks" I couldn't already solve with
grepor other tools more quickly and with fewer things to fix by hand.As for personal projects, even if someone gave me a free magic button that solved every problem in them perfectly, I wouldn't press it. They're passion projects, and also my portfolio. I want everyone to see what I'm capable of without delegating thinking to a fancy text auto-complete program.
3
u/Lachtheblock 1d ago
I work in a team. I know how my team writes code. It is pretty easy to tell when they have offloaded writing whatever function to AI. I'm pretty utilitarian, in that I don't care as long as the code is good and every human who is signing off on it has read it.
I don't like pretending that AI didn't write the code.
3
3
u/chcampb 1d ago
Definitely
A lot of python is not written defensively. It's usually scripts and things. If you have a script that does something offline and it is very defensively coded, that's a dead giveaway.
Too many comments verbosely describing what is in the code, also a dead giveaway
More subtle things include
Verbiage such as explicitly stating key words that commonly occur in tickets that humans don't use (I once had a prototype game world in a gym (isolated test) folder, and said hey make the production one in the main folder. Instead of just calling it like normal it infected everything it did with "this is the production thing" or logs that say PRODUCTIONWORLD... and things like that. It's not wrong just redundant, usually the world is the world and if you need a dev one it's called a dev one. I am guessing it latched onto some issue it was trained against in this regard.
Random unicode - sometimes LLMs insert unicode into an otherwise ASCII file. It shouldn't matter and doesn't get detected usually but unless you guard against it, the appearence of unicode that nobody types will give it away.
5
u/The_Drakeman 2d ago
I'm not a python pro but I dabble here and there. I saw some LLM python code from Claude and the dead giveaway was randomly having 2 statements on one line separated by a semicolon in a few places. That was so strange to have that sprinkled in to non minified python.
2
u/ZSJJ 1d ago
I’m guessing most people wouldn’t learn that notation as standard. I suppose the way it is now though if you do something abnormally efficient or away from standard practice it’s very easy to be framed as using LLMs for everything
6
u/The_Drakeman 1d ago
It was interesting. So in this case I already knew it was LLM code. Someone I know (who isn't a programmer) used Claude to generate some code that could calculate some data that originated from spreadsheets that tracked the output of his solar array, and wanted to show me the code to see what I thought of it as a programmer. I mainly use C++ and C# in my work so I'm not python expert, but I use it just enough, and the script was simple enough, that I could follow it. The other thing that jumped out at me is that the CSV reader was trying to convert string to float by doing basically "try: return float(val) except: return 0.0" which jumped out at me as a huge red flag. Any non numeric data in any cell in that spreadsheet would have ripple effects and just throw bad data into the pipeline to be crunched with all the other numbers. I pointed it out to him, he asked Claude about it, and Claude gave a response along the lines of, "your intuition is right that this can result in bad calculations, but it worked on the spreadsheet you gave me because there was no bad data." Which to me is the biggest danger of LLM code. It works just often enough to make non professionals trust it, but hides little landmines like that everywhere.
2
u/aishiteruyovivi 1d ago
I find myself really only using semicolons in Python if I'm testing something in a REPL, in production code or really any code I ever plan to revisit I've really never had a case where it reads better than separating them out. Same kinda goes for
x, y, z = 1, 2, 3syntax, unless I'm actually unpacking something (likewidth, height = sizewheresizeis a tuple of two number values) it's almost always clearer to me to just writex1 = -100 y1 = -100 x2 = 100 y2 = 100instead of
x1, y1, x2, y2 = -100, -100, 100, 100 # or x1 = -100; y1 = -100; x2 = 100; y2 = 100Separate lines are also a bit easier to deal with when it comes to version control diffs.
1
u/The_Drakeman 1d ago
I agree completely. Like I said in my other comment I'm a C++ and C# engineer first and foremost so I'm used to seeing semicolons everywhere, except for python. But even when I'm working in those languages, I pack as few things into one line as possible for readability's sake. What the LLM did then wasn't even a multi declaration, it was just two sequential statements in a calculation on the same line for whatever reason, and it did that 2 or 3 times throughout the script.
2
u/newprince 1d ago
I've noticed tons of multiline comments, and the way they are written are a giveaway... lots of "we"
2
u/kepper 1d ago
Context leaks are the main tell, in my experience. The AI will comment something or name a variable in some way that only makes sense given the context of the chat that it came from and does not have any real meaning outside that conversation. Things like # Protects against section 4's risks where section 4 was some ephemeral design artifact.
2
u/DragonWolfZ 1d ago
If there are comments it's usually obvious to me. The AI often over explains or only adds detail in a few key places, the way humans write comments are often concise and to the point.
2
u/Capable_Fig 1d ago
Yes, even when its cleaned up from the incessant comments. I use LLMs to syntax check primarily, sometimes for scope. I swap between a few languages (though python is my first love), and having an LLM clean up my errors (especially white space dependent languages like python) has been a godsend.
One of my coworkers primarily uses LLMs for his code, and its been a hastle to approve his PRs. I'm not opposed, but he's on the left side of the dunning-kruger curve when it comes to python.
3
u/natlight 1d ago
If it has good error handling and extensive test coverage its probably written by an llm
2
u/ejpusa 1d ago
If you also use python in your job, how often do you use AI to write or plan your code and applications as a whole?
100%. Never see a line of code now. The output is close to flawless. It's 2026 AI. It's come a long way. AI turns ordinary coders into extraordinary coders. The rocket has taken off; suggest getting on board. ASAP.
Google CEO Sundar Pichai is referring to artificial intelligence (AI) when he stated that it is more profound than fire or electricity.
:-)
1
u/Fabiolean 1d ago
Yes. 10/10 times. It’s extremely obvious when something has been generated by an LLM
1
1
u/PazyP 1d ago
Use AI daily pretty much exclusively for 99.99% of coding tasks, while I could and can do it myself what might take me a a day AI can get done in an hour with added unit and integration tests and the code is fine, occasional minor change here and there as AI doesn’t truly have the complete picture but it’s rare.
Hardest part now is always testing and to ensure it’s tested well enough to be confident in what AI has written.
1
u/Pyromancer777 1d ago
I'm starting to see that each model has their own style of logic, so if you use one enough the codebase starts seeming pretty AI heavy. There are other subtleties, but considering Anthropic is starting to watermark even text-related output, there are going to be style signatures that will be easily scanned to reveal if it was AI generated, even if it looks passable to a human.
At work, the AI generated code is making mistakes that a human working on the same project wouldn't make. The mistakes aren't in syntax, but in overall logic decisions about how to handle certain scenarios. I can't get into details since the codebase is proprietary, but even if our AI workstream hadn't been separated from the main project, it would have been obvious that parts of it was entirely AI generated with minimal human oversight
1
u/AlexMTBDude 1d ago
If you like try it yourself by asking your favorite AI chatbot whether a piece of code is written by AI or not. I've done this a few times and the results are interesting. We humans are no better than AI themselves at telling whether a piece of code was written by AI or not.
1
1
u/codeguru42 1d ago
TBH, I could care less if code into review is written by AI or not. I only care that features work according to requirements and code is maintainable in the future.
I am currently on a pure JS project and use AI for everything. I haven't written code "by hand" for almost a year. My company also has python projects that i will be working on and don't expect my current workflow with AI to change when i move those.
1
u/Worth_Specific3764 21h ago
Yes. Clearly. Llm can code python faster than anyone can read. Entry level python engineering positions are dead.
1
u/ShelLuser42 21h ago
It depends on how people are using it. If you get hold of a script that was fully generated with AI then it will quickly start to show, simply because of the (sometimes enforced) coding style(s).
But if someone has used AI to build snippets of their code and then combined this with their own or... better yet (!) => when they used the generated code as a template to build upon for themselves, then it can easily become a lot harder.
This also leads us to the real decisive moment that will reveal if someone used AI smart & efficiently, or if they simply dumped all their tasks onto the AI. See, building something with AI is something anyone can do. But trying to extend on that code at a later time? That's when some people are going to run into major issues.
1
u/ContentImpress1118 19h ago
just realized my comments probably sound like AI to everyone here but I’m just not advanced enough to always remember the logic behind doing something in my code lol
1
u/jessica_connel 18h ago
Yes! It’s a lot less readable and variable names and comments usually give it away for me
1
u/BigPersonality1574 1h ago edited 57m ago
I work with average python devs, the increased use of methods such as getattr() are very AI. I dont like it, because getattr provides a fallback, when sometimes you just want it to fail because it can mean an attribute didn't get initialized which should have at a certain point in the code - and we should rather handle that at that section. Also very thin wrappers (functions that just call another function) pop up all over the place. Also comments of about 3 lines started appearing a lot over the last 3 months.
Then I end up commenting this recurringly in PRs: is the fallback a conscious decision or should we just make it fail? Rarely I get a clear answer.
So these kinds of patterns in the code, python stuff that is more 'obscure' in daily python use suddenly inflated in code base, without an answer ready why that approach, with a clear tendency to built in very thin wrappers and lots of fallbacks, even though sometimes it should just fail (which you can handle at the appropriate point).
I suspect AI is trained to provide all these fallbacks to give you the dopamine of having this 'working' project out of the box. But not failing is not the same as working.
•
u/doubleyewdee 10m ago
Heavily context-dependent, for me I can often tell by the typical AI "failsafe" mannerisms that a regular developer wouldn't do in the course of their work, many of which are language-agnostic. Error-checking for very unlikely "this should probably leak and crash your app, actually" exceptions and logging them is very AI to me. So are certain kinds of comments/docstrings. Also, harder to define, but I feel I can tell when I get LLM-output Python code via the way type hints are used (basically: poorly and unevenly).
One other tell-tale sign is weirdly encyclopedic knowledge of the Python standard library. If I see code appear using dusty/disused things I never even knew where in the stdlib, it's likely AI.
1
u/Long-Opposite-5889 2d ago
Of left untouched after the LLM spit it out you can definitely tell it's AI.
1
u/ZSJJ 2d ago
What’s the giveaway? Syntax, comment or general language
3
1
u/Jello_Penguin_2956 2d ago
A few things. At least what I notice from Claude. Could be different with other ones.
- over-explanation in comments. You often see them overly decorative too like # --- <comments> ---#
- Double or triple validation. It tends to do extra checks on things that often I didn't think necessary. Just as we speak I just directed it to pull file names with glob and yet it does if exist checks on every single one of them.
- Variable naming. More obvious if you're working in a specific domain I suppose you'll spot words that sounds alien to you. I assume is probably from different industry where it makes more sense.
- excessive use of REGEX. Used even in simple checks I wouldn't have thought about using. TBH not a bad thing and I found my own REGEX skill improved 10 folds in recent years thanks to AI.
- Nested functions. Lots of nested functions.
1
u/alliknowis 2d ago
Yes, the comments are usually so much better than a human's work. The other tell, which is a negative, is that they seem to look for libraries as soon as they encounter any slowdown. So lots of libraries, and they often solve each issue with a different library with no attempt to consolidate solutions into fewer libraries. Easy enough to prompt for either during or after proof of concept. Just a couple giveaways for me though.
158
u/Plenty-Midnight2075 2d ago
You usually can't tell with certainty just by looking at the code.
There are some patterns that make me suspicious though: way too many comments explaining obvious lines, generic variable names, unnecessary abstraction, overly defensive error handling, or code that is technically clean but doesn't really match the style of the rest of the codebase.
The bigger giveaway is usually not "AI style", it's when the person can't explain why the code works or why a particular design was chosen.
At work I use AI pretty often, but mostly as an accelerator: boilerplate, tests, refactoring ideas, debugging, unfamiliar APIs, or getting a first draft of something. I still want to understand and review anything that actually gets merged.
Good AI-generated Python and good human-written Python are getting harder and harder to distinguish. Once a competent developer edits the output, I don't think there's a reliable way to identify it from style alone.