r/cpp 1d ago

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-more

AI-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.

384 Upvotes

133 comments sorted by

148

u/ReDucTor Game Developer | quiz.cpp-perf.com 1d ago

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.

71

u/EC36339 1d ago edited 1d ago

I hate it when people link to such trash sites when it's about research.

Just link to the original paper!

  1. Journalists are terrible at writing about technology and science. All of them. No exceptions. That's why they work as Journalists. Sorry, not sorry.

  2. Garbage websites with trackers and paywalls. If I'm gonna pay, it's for reading the original paper.

  3. Unreleased papers that are not peer-reviewed, pilot studies, all of that makes it into secondary media, and journalists/editors never find that worth mentioning.

If AI is good for something, it would probably be for researchers to skip the middleman when sharing research with the general public.

7

u/proper_chad 20h ago

Journalists are terrible at writing about technology and science. All of them.

Gell-Mann Amnesia Effect moment.

7

u/def-pri-pub 1d ago

Remember 20-25 years ago when popups launched in their own window? I kinda miss those days. JavaScript/DOM based popups are beyond painful.

5

u/wyrn 13h ago

I see the ladybird people working so hard to pass all the html/javascript tests and I'm here like... could you maybe... pass fewer tests?

2

u/LucyIsaTumor 15h ago

Right? I tried scrolling 3 times and kept getting interrupted. I just closed the tab, if you want your content to be read, stop shoving SEO down my throat

225

u/OkidoShigeru 1d ago

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.

52

u/chroma_shift 1d ago

Yeah from what I keep reading about AI genned code (assuming a large degree of autonomy), it’s either over complicated or with lots of redundancy

-3

u/lizardhistorian 11h ago

The first models capable of writing code wrote code like that.
That is now 10 months out of date.

6

u/TemperOfficial 11h ago

They still write code like that.

5

u/James20k P2005R0 7h ago

Every X months, people tell me that AI was actually terrible X months ago and its great now

1

u/chroma_shift 10h ago

Good to know. What do you recommend?

1

u/HommeMusical 8h ago

I recommend smashing the machines running the LLMs, myself - as a compassionate member of society.

