r/cpp • u/Suspicious_Orchid770 • Aug 20 '26
AI-generated C++ passes tests. It also uses nearly 2x the loops and drives up memory growth
https://leaddev.com/ai/ai-code-is-correct-and-still-costs-you-moreAI-coding tools have swept through organizations because of their speed: you type in a prompt, and it spits out code far faster than a human ever could. However, a year-long study of 3.52 million changes inside a large unnamed technology company suggests that saving time at the keyboard can create costs elsewhere.
444
Upvotes
168
u/ReDucTor Game Developer | quiz.cpp-perf.com Aug 20 '26
That site really doesnt want people reading things, full screen tracking denial needs multiple clicks, trying to force sign up for things, and other awful patterns.
236
u/OkidoShigeru Aug 20 '26
No kidding, I work in graphics, and while this stuff can be useful for some boilerplate type stuff I wouldn’t trust it within 10 feet of tightly optimised shader code, have seen even the frontier models make so many bogus assumptions about what is and isn’t efficient on the GPU.
61
u/James20k P2005R0 Aug 20 '26
This is an absolutely terrible study, and some remarkably shoddy work by google. I'm not pro AI, what they did was take dozens of different factors and then analyse them all independently. Ie:
And then make generalisations by looking at each of these factors individually. This is literally the definition of the XKCD jellybean problem https://xkcd.com/882/. They didn't even attempt to do the statistical analysis properly as far as I can tell, and this is literally basic stats 101
I suspect the study doesn't have the statistical power to actually find anything they're looking at. Its also just really weirdly written:
Its not really how you tend to write papers which are meant to be unbiased
Also, the actual site in question posted contains near exclusively backlinks to other articles, which looks a lot like SEO farming. Its pretty crap all around
13
u/aroman_ro Aug 20 '26
Out of boredom for the subject, I generated a Density Matrix quantum computing simulator for my open source quantum computing project. I described what I want, I pointed out that the 'calculator' for the statevector simulator I already implemented can be reused, how the operators should be applied and so on and so forth... it generated something correct (the tests passed, at a quick glance it seemed mathematically ok).
Yeah, the maths were ok allright, but it did an adjoint in one place of the whole density matrix (which can be... HUGE), instead of doing the same on a tiny operator matrix.
It copied back and forth data instead of passing references to let the data be computed 'in place' (where possible).
I had to look over the code, spot the issues and prompt Claude to do the changes accordingly. Now, since it can generate a lot of code, it's hard to look carefully over all of it, so a lot of issues can pass unnoticed.
5
u/ninjaonionss Aug 20 '26
The biggest trap is the moment you let ai do the thinking , coding ai is fine as long as you let it execute what you want and not what the ai want
5
u/Electronic_Tap_8052 Aug 20 '26
you could do the same thing before AI by just copy and pasting code off stack overflow
how many times did I just copy and paste beej's network guide to roll a network stack? too many times to count
21
u/[deleted] Aug 20 '26
I'm genuinely worried whether people will still be writing code by hand / learning programming like like 10-15 years from now? It just looks scary lol. I think we will probably end up with unmaintainable mess that no one understands except the LLMs themselves(kinda), the same way basically bun is now a piece of slop being 'maintained' by claude after its rewrite to rust.
BUT, I do think programming will remain as a hobby, maybe niche, but it would remain, people who will do it because they genuinely enjoy the problem-solving aspect of it, the same way there are lots of people who do recreational maths, obviously not because there are no insanely fast and accurate calculators and computers in this world, but for the pure joy of it.
8
u/XxThothLover69xX Aug 20 '26
I love prototyping using ai because, in the words of the world's greatest visionary, "it just works". And it catches common c++ problems like it's no one's business. And after It runs, i get to optimize. So i get the 2 fun jobs, arhitect and optimise without the unfun 20h harness and glue code writing (i'm not adding boost to a project for 1 lib and 1 utility)
7
u/rileyrgham Aug 20 '26
I hate AI and would ban most.. it will take our jobs. The fact is that every weakness you see now will be gone, admittedly to be replaced by new ones, soon. It's growing. It's terrifying. It's brilliant yet flawed. And it needs to be reined in.
2
u/EC36339 Aug 20 '26
As always, the question is:
Are YOU a statistic in a year long study?
My AI-generated C++ code is better optimised than it would be if I wrote it by hand. Because I know how to optimise, and thanks to AI, I have time to optimise more.
AI also helped me discover, learn and understand several ways to avoid heap allocations in critical paths that I didn't know about and never had the time to research. And AI nitpicking stopped me from making optimisations I didn't realise were UB.
How you contribute to the statistic is your decision and under your control. It's not (just) about what tool you use, but about whether you care and are curious.
So either be a statistic, or do better than the statistic.
2
u/cptjpk Aug 20 '26 edited Aug 20 '26
Study sourced by the article: https://arxiv.org/abs/2608.06640
1
u/victotronics Aug 20 '26
"More haste, less speed"
I like that.
1
u/sohang-3112 Aug 20 '26
I guess then AI generated C++ should be fine for usecases where resources aren't constrained much?
1
u/gosh Aug 21 '26
Tests that runs methods is what you use to lock code.
This is C++, so many other techniques to create high quality code
1
u/Polyxeno Aug 21 '26
"Spitting out code" is not what I want in my projects.
1
u/No_Pollution_1194 Aug 21 '26
Guardrails are important for humans and coding agents alike. Resource efficiency and cyclomatic complexity are things we can measure. If projects don’t test this stuff, it’s kinda irrelevant as to whether a human or an agent introduced the issue imo.
1
u/Hot_Adhesiveness5602 Aug 21 '26
Write cpp like it's JavaScript. :)
1
u/Unlucky-Work3678 Aug 20 '26
Someone didn't spend the extra review token
1
u/TheRavagerSw Aug 21 '26
Ai isn't really that good outside of mechanical tasks. But for that it is extremely effective.
Like styling changes, refactoring, porting libraries.
I use it extensively to on my dependencies, but very little on actual applications
0
u/oclafloptson Aug 20 '26
I'd be very surprised if it weren't intentional. These same people would have you believe that cloud computing is state of the art and that memory is expensive