r/Python • u/UltramanQuar • 17m ago
Discussion Why AI agents are so eager to use Protocol?
I hate Protocol and whenever AI agents write code they choose it over having normal abstract class with abstract methods. So whenever I see it now, I jut get triggered and think this code is probably slop. I know why Protocol could be useful, but agents constantly misuse it.
0
Upvotes
•
u/CzyDePL 13m ago edited 10m ago
Because it's a superior solution in most of the cases, abstract classes are conflating typing, code sharing and enforcing the implementation of a method into single concept, while in fact it might call for 3 different shapes.
https://hynek.me/articles/python-subclassing-redux/ that's a pretty good summary where inheritance and by extension ABCs make sense and where they don't
•
u/TMiguelT 13m ago
In my book it's preferable to abstract classes in that it's checked statically (no runtime performance cost) and supports implicit implementation.
•
u/DreamingElectrons 11m ago
Every time something news is introduced you get lots of blog posts and online comments gushing over how much better an greater the new feature is with everything else being old and boring. LLMs just absorb all of this as facts during their training, but since there is no real intelligence in an LLM, they simply don't get that it's a recurring pattern of overhyping things. In other words: AI is really susceptible to falling for clickbait.
You could blacklist protocols and just tell your AI agent to just not use the pattern or even better, not bother with agentic coding and write the code yourself.
•
u/tardmrr 12m ago
OOP Considered Harmful
•
u/PrestigiousStrike779 11m ago
What’s wrong with Protocol? It’s the right design in some cases, when there’s no expected implementation, and it’s more flexible. The only thing I don’t like about it is there’s no good way to signal that you’re implementing the protocol.
•
u/Fine_League311 13m ago
Why a dev read logs, why a dev write comments in code, why and dev write an roadmap and an changelog? cause its his Protocol!
Teach your AI with resricts not with overpromting, he is smarter than the most ones.
•
u/ProbsNotManBearPig 10m ago
I’m a professional software engineer for 15 years. I’m not saying I blindly trust ai, but I distrust humans more than I distrust ai at this point, so I’m skeptical of your opinion if it’s constantly disagreeing with Opus 5.5 or Astra.
Please give concrete examples where it’s choosing Protocol and you think it’s a bad choice, and explain why you think it’s a bad choice.
•
u/m02ph3u5 12m ago
I specifically have to instruct it to use protocol, override, and runtime-checkable. Otherwise they're gonne abc and duck-type yolo like crazy.
Also, mind your existing code base - it's context, too. If they see protocol they are likely to use protocol.