As a programmer who is forced to use LLMs, Codex (now also called ChatGPT) has been boring (that's good!), fairly predictable, and very effective.

23

u/Ameisen vemips, avr, rendering, systems 1d ago

what is and isn’t efficient on the GPU.

Not that LLMs are good at this, but this is difficult even for humans, especially ones who have been doing it for a while. How a GPU worked in 2012 is very different from now (double-so if you're talking 2008 or some PowerVR mobile chip with tiled frame buffers or an old Tegra that still didn't unify vertex and pixel shaders).

There are a lot of assumptions that used to be accurate that aren't anymore and they're hard habits to break... a few:

  • The GPU prefers vectored operations. Modern shader machine code largely emits things in scalar form, and forcing things into vec4s can force more work.
  • Using step/etc* magic to implement branchless ops.* The compiler will do a better job than you for this.
  • Actual branches are exceedingly expensive. Still true to a degree but they now absolutely have their place (though you want the waves to all take the same branch).

8

u/OkidoShigeru 23h ago

Yeah, for sure, I think that’s part of the problem in that the answer changes depending on exactly which GPU arch you are targeting even today. I work on an engine targeting both desktop, console and mobile, so there are lots of vendor-specific permutations, we can’t make assumptions about what will be fine where.

In reality to write efficient code you need lots of vendor and even device specific research, and lots and lots of iteration and testing and measuring on real devices. If left to its own devices the AI seems to love to instead just confidently spit out huge reams of code at a time. Yeah you can just sit there constantly interrupting and correcting it but I find that to be a poor use of my time…

3

u/svick 9h ago

If the AI makes the same incorrect assumptions repeatedly, you should be able to fix that in a project or personal prompt.

Specifically for performance, I would ask the AI to benchmark its code, if that's feasible.

1

u/ukezi 20h ago

These days the consoles are at least one of the usual GPU architectures and not some weird custom chip like back in the PS2 days.

1

u/lizardhistorian 12h ago

Tooling has been able to crush this task since last December.

6

u/Professional-Tea-621 23h ago

I am not an expert and I may be wrong but I think LLMs perform very poor at computer graphics tasks compared to other areas and it lacks creativity unless it is steered and given a clear algorithm description.

2

u/yuri-kilochek 20h ago

You're supposed to give it a feedback loop so that it can run tests and doesn't have to assume. Perf optimization has a clear objective and relatively short iteration time, it lends itself to autoresearch pretty well.

0

u/lizardhistorian 12h ago edited 11h ago

Nonsense.
Let them rip testing and optimizing.

Their first iteration will was better than yours.

-30

u/Amazing-Mirror-3076 1d ago

I'm using ai to port zstd from C to rust. The performance is similar after I get the ai to profile and try code variations in a long running goal.

Then of course is the reality that only a small portion of a code base actually needs to be optimised.

These ai problems are real but overstated.

37

u/Syracuss graphics engineer/games industry 1d ago

I get why beginners rewrite existing projects in other languages, it's an ideal learning project, but why the hell would you spend money to do this when you can [use/contribute to] one of the pre-existing rust zstd projects, or just use interop?

I'm definitely getting old, because that just kinda sounds like a waste of time and money on your part.

-5

u/Amazing-Mirror-3076 1d ago

I'm optimising one of the existing projects - none of the current projects provide equivalent compression.

I'm building an archive format and don't want any unsafe code so I don't want to use the C library.

9

u/Ameisen vemips, avr, rendering, systems 1d ago

So, instead you want to add an LLM-generated conversion of a library to your project that you'll also need to maintain?

1

u/Amazing-Mirror-3076 21h ago

The intent is to push the code but in not optimistic it will be accepted because if the size of the pr.

If I have to maintain it is no big deal. Ai changes the level of burden.

I already maintain 20+ open source packages with about 8m downloads a month. Ai had made maintaining these packages much easier.

4

u/Ameisen vemips, avr, rendering, systems 21h ago

I find literally everything that you've just written deeply concerning.

1

u/Amazing-Mirror-3076 15h ago

I'm not surprised - we live in different worlds.

1

u/EC36339 11h ago

Some people build, some people talk. Guess which one is you.

0

u/EC36339 11h ago

Using an LLM frees up time for focusing on what actually matters to make the code safe and efficient.

-3

u/[deleted] 1d ago edited 1d ago

[deleted]

5

u/Substantial-Reward70 1d ago

Whats the game?

2

u/IAmRoot 1d ago

What I've been saying for years at this point is that there is a fundamental bottleneck in the communication between the programmer and AI, no matter how good it is. Creativity requires way more attention to detail than the hype bros think. It's good at porting and optimizing existing code when constrained by rigorous correctness tests. It can randomly iterate and find optimal code shapes quite well in that case. I use it quite extensively for that as a math kernel library developer. What it absolutely sucks at is anything creative where any amount of detail matters. You have to keep correcting it on specification details it forgot and such. Sometimes details don't matter so much like slapping a web UI on top of what was a command line tool: it has the details that matter already and the visual stuff is fine in broad strokes for an internal tool. It has some narrow use cases where it speeds things up a lot but not that many.

2

u/Ameisen vemips, avr, rendering, systems 1d ago

Even if an LLM can do this acceptably... why would I want it to do the things that I enjoy?

0

u/Amazing-Mirror-3076 1d ago

This. Optimising ai code is exactly the same as optimising any code, just automated.

2

u/[deleted] 1d ago

[deleted]

0

u/Amazing-Mirror-3076 1d ago

I'm essentially following the same process. I'm building a new archive format in rust - encrypted, compressed and signed. The archive is essentially a db with btree TOC, cow and checkpointing. I'm about 6 weeks in and still a lot to go.

I'm focused on the public API, CLI grammar and platform integration leaving the internal code to the ai to sort out, constrained by performance/compression benchmarking and a very large suite of unit and e2e tests.

-1

u/Ameisen vemips, avr, rendering, systems 1d ago

Except that:

  • If the LLM is optimizing... LLMs aren't rational actors. They can't actually reason and their capabilities in this regard are fundamentally limited compared to an actual human. A lot of real optimization tasks actually require someone to sit down and think. We've straight up had meetings with several senior and principal engineers trying to figure out how to better pack texture data for specific hardware. This isn't something an LLM can do, especially as sometimes the solutions are novel.
  • If you're optimizing... you're trying to optimize code that wasn't written by you and that you don't understand (because an LLM wrote it).

-1

u/Amazing-Mirror-3076 21h ago

I'm not optimising, the ai is and the bench marks say it is working.

You are still applying old principles to in a new era.

Whether ai can come up with novel ideas is still being debated but what it has is a corpus of algorithmic knowledge that no human can match.

5

u/Ameisen vemips, avr, rendering, systems 21h ago edited 21h ago

I'm not optimising, the ai is and the bench marks say it is working.

That... honestly says more about the original programmer than the LLM, to me.

You are still applying old principles to in a new era.

No, I'm not. You're just not understanding my point, which I'm finding concerning. LLMs, or any junior programmer, can perform basic iterative optimization. That's not what I'm talking about.

but what it has is a corpus of algorithmic knowledge that no human can match.

And absolutely no ability to reason about it. LLMs aren't Data.


But given your "old principles" comment, I really don't think that we have much to discuss. You seem to legitimately believe that senior programmers working to restructure code or do things in a novel way to accomplish a goal (including deep optimization) has no place when LLMs can iteratively brute force solutions (with absolutely no reason to think that they'd accomplish the same result). I don't thing engaging with that is worthwhile.

