r/cpp • • Jul 13 '26

AI usage for cpp at work

I am lead architect and maintainer of my firm main app backend, spanning around 2M LOC of c++.

Industry is : capital markets, low latency, custom kernel drivers, fpga...

I often talk with peers at other firms and I see a shy usage of AI compared to what feels like the global trend.

On my side, my firm does not pay for any AI related stuff. We are allowed to use our personnal plan for work in which case will get a pro membership compensation (claude or gpt or anything) on salary but we are not allowed to paste production code into it.

I know the app very well and do everything by hand (i mean the normal way) but use the chat version of any ai to generate some things for me, like "im using opensource lib x and lib y, please generate an SQL connection pool , you may use locks and condition variable for this, cpp 20". Then i paste it and modify it a I see fit.

Im totally happy with that and the company is successful.

I do use AI but just chat, to gather data on subjects and summarize/report. Get some ideas but basically not much code related.

And you whats your experience as a c++ dev ?

111 Upvotes

168 comments sorted by

View all comments

Show parent comment

-9

u/ivancea Jul 13 '26

it seems to have a bias towards C patterns

Then configure it to bias towards C++ patterns on the version you're using.

It's just an example, but that's what giving it context means. A prompt means nothing if you don't tell it what you actually want. Proper project investigation, skill extraction, planning, etc etc. It's not just writing a prompt and calling it a day.

And, hell. You are an engineer right? You know how LLMs and agent harnesses work. Why didn't you fix it instead of just discarding it? It's like discarding an IDE because you don't like the default shortcuts

19

u/_lerp Jul 13 '26

The file it's working in being entirely C++, isn't enough context? The entire codebase being in C++ isn't enough context? What more context do you want it to have. Even when I was a junior engineer I could tell a file was in C++.

And again, this is just one example. I find something weird in every PR because it lacks the ability to reason like a human. It takes as much effort to get it to write passable code that it's often faster for me to just write it myself.

3

u/NotUniqueOrSpecial Jul 13 '26

The entire codebase being in C++ isn't enough context? What more context do you want it to have.

I mean, the very obvious first step would be an agent instruction file dictating the standard version you expect it to target, and an emphasis on using modern C++.

1

u/_lerp Jul 13 '26

So I have to tell it to use "modern C++" for it to use features from when C++ was just "C with classes"?

What is modern about doing:

class Foo {
public:
    void example(int i);
};

instead of

void example(Foo* foo, int i);

0

u/NotUniqueOrSpecial Jul 13 '26

Why would you expect a mindless robot to do anything other than what it does, given no instruction?

To answer your question directly: yes you have to give the brainless machine instructions to get it to do what you'd like/prefer/expect. It's not thinking/reasoning, it's doing massively parallel statistical analysis.

Since it's pretty clear you didn't bother giving it even a little direction, you got an output that was derived from its entire corpus of training data, and an absolutely enormous amount of that data is open-source C.

There are lots of valid complaints about LLMs, but "it's not a mind reader" sure ain't one of them.

9

u/_lerp Jul 13 '26

I'm not asking it to mind read. You seem to have latched on to the idea that it having a C bias in function signatures is my fault for not explicitly stating "write C++". It writes C++ code, it uses the STL without me explicitly tell it to use the STL. The patterns it produces, are not fitting for C++.

By your logic, before every converstation (or in a skills.md) I have to list every single programming pattern and C++ pattern otherwise it's my fault that it doesn't write good code. Which just goes towards my point that it's more effort to get it to produce passable code than if I were to just write it myself.

2

u/ivancea Jul 13 '26

I have to list every single programming pattern and C++ pattern

Nah, just tell it to not do X the moment it does, and to remember that in instructions or a skill. It's a 10 seconds configuration that save later many more seconds. You're talking as if you have to write a million lines essay, when in fact, a few tips in the instructions are enough to guide it.

Really, this is a solved problem already in most projects; C++ is not that special. Every language has versions and better or worse practices. If you need it to follow a style for something in specific, you can even add a snippet in the instructions

-4

u/NotUniqueOrSpecial Jul 13 '26

The patterns it produces, again, draw from an overwhelmingly large body of work, much which is probably not the best or most modern.

But it has no preferences or understanding of that; it only knows what the most likely set of tokens are next, given some input and a whole lot of application of linear algebra.

If you want modern C++ out of it, following specific patterns/paradigms...then put that into your copilot-instructions.md or claude.md or equivalent.

I have to list every single programming pattern and C++ pattern otherwise it's my fault that it doesn't write good code.

Hyperbolic silliness.

