r/AskProgramming • u/TheWanderingAnimimo • Oct 16 '26
Why are all vibecoded programs and games I see coded in Rust?
Is there a particular reason why specifically Rust is used? Is it the new C++?
edit; thank you all for the comments, I've learnt alot!
167
Upvotes
222
u/canarydev Oct 16 '26
the compiler is basically a free reviewer for the ai. a lot of bugs that would show up at runtime in python or js just dont compile in rust, and the errors are clear enough that the agent can fix its own code
39
u/edave64 Oct 16 '26
The more compile time restrictions you can put on an LLM, the lower the chances that it will break things. At least for memory issues, rust forces you to explicitly mark
unsafesections, which reduces the context required to evaluate if the code is actually fine to that block.So the theory at least, I don't use LLMs enough to tell you how well this works in practice.
For true vibe-coding, it could also just be they feel a degree of "prestige" to being written in rust, or they don't care at all, just let the LLM choose, and it chooses rust because that's what a lot of it's newer training data is in
17
u/ern0plus4 Oct 16 '26
Rust's ownership and lifetime restrictions prevents any programmer (human or LLM) to write programs which makes basic mistakes of these types. In C or C++ you can allocate memory, then never free it, or lock a mutex, then never release it. In Rust, you can not do such.
In C or C++ incrementing a lock-protected value looks like:
In Rust:
In C++, if you forget
x_mutex.unlock();, it will be locked forever.In Rust, you can't make such mistake. If you don't put it into a block, it will be keep locked until the next block close, in worst case, until the end of the function.
The glass is half full: using Rust for vibecoding, at least, does not cause a wide range of errors. But a program, which have no memleaks and lock errors, still can be crap. And the glass is half empty: using LLMs, without human architecting and supervision, it will be crap, I promise.
8
u/GlobalCurry Oct 16 '26
Rust by design prevents a lot of bug and error classes, the compiler provides verbose output on the problem and it's a fun language to write by hand if the need arises.
12
u/AssistantNo3545 Oct 16 '26
Honestly I see way more Python and TypeScript than Rust when people post AI generated projects.
8
u/Adorable-Strangerx Oct 16 '26 •
Because each language has it niche - for example python is widely used by scientist. And rust's niche is "language for rewriting stuff into".
3
u/DDDDarky Oct 16 '26
Because they produce so much broken shit they hope a restrictive language will prevent some of it.
4
u/ChickenSpaceProgram Oct 16 '26
some people want to use the new shiny thing. that can be LLMs, and it can be Rust, and the type of person to want to use one is probably also going to want to use the other, because shiny.
2
u/cjc4096 Oct 16 '26
It's not a horrible way for an experienced dev to learn a new language. I've learned a ton going thru others code. Tho most wouldn't publish or market it.
For all the reverse engineering work done on existing apps. It's provides an implementation separate. It's created by a spec (even if internal llm thinking) and recreated. Not a derived work. Whether that is sufficient I don't want to get into.
2
u/KnackeHackeWurst Oct 16 '26
Most comments here are just about the language itself but Rust has with Cargo also a very easy to use build and package ecosystem. Compared to C++ it's straightforward to get a native application even for different target architectures.
Yes Cmake, Conan, etc. exists but that all still feels like makeshift solutions and nothing has any "official" blessing or is the default on multiple platforms.
After over 20 years of C++ development I love Rust for Cargo alone.
4
u/Luoravetlan Oct 16 '26
Performance comparable to C and C++, no memory leaks, doesn't compile on silly mistakes.
3
u/Due_Laugh6474 Oct 16 '26
Rust is absolutely the best language for vibe coding, and you’ll never convince me otherwise. Successful agentic coding is all about steering and flagging issues deterministically. Rust gives both. AND it’s super fast and efficient as a language. The hard part of actually learning Rust isn’t an issue if the agent is doing it, so there’s no reason not to use it.
1
u/AccomplishedBrief639 Oct 30 '26
Probably just for promotion
1
u/qrzychu69 Oct 16 '26
It kind of is the new C++ - it takes you VERY close to the performance ceiling when written well, overtaking Rust in C++ means doing "technically unsafe" things, like assuming things are true that cannot be proven true at compile time.
It can be done, but requires a lot of practice and skill to pull off.
Rust is just easier and gets you 99% of the way (or 95% for the C++ fanboys). And it has WAY better error messages, so it's easier to fix issues.
1
u/TheSodesa Oct 16 '26
Because the borrow checker and lifetime mechanisms of Rust make it very likely that if a program compiles, it also works as the program specification intended. This however shifts the burden of correctness to the specification stage, so an LLM prompter needs to think carefully about what they ask from an LLM.
1
u/rogue780 Oct 16 '26
I do most of mine in python and java ¯_(ツ)_/¯
1
u/wunderbarposter Oct 16 '26
they are a particularly good fit as rust prevents quite a few easy to make / hard to debug mistakes... mistakes which are even more difficult to find if you didn't pay close attention to the programming. The syntax/language is also on the more difficult side - AI can be very helpful with that.
1
u/crusoe Oct 16 '26
Strong assertions and types and rust prevents whole class of subtle errors in the code. Such as race conditions, use after free, etc
Plus tooling is super good and messages super helpful to agents.
1
u/tropic_gaze_v2 Oct 16 '26
the borrow checker acts as the ultimate lint tool, forcing an LLM to respect strict data integrity boundaries before code execution
1
u/No_Strike_6496 Oct 17 '26
I assume because AI can't ensure correctness with a C++ program like it can with a Rust program. The compiler just gives the AI so much for free (memory correctness namely) that it can't get with C++
1
u/huuaaang Oct 17 '26
Rust is easy for AI to write because it gets immediate feedback when it does something wrong. Same as a human programmer. In Rust, if it compiles it probably works.
1
u/biskitpagla Oct 17 '26
Rust takes care of things AI can't guarantee due to being probabilistic unlike compilers.
1
u/Alex-S-S Oct 17 '26
Because people apparently think that modern C++ doesn't exist.
1
u/Dependent-Net6461 Oct 17 '26 edited Oct 17 '26
Someone is trying to opensource adobe softwares with ai and rust. The clear failure , at the current state and considering the huge amount of burned tokens, shows that rust + ai is not that magical combo "everyone" is shilling about
1
u/texxelate Oct 17 '26
Rust has an amazing compiler and borrow checker in that the cause of a compilation failure is very well described to the programmer in clear language. Agents are also very good at interpreting clear language.
1
u/ImAmalox Oct 17 '26
Don't worry bro in a few months AI won't use programming languages anymore and it will just produce native machine code
1
u/OrphisFlo Oct 17 '26
Another reason is that it's easier to start a new project with Rust than C++. There are a lot of high quality libraries to rely on that are easy to integrate in your project.
In C++, if you try to integrate some libraries with a new compiler, you'll run into so many issues that you have to deal with first as the compilation model allows for a lot of hidden "mistakes" that are hidden behind other "mistakes". For example, some standard library header includes <string>, so you forget to do it in your code, and when the standard library fixed that accidental leak, your program stops working.
There are lots of small problems like that all the time, and it's tiring.
1
u/Low-Set741 Oct 17 '26
Better memory safety and still super fast
1
u/_usr_nil Oct 17 '26
Can someone explain to me why a comprehensive any-SAN toolchain not be enough for LLMs vs Rust ?
1
u/DawnOnTheEdge Oct 17 '26
Rust’s strong type system, and use of sum types for error checking, makes it easier to use typed-hole programming to implement a top-down specification iteratively.
It’s also more likely that a program that compiles without warnings does something related to what the vibe coder wanted. You can’t forget to free heap-allocated memory (because a
BoxorVecwill be dropped automatically when its lifetime expires) or check for error (because aResultorOptionmust be unwrapped to use it).1
u/hunterh0 Oct 19 '26
What I don't understand, is why not simpler languages like C#? which are also safe
1
u/DanKegel Oct 20 '26
If rust compiles, it tends to work Can't say that about c/c++.
1
u/DrHydeous Oct 16 '26
That's just because you're only looking at Rust stuff. There's plenty in other languages.
-1
u/iSnapThere4iAm Oct 16 '26
Because you’re terrible at developing
0
u/jankovize Oct 16 '26
yes
0
u/arjuna93 Oct 16 '26
Hipster coders don’t know anything aside of Rust and Go exists.
-4
u/Mediocre-Brain9051 Oct 16 '26 edited Oct 16 '26
Rust replaced C++ and C a long while ago already due to memory safety, having several proeminent institutions recommending it over C++ and C. It is however hard for humans to write rust code when memory management gets challenging, while AI takes care of that problem painlessly.
AI is indeed accelerating the move from those legacy unsafe languages into Rust.
Edit:
Institutions recommending Rust (or other memory-safe languages) over C and C++ due to safety concerns:
-1
u/IamGah Oct 16 '26
Because it is ‚damn hot right now!‘ and .. really it doesn‘t matter?
crap UI is shot, whatever the <language>
-2
u/code_tutor Oct 16 '26
People who are regarded choose Rust as their first language. It somehow attracted the entire "I want to be unique just like everyone else" crowd. Also they all use vim and can't even type.
Vibe coders are the same way. They think it's cutting edge or something, don't want to use "old" tech, only hyped stuff.
DHH has some things to say about it though, so there are valid reasons.
For game design specifically it's dogshit though.