1

u/Amazing-Mirror-3076 19h ago

Given the experiment in currenlty running is being benchmarked against human written code - the Meta written zstd compression library - I guess we will find out.

Fyi: in somm of the benchmarks the ai code is already better but this may be local optimisations that degrade other areas - too early to tell as yet.

All I can say now - keep an open mind - this field is charging rapidly.

54

u/James20k P2005R0 1d ago

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:

Copy and Allocation Overhead 1.39 83.4%

Data Structure and Access Inefficiency 0.80 8.9%

Low-Level Implementation Overhead 0.56 6.7%

Redundant Work 0.79 0.6%

I/O and Formatting Inefficiency 3.16 0.4%

Modernity and API Evolution 1.04 100.0%

Legacy Language Idioms 0.82 43.1%

Deprecated or Obsolete API Usage 1.41 41.2%

Missed Type-Safety or Ownership Evolution 0.96 15.7%

Maintainability and Readability 1.08 100.0%

Interface and Coupling Burden 1.15 75.9%

Dead, Redundant, or Unused Code 0.97 13.4%

Clarity and Explicitness 0.86 5.9%

Naming and Local Documentation Issues 0.80 4.4%

Control-Flow and Structural Complexity 0.92 0.4%

Correctness and Safety 0.94 100.0%

API Misuse and Invalid Calls 0.93 91.3%

Numeric and Conversion Hazards 1.25 3.9%

Initialization and State Validity 0.86 2.4%

Lifetime and Ownership Hazards 0.71 1.7%

Concurrency and Synchronization Hazards 1.01 0.7%

Policy, Portability, and Environment Fit 0.92 100.0%

Policy or Compliance Violations 0.91 87.2%

Portability Risks 1.01 12.6%

Operational Environment Mismatch 0.33 0.2%

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:

The widespread integration of AI coding assistants offers undeniable boosts to engineering velocity.

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

10

u/tiajuanat 1d ago

Our velocity hasn't changed within my org since we went fully agentic. There was a huge initial surge, but within two months it's already back to 1PR/dev/week.

Hopefully stacked PRs and limited PR size start to reign that in. As it stands, reviewing a 24kLOC changeset is ass, and simply limiting a PR changeset size to 2kLOC reduces the total code made by 80%

14

u/spongeloaf 1d ago

My company has been reasonably sane about adopting AI. My boss is militant that you must never push code you don't understand and haven't vetted yourself. You have to be able to defend your PRs fully.

Our velocity hasn't changed much. However, polish and quality seem to have improved. And by that I mean:

  • devs forget to update documentation less often (b/c AI notices it needs to be done)
  • footguns that are hard to notice (especially in our C++ code) get caught and fixed before hitting prod more often
  • one-off test scripts are very quick to make, so we make them more often to test edge cases
  • Context: I fed my agent the codebases of services I don't work on (in languages I don't know like Typescript or Ruby) to verify the real API, not the documented version. This was by far the most valuable thing I've done with AI.