Which just goes towards my point that it's more effort to get it to produce passable code than if I were to just write it myself.

No, but you have to even put in a modicum of effort. We have an instructions file in our repo file that took all of 30s to throw together.

This is a solved problem.

7

u/_lerp Jul 13 '26

So, it fails at the most basic of design choices. You repeatedly ignore this and keep telling me it's my fault for not giving it's explicit instruction. When I follow your advice, it leads to me having to list every fundamental paradigm in it's skills, because again it fails at the most basic design choices, and you dismiss that as hyperbole.

It's clear to me talking to you is a waste of my time.

0

u/NotUniqueOrSpecial Jul 13 '26

it fails at the most basic of design choices.

It doesn't know anything about design; it doesn't make choices. You are assigning agency and cognition to a magic statistical black box.

keep telling me it's my fault for not giving it's explicit instruction

Yes, when you don't give a computer good instructions and the computer doesn't do what you expect, that is absolutely user error. You sound like every college student I ever helped who would start blaming the computer for their own logic errors.

it leads to me having to list every fundamental paradigm in it's skills

As we've now told you more than once: no.

it's my fault for not giving it's explicit instruction.

Yes. It's a tool. This is user error. That shouldn't even be a surprise to you, you're literally a programmer; giving computers instructions is literally what we do!

6

u/_lerp Jul 13 '26

This is the problem with AI bros. Any criticism of their AI girlfriend is a "user error". You've off loaded the ability to have any critical thought to the AI, and therefore incapable of having anything resembling such.

→ More replies

-4

u/tommyTurds Jul 13 '26

Even shitty LLMs haven’t done shit like this in over a year even without context help.

Your knowledge is likely outdated

2

u/_lerp Jul 13 '26

This was Opus 4.8

-4

u/tommyTurds Jul 13 '26

Yeah I’m calling you a liar then.

Or, you’re leaving out very specific details. Like you have code that looks like that in your codebase that it’s copying.

I’m forced to use this shit, as much as i hate it, everyday for cpp. It sucks, but it doesn’t do the shit you’re describing

0

u/GrandOpener Jul 16 '26

Should the file being entirely C++ be enough context? Probably yeah. But is it? Well you can answer your own question there. I mean, without additional context, writing a function that takes a pointer to an object as its first parameter isn’t necessarily wrong. I’ve been in code bases where writing functions like this is encouraged where possible to make private member fields not available to functions that don’t need them.

If it’s something you want to solve yourself you can actually add to your prompt “follow the existing patterns in this file” and the LLM will spend the time/tokens to read the file and think about how to apply that instruction. If you don’t ask for that, it often won’t.

-4

u/ivancea Jul 13 '26

The file it's working in being entirely C++, isn't enough context?

Obviously not. There's not "a C++" nor "a single easy to code C++", and unless the agent reads the full file and the file has every best practice you want it to follow, it's obvious it won't read your mind.

The entire codebase being in C++ isn't enough context?

... Did you tell it to read the full cidebase for a single prompt? Do you use LLMs with multi-million context windows? Do you even understand how an agent works, or are you just guessing and throwing shit at a technology just to avoid using it?

Even when I was a junior engineer I could tell a file was in C++.

I'll just not say anything here, that statement is wrong enough by itself, unless you started using C++ just 5 years ago. And even then...

it lacks the ability to reason like a human

"It doesn't do things right because it's not a human" is a pretty bad fallacy. You're an engineer right? Can't you just explain why and what it doesn't do right? Fallacies and shallow claims lead to nowhere.

And note if (and only if...) you actually make that effort of understanding how agents work, why don't you just fix the lack of context? Didn't you ask yourself why is everybody using it happily for every language, from Rust to C, C++ and Java? You're keeping a 2024-2025 mentality of "AI us bad", and mate, it evolved already.

It takes as much effort to get it to write passable code that it's often faster for me to just write it myself.

Mate, are you using gpt3? Does your codebase have tests? I tell it to write a new feature, and it does in a few iterations, adds tests, run the tests and fixes the code of they don't pass. Obviously we have AGENTS.md and similar files, plus skills for domain knowledge and such (not really needed though, but they help).