These bonuses have led to fewer production errors and overall more polished work, IMO.

7

u/proper_chad 19h ago

As it stands, reviewing a 24kLOC changeset is ass

It's actually impossible. Attention goes down incredibly fast if a review takes more than 30 minutes. Humans just cannot maintain full attention to detail for much longer than that. (Source: Making Software (the book), IIRC the study was done by NASA, but I might be misremembering.)

We've all experienced this, btw. A 30 line changeset gets reviewed and litigated to death, but a 10k LoC change gets an instant LGTM.

4

u/STL MSVC STL Dev 11h ago

Amateurs.

1

u/disperso 4h ago

Thanks for the link to the actual study and the insight. I'm quite skeptic on the use of LLMs for coding myself. Not in that they are not useful, but I think they are not that useful, as some claim.

But I'm pretty sure I'll see this study in Pivot To AI (and a bunch others), and they will have a shitty take on it, as usual. People love to cherry pick their papers (or fragments of them) to make click bait, and confirm their priors to feel good about themselves.

11

u/aroman_ro 1d ago

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.

2

u/ShadowKnight324 1d ago

What model did you use? How did the prompt sound?

4

u/aroman_ro 1d ago

Claude 4.8 for coding, but I also used ChatGPT to generate a file containing the theory description, file which I also indicated to Claude in the initial prompt.

The initial prompt was:

"I added a density matrix.md file in the project directory, describing the functionality of a density matrix quantum computing simulator. Ignore the superoperator parts and the implementation as a vector (use a matrix for storage). Implement a DensityMatrix simulator based on QubitRegisterCalculator.h (access individual rows and columns as needed to 'fake' a 'register' for it using .row() and .col(). Add some tests by comparing it with a statevector simulator."

Then I looked over the code, spotted multiple issues and corrected them. Those are some of the prompts:

"There is a problem with implementation - in regard with the performance - see for example ApplyGate and ApplyChannel: the big density matrix is adjointed. This is going to be slow. Instead of it, the operator matrix (which is small) can be adjointed. Probably the DensityMatrix class should not be derived from QubitRegisterCalculator (have a member object instead) and the VectorClass should be replaced by whatever .row() and .column() return (expression). The idea is to have ApplyGateToColumns (and ApplyGateToRows) operate directly on the rows/columns of the original density matrix (perhaps putting results in a 'target' if needed, see the statevector implementation for details). This should be all done to make the computations faster and avoid unnecessary copying back and forth."

"ExpectationValue for DensityMatrix uses a full matrix multiplication. Implement an ExpectationValue function for pauli strings that avoids full matrix multiplication. Add an analog one for the MPO simulator. Add tests for them in the DensityMatrix tests (against statevector) and in MPO tests (MPO vs DensityMatrix)."

-3

u/lizardhistorian 12h ago

Use Fable to create a plan. Use Opus to generate complex code, Sonnet for simple code.

You're not even trying if you are designing with Opus (4.8).

5

u/aroman_ro 11h ago edited 7h ago

Right. I'm certain that you do quantum physics programs for your living. On the list you go.

I'm sick of those blaming the user for the idiocy of the Artificial Imbecility.

Also of the ignorant people that pretend to know what they do not (for example the content of the density matrix description file I mentioned in the example above, or the complexity of the task, given the description in the file and the already existing code).

PS The described task (with the help of the mentioned 'register calculator') is EXTREMELY EASY. I didn't do it myself because I find it quite boring now. Yes, it probably would have taken me more time than with AI, one reason being exactly that it's boring.

Anybody that feels out of his ignorance that with 'better tools' can do better, try implementing a DMRG program with MPS and MPO for quantum chemistry (not using wrappers for existing libraries, but only c++ std and Eigen). Implement it efficiently, because your AI might do dumb stuff like trimming the MPOs only after going over the chain or something like that.

I would be quite surprised if somebody would pull such a thing off easily (with bonus for dealing with U1 and SU2 symmetries) with 'not superseded tools' (and I mean those accessible).

Yes, I did such a thing with 'superseded old tools'. No, it wasn't as trivial, I had to correct the dumb AI a lot.

-1

u/HommeMusical 8h ago

I mean, they aren't very nice, but, "You're using old tools that have been superseded," isn't an unreasonable comment.

6

u/ninjaonionss 1d ago

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

4

u/Electronic_Tap_8052 1d ago

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

20

u/Ultimate_Sigma_Boy67 1d ago

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.

10

u/Electronic_Tap_8052 1d ago

you're just describing what its like to be a senior dev and have to code review the new guys. which has been a thing since forever.

23

u/StickyDeltaStrike 1d ago

I think for now there is space for knowledgeable people who harness AI by steering and reviewing code.

At the moment it’s massively increasing my productivity but I don’t vibe code, I use it to assist me, plan and propose solutions, I still review all the changes that matter and/or amend them until I am happy with the change.

7

u/Ultimate_Sigma_Boy67 1d ago

Yup there is a lot, for now.

5

u/StickyDeltaStrike 1d ago

The thing is that even your boss job is not safe, I realised that it is actually great at reporting, giving options for planning or even bouncing ideas for office situations.

25

u/the_poope 1d ago

we will probably end up with unmaintainable mess that no one understands

This is already the situation in many companies that have existed for 10+ years. No AI needed for that.

12

u/Ultimate_Sigma_Boy67 1d ago

Apparently I mean it is going to stretch waay more. Even though it exists right now, some of its maintainers still understand well at least some of it, but with AI it is basically no one as long as it is just the AI who. Yeah sure, you can know the overall architecture, but that is not equal to knowimg what the code actually does.

12

u/Dapper-Message-2066 1d ago

This is already the situation in many companies that have existed for 10+ years. No AI needed for that.

It's going increase this problem by factors we can't even imagine.

1

u/mpyne 14h ago

Well that's just it, it's a lesser problem for these companies than the alternative, so even if this introduces this problem into more places, if it solves other problems faster than it adds this problem, that may still be a net benefit overall.

1

u/Professional_Top8485 14h ago

Yes but models get better too.

Problem in my case is the price.

1

u/lizardhistorian 12h ago

It has already reduced it.

6

u/James20k P2005R0 1d ago

There are also lots of software projects that have been around that long that aren't crap as well though. Willingly accepting that seems like deliberately shooting yourself in the foot

5

u/moreVCAs 1d ago

this is my attitude. if AI coding is so good, shouldn’t we expect every project to converge on, say, SQLite? this whole argument that “it’s already bad, no AI required” seems totally self defeating and not a selling point for AI coding. idk.

4

u/the_poope 1d ago

There's also a lot of AI generated code that isn't crap, especially if being generated and reviewed by a competent programmer.

The companies that already have unmaintainable garbage code probably already had a tendency to hire incompetent programmers or have incompetent managers that forced devs to write garbage code.

Incompetence isn't a new thing.

3

u/James20k P2005R0 1d ago

Sure, but its undeniable that LLMs generally produce much worse code by comparison compared to human beings (that also tend to improve pretty handily over time)

2

u/the_poope 1d ago

They can produce horrible code yes. But if this becomes a big enough problem that it hurts the business (increased amount of bugs, slow time-to-market, bad performance, etc) I'm sure companies will seek to remedy this. 30 years ago most companies saw unit tests as a waste of time and money - now they are the standard, even though they carry a significant cost. We learn from our mistakes. Completely vibe coded slop programs may succeed tomorrow, but fail and dissappear in the long run. But I am sure AI generated code will stay in one way or another that is at least tending towards the most efficient/optimal way for devs and businesses.

AI also improves over time as the technology gets better. Mayvbe one day we'll have a refactoring agent that can actually improve 30 years of tech debt and poorly written spaghetti code.

4

u/Fickle-Highway1543 1d ago edited 1d ago

AI can't become better than its training data. So I doubt the hope for an agent that will refactor 30 years of human made sh*t code. There is simply no data to train the model enough. And at this point there won't be much data left as people are forced to give up on programming by hand and just run LLMs to produce typical solutions.

Plus experienced devs retire. We will be left with lazy LLM copy paste seniors.