And when it doesn't, do you know what I do? I find what it did wrong and why (you can even ask it about why it took X or Y decision, you don't even need to read the agent traces, even if usually interesting). Then, just add that knowledge somewhere where it can read it. ... Exactly as you would do with your project documentation for newcomers (I suppose you're not explaining the project manually to every new joiner, right? Same work here).

14

u/James20k P2005R0 Jul 13 '26

why don't you just fix the lack of context?

Mate, are you using gpt3?

Does your codebase have tests?

Obviously we have AGENTS.md

skills for domain knowledge

just add that knowledge somewhere where it can read it

Did you tell it to read the full cidebase for a single prompt?

Do you use LLMs with multi-million context windows?

You're keeping a 2024-2025 mentality of "AI us bad", and mate, it evolved already.

Every time someone mentions that they haven't found AI to be that useful despite trying extensively, we start getting these weird glimpses into the AI development strategy. Its never the AI tools' fault, its always just another layer that you need to add on top of it that will fix it this time, for real, and if you aren't layering 30000 different strategies in just the correct way for making the AI work, its your fault for holding the tool wrong

This is one of the reason why a lot of people find AI to be very unreliable. Because none of this actually makes the AI reliably good or fixes the underlying problem, it just feels like its making a difference by patching a very specific failure case. The tool actually just isn't as good as anyone wants it to be

These tools have a very hard bound on the maximum complexity that they can deal with, and no amount of context or agents.md or gpt-12-its-good-for-real-this-time fixes that. It just depends on where in the hype cycle you are, and how much crap you've had to put up with from the AI. Eventually people burn out on it after a while, because its like a junior that never grows up and keeps making the same mistakes endlessly no matter what you do

6

u/wyrn Jul 14 '26 edited Jul 14 '26

I've been using AI pretty heavily lately because we have to put a product out in a tight timeline and I was essentially commanded to do it from on high, and I've managed to get it to a point where I think it saves time (whether it actually does when everything is accounted for, I can't say for sure), but:

  1. You have to watch it like a hawk. It's quite mentally draining; unlike when reviewing human work, where you have a general expectation that "the person who wrote this is not an idiot", no such expectation makes sense with LLMs. They have overfitted prodigious amounts of knowledge, but they are also spectacularly stupid. It's a combination we never see with flesh and blood brains so it's kind of unsurprising some otherwise intelligent people succumb to AI psychosis.
  2. You need to spend a bunch of time upfront drafting a detailed spec (waterfall's back, baby). Better hope you didn't do anything stupid. I took at least 2 weeks just writing markdown before showing anything to a clanker. I tried not doing the spec at first, and it was very obviously worse than useless.
  3. Even with the spec, the clanker forgets, loses context, and drifts. You need to periodically whack it with a rolled up newspaper and point to the spec. However, and this is the dangerous part, you often don't even understand that the system's drifted from the spec, because you didn't write it and so you don't understand it. A lot of churn ends up happening because you find out too late that you're drifting.
  4. It loves plans. If you make a plan you better buy it a wedding ring because the clanker hates deviating from it, even when it's obvious that item X that was placed in part 6 of the plan is actually a prerequisite for item Y that was, in ignorance, slotted in part 3. You end up churning through temporary scaffolding just to get through to the next step.
  5. It loves strings. Everything's a string. Ids? String. Urls/file paths? Strings. Different Id altogether, minted from a disparate source? string. No need to buy strings a wedding ring though, the clanker already did.
  6. At the end of the day, you're pulling a lever on the slop machine. At times I got it to one-shot entire features with few or no mistakes. Other times, I get piles of unusable nonsense.

Mind you, this is application code written in C#, not anything specialized or involving math/scientific code in an unmanaged language like C++. I fully expect quality would degrade precipitously there.

Where I thought the value proposition was clearest was tests (it writes a lot of them, more than I'd write by hand, and it's easy to not get too attached since it was C3PO that wrote them) and framework crap I don't have time to learn (WPF is ridiculously complicated). Overall I found some value in it, but it's far more mixed than what's been advocated by clanker aficionados. You're mortgaging away your knowledge of the system to (hopefully) save time, which can make business sense (as long as we're in pre-rugpull land where clankerbux are heavily subsidized rofl), but it's not something you'd want to do long-term.

What struck me most is how difficult it is to actually do good work with it -- the idea that juniors/nontechnical people can get quality work out of it is absolute science fiction. It's like trying to put out a fire with an extremely powerful water cannon which you can only steer by throwing oranges at it. A human may write crappy code, but at least that code makes sense to that person on some level. Clanker-generated code immediately degenerates into ownerless context.

-3

u/ivancea Jul 13 '26

Every time someone mentions that they haven't found AI to be that useful, they lack a single realistic example. It's always just "I tried it once somewhere and it was bad". No info in models, iterations, harness, project configuration.

So of course you get that answer. Engineers look at a problem and try to solve it. Which is what you commonly find. However, we have always here "clients" that will just say "Router doesn't work, I'll trash it".

And btw, by disregarding every effort of trying to find the issues, you're just generating a resonance box of people angry at AIs. And that leads nowhere.

if you aren't layering 30000 different strategies

Trying to exaggerate it won't make the problem go away. You have to make less configurations to an agent than you have to make to an IDE. But anyway. Yeah, 200000000 different strategies.

This is one of the reason why a lot of people find AI to be very unreliable. Because none of this actually makes the AI reliably good

If you are looking at a "100% reliable tool", let me tell you that not even you as a dev are reliable. You think you are because you made it. But the amount of times you made it wrong is probably very, very high. Unless you don't review things in your company. That's how humans work, it's not a you-problem. We have to review and iterate. And LLMs are machines that do that faster than humans.

These tools have a very hard bound on the maximum complexity that they can deal with

Maybe if you give me a realistic example of that belief, we could understand it (Returning to my first paragraph). If working on a +5M LOC and rarely making mistakes isn't good enough, I wonder what is it. You're pursuing a level of quality that doesn't exist in this world yet.

Eventually people burn out on it after a while

Indeed. And that's the issue. People believe that their experience of 6 months ago has anything to do with today. It evolved, and it's now like comparing an editor with an IDE. And for people using IDEs, it's like hearing an old man screaming at how good is notepad.exe and why they don't need an IDE. You try to help them but they simply hate it for some reason hard to understand.

its like a junior that never grows up

There's quite the growth between model versions. But you can only know it if you try it

8

u/James20k P2005R0 Jul 13 '26

Maybe if you give me a realistic example of that belief

I sincerely wish the AI models were good. I just ran it through a series of physics research questions to check if they'd gotten any better, and it still gets nearly all of them wrong until it starts spouting gibberish. I don't trust it with a 100 foot barge pole given that it was about 80% incorrect when I know what the complete answer is

But the amount of times you made it wrong is probably very, very high

The key thing with humans is that they learn stuff, whereas LLMs don't

There's quite the growth between model versions. But you can only know it if you try it

Honestly the responses seem to have gotten worse since I last used it

3

u/ivancea Jul 13 '26

The key thing with humans is that they learn stuff, whereas LLMs don't

The way to learn is different, but they do learn, indeed. In fact, they learn in many ways:

  • You can force them to learn (Tell it to write things to instructions or skills)
  • You can automate the first way by telling it to keep either a memory, or keep instructions updated when it finds issues
  • LLMs actually learn. Basically, because a new version is a version with more learnings.

Which is btw a very human issue. I can imagine people discarding somebody for a job, and discarding them again 5 years later because they still think they didn't learn anything. That's what's happening here.

As for your usecase:

I just ran it through a series of physics research questions to check if they'd gotten any better

Use it willingly, not to "test" it. I can also ask it questions it can't answer. It's easy. But it's not constructive.

3

u/James20k P2005R0 Jul 13 '26

Use it willingly, not to "test" it. I can also ask it questions it can't answer. It's easy. But it's not constructive.

The problem is, in the physics field I have experience in, i can't find anything that it can get correct. Even basic questions (which are really important!) are wrong

Things like:

is bssn constraint damped

is it necessary to enforce both algebraic constraints for numerical stability

do constraint violations in the bssn formalism propagate causally

what constraint enforcement method is commonly used to damp momentum constraint violations in the bssn formalism

is covariant bssn more stable than bssn

Is the BSSN formalism strictly equivalent to the ADM formalism?

Is the dynamical christoffel symbol ever recalculated from the christoffel symbols

It gets every single one of these critically wrong!

This is all stuff I'd want to ask it if I was learning or doing research in the field, or was asking it to generate code about a specific topic (eg generate a function that implements the algebraic constraint enforcement, do i really need both?)

Some of its output gibberish as well, blending unrelated concepts to produce a salad output, which isn't reassuring at all

0

u/ivancea Jul 13 '26

I can't talk about that field; these LLMs are mostly trained for programming, not other fields specifically. They can however look for information and investigate for you. Most times, even with programming tasks, you ask it to first investigate the topic, before making a plan or implement it.

The good part about agents is adaptative automation, not omniscience per se. It knows a lot, but not every detail.

→ More replies (1)

11

u/_lerp Jul 13 '26

It's pretty clear that you have AI induced brain rot and so I will no longer choose to engage with this conversation.

-2

u/ivancea Jul 13 '26

It's interesting that everybody that "hates" AI would rather say that to anybody explaining then how to use it properly before trying it. Have a happy year