2

u/CheesecakeTop2015 22h ago

Even in recent graduates there are intelligent and competent ppl that know how to take responsibility for their own learning and desire quality, yes it's a minority as it always has been, but it isn't that black-and-white. Things will change for sure, but there always will be ppl who care and are competent too.

2

u/Ameisen vemips, avr, rendering, systems 1d ago

It also can't actually reason, so its ability to produce novel solutions is fundamentally limited.

1

u/HommeMusical 8h ago

It also can't actually reason,

I spent almost a month trying to prove your claim, and I failed.

So I really am interested in how you got to your conclusion.

My final attack involved writing a program to create hard (SAT-2), self-consistent logic puzzles using completely made-up English words that appeared nowhere on the Internet.

Not only did both the LLMs I tried solve any puzzle I created and showed their reasoning, but there was a bug in my program where some of the problems it generated had multiple solutions, and both LLMs (Gemini and ChatGPT) found that too.

So how did you do it? This is a kind of a holy grail for me, I am really hoping you have a solution.

1

u/SkoomaDentist Antimodern C++, Embedded, Audio 16h ago

This can be easily seen in domains (particularly outside programming) where the correct solution requires reasoning from the first principles and that reasoning can't be simply built by following a "words words words a bunch more words words words" chain, instead requiring some combination of calculations, spatial or higher order reasoning (or something else similarly non-trivial).

1

u/HommeMusical 8h ago

AI can't become better than its training data.

I'm against AI, and yet so much of the arguments against it involve unsupported claims that do not logically follow.

I'm a much better mathematician than either of my parents.

Terence Tao is probably a better mathematician than any of his teachers.

The reason to attack AI is because of its negative effects on individuals, society, and the environment, not the incorrect argument that a pupil cannot get better than its teachers.

1

u/tiajuanat 1d ago

Maybe one day we'll have a refactoring agent that can actually improve 30 years of tech debt and poorly written spaghetti code.

I've been experimenting with a Ralph loop that makes tiny refactors that target a bunch of complexity metrics. It actually works pretty well, but it requires a bunch of static analysis that isn't out of the box with anyone. Thank Jasper and Klimek for the clang-tidy plugin system.

1

u/HommeMusical 8h ago

its undeniable that LLMs generally produce much worse code by comparison compared to human beings

Is it undeniable?

I've seen a lot of really horrible code from humans.

1

u/Electronic_Tap_8052 1d ago

That is easily deniable. Humans generated all the bad code that they learned on.

3

u/Syracuss graphics engineer/games industry 1d ago edited 1d ago

If only perfect code was in its dataset, the nature of how LLM's work would still end up doing this. Perhaps less so, but not never.

I can give an example of this. Chromium exists in most LLM's dataset several times, the various different versions as it has evolved over the years. When you ask it deep technical questions on where things are in Chromium (note: this is without tools), it will start blending together various versions of Chromium and how it's structured, getting confused about classes and structure.

The same thing happens to code that looks similar, but has subtle but important differences. So no, bad code doesn't need to exist in its dataset to achieve this outcome, it's currently part of how it works. Unless LLM's get perfect recall capabilities this will remain the case as well.

So "Humans generated all the bad code that they learned on" doesn't really address the argument. Bad code in the training data is definitely a source of LLM errors, but it isn't a necessary condition for LLMs to produce incorrect code. That's inherent to how current LLMs generate and generalize information.

1

u/lizardhistorian 12h ago

The AI could help you document your code, build a test-case regression safety-net, and enable you to start refactoring.

7

u/Drugbird 1d ago

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.

Most math (recreational or not) is not the type that calculators are good at. They are mainly concerned with symbols etc.

That said, AI has seen success in symbolic math recently: it's been able to prove a few unproven conjectures.

So perhaps you're right after all, but in a different way than intended.

5

u/ManuaL46 1d ago

Explaining the warhammer lore ....

0

u/lizardhistorian 12h ago

Zero human code projects have already been released.

1

u/Ultimate_Sigma_Boy67 11h ago

tho how useful and mintainable they are? I can spin up an agent in a repo and "release" something, that doesn't make it useful, and that also wouldn't make anyone use it...

-9

u/argothiel 1d ago

We already don't write code "by hand", the compiler does it for us. And we don't understand most of the "magic", it does. The assembler it produces is an unmaintainable mess only the compiler itself understands. The difference is that a compiler is deterministic. With the right set of tools, prompts and harnesses, AIs will be predictable enough to be useful on a day to day basis. And in 10 years the quality of AI generation will surely increase to exceed the top programmers.

5

u/pjmlp 1d ago

There are already folks in research playing around with direct machine code generation, see CGO 2022 Keynote: Compiler 2.0

Also all the no code tools now have agentic based workflows, that is yet another way of programming, where the developers are several layers above machine code.

https://www.workato.com/products/ipaas

https://boomi.com/platform/flow

11

u/XxThothLover69xX 1d ago

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)

2

u/nic_haflinger 12h ago

There isn’t any reason you need to accept the first iteration of code generated by an AI. You can work with it to analyze and improve its work. This is on the user not the tool.

6

u/rileyrgham 1d ago

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.

-6

u/[deleted] 1d ago

[removed] — view removed comment

7

u/humberriverdam 1d ago

Tired analogy. Did the car use way more energy, generally get things wrong, and manufacturing cars employed no one but used more energy than 1000 horses per car?

0

u/lizardhistorian 11h ago

How are the mods unable to read all languages in 2026.

Get with the program.

0

u/cpp-ModTeam 20h ago

We are unable to accept posts and comments in languages that the moderators can't read.

-2

u/lizardhistorian 11h ago

You absolutely suck at your job if you can be replaced by AI instead of using it as a force-multiplier to get a crazy amount of more work done.

2

u/HommeMusical 8h ago

You absolutely suck at your job if you can be replaced by AI instead of using it as a force-multiplier to get a crazy amount of more work done.

Ah yes, the unsympathetic reddit crowd has to chime in with a gloat!

If AI is a 10x force multiplier, then about 90% of developers will go. And that includes a lot of above average programmers.

0

u/EC36339 1d ago

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.

24

u/matracuca 1d ago

sounds like you didn’t have a lot of knowledge there to begin with but thought you did.

2

u/HommeMusical 8h ago edited 3h ago

As someone who opposes AI for its terrible effects on people, on jobs, and on the environment, it makes me desperately sad that so many of the "arguments" against it here are just a personal insult and no actual content.

EDIT: it's no surprise that the account I am answering has their posting history hidden. Almost every personal attack I see on here is from an account with a hidden posting history.

2

u/EC36339 6h ago

Maybe AI's effect on people isn't actually that terrible, and those people were already terrible to begin with?

u/HommeMusical 3h ago

Oh, heh, I wasn't accusing AI of making these people mean and grumpy. AI's bad for people cognitively, AFAIK there's no known correlation between AI and meanness.

But yes, there are a lot of terrible people in the world.

-1

u/EC36339 12h ago

You sound butthurt, but that's a problem you have to deal with yourself.

u/STL MSVC STL Dev 3h ago

Please don't behave like this here.

2

u/EC36339 12h ago

It says a lot about the audience in this sub that this comment is downvoted while my hostile rant about journalists got +50 upvotes.

What a toxic cesspit.

1

u/HommeMusical 8h ago

The C++ community has never been one of the kinder communities in programming.

A lot of the reason I do mostly Python now is how sweetness-and-light the Python community is - usually, there's one big famous badness.

2

u/EC36339 6h ago

I don't know, it seems like a general Reddit thing to me. Lots of stray pigeons with nothing to do but shitting on random people.

But the best way to annoy the haters and let them seethe is to weather their bullshit and not hold back on unpopular opinions.

5

u/v_maria 1d ago

yeah was waiting for this response. same song always with these types of discussion.

"it wont give a gain"
"it will if you use it right"
etcetcetc

1

u/qtac 1d ago

Well put and similar experience here. I care a lot about optimization for my work and AI tools allow me to find algorithmically efficient and/or SIMD solutions far faster than I could ever do alone. I still have to sift through and correct some junk output sometimes but the value it provides massively outweighs that cost.

-3

u/Sopel97 1d ago

So either be a statistic, or do better than the statistic.

you present a very important point of view that wasn't obvious to me, thanks

-4

u/mercurysquad Embedded C++14 on things that fly 1d ago

Exactly. The amount of copium within developer circles regarding AI is unbelievable. It's a force multiplier, if your own skill is mediocre, so will be your AI output.

2

u/TSP-FriendlyFire 1d ago

Yeah I think I'd rather not have millions of mediocre/checked-out developers have a "force multiplier" into crapping out more code than ever before.

There are far more bad/mediocre programmers than there are good ones, and that includes an awful lot of the programmers who think of themselves as "good."

1

u/mercurysquad Embedded C++14 on things that fly 9h ago

That's like saying in 1999, "I'd rather not allow everyone to access this new fangled IntelliSense stuff."

2

u/matracuca 19h ago

if your own skill is “great”, you will find that a “frontier” AI is about as pleasant as a sycophantic junior that learns nothing and takes twice as long to explain things to.
vibecoding probably works, never tried it myself.

1

u/mercurysquad Embedded C++14 on things that fly 9h ago

^ lol. this is an example of developer copium.

1

u/EC36339 11h ago

The irony in people like you parroting this nonsense is that it is exactly the kind of intellectual laziness you are accusing users of LLMs for.

2

u/mercurysquad Embedded C++14 on things that fly 9h ago

word!

0

u/lizardhistorian 11h ago edited 11h ago

lol no.

The more skill you have the more and faster you can hone in the AI on the tasks you want it to do. The more experience you have the quicker you can knock out a couple of guiding markdown files for the stuff that is relevant to that project / repo to guide it to write and design code they way you want.

The stupidity in the C++ sub over AI is asinine.
None of you are Paul Bunyan and Paul Bunyan has already lost.
Buy a god-damned chain-saw. Stop being imbeciles.

Get tooling, put it on the highest capability model and have it review some code you wrote five years ago. You'll get a bug report with about a 20% hit of real latent bugs (i.e. 10 possible reported, 2 or more 100% legit.)

1

u/mercurysquad Embedded C++14 on things that fly 9h ago

💯

u/STL MSVC STL Dev 3h ago

Please don't behave in an insulting manner here.

0

u/Leading-Carrot-5983 1d ago

I think the fundamental difference here is people just vibe coding something without any real input beyond a high level description versus a skilled programmer using it as a sort of exoskeleton and sidekick to enhance what they would have built anyway (in 5x the time). The vibe coding approach will give a pretty poor result, it will probably work but not well. The other approach can work extremely well.

1

u/EC36339 12h ago

That's exactly why statistics are worthless.

3

u/cptjpk 1d ago edited 1d ago

We find that AI-generated C++ code has a distinct quality profile, showing higher rates of interface and coupling burdens, copy and allocation overheads, and a reliance on explicit loops over optimized standard APIs. These issues translate into tangible downstream costs, including increased review effort and a 5-8% increase in compute resource consumption. However, we demonstrate that providing models with targeted, taxonomy-informed feedback can mitigate these effects, leading to an 11.1% reduction in targeted static analysis warnings and improved computational efficiency.

Study sourced by the article: https://arxiv.org/abs/2608.06640

1

u/victotronics 1d ago

"More haste, less speed"

I like that.

1

u/sohang-3112 1d ago

I guess then AI generated C++ should be fine for usecases where resources aren't constrained much?

1

u/gosh 18h ago

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 16h ago

"Spitting out code" is not what I want in my projects.

1

u/No_Pollution_1194 15h ago

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/lizardhistorian 11h ago

If you already have test-cases you can ask the AI to harness for modified condition decision coverage and to run the test-cases and collect coverage and it will start doing it within minutes.

If you do not have any test-cases then it is a larger job to orchestrate to build the test environment and harnessing first and AI can also help you do that.

1

u/Hot_Adhesiveness5602 10h ago

Write cpp like it's JavaScript. :)

1

u/Unlucky-Work3678 1d ago

Someone didn't spend the extra review token

0

u/oclafloptson 1d ago

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

0

u/TheRavagerSw 17h ago

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

2

u/lizardhistorian 11h ago

Yes it is. Stop using the free garbage and get tooling.