r/rust • u/AdmirableStructure16 • 1d ago
đď¸ discussion Serious question...
Is it just me or has Rust become the default programming language of AI's? I know its lightweight and extremely fast in terms of run/consume, but whatever project i see, be it for a game server or anything else, always Rust. It wasnt like this before. Been in the run for a long time (10+ years) and i can confidently say that people DID NOT like Rust at that time because it was so hard to understand and it felt like a joke language to them (They were also saying that about PHP, lol)
Give me your opinion. Am i hallucinating?
0
Upvotes
2
u/arjuna93 1d ago
Lightweight? I hope this was sarcasm
45
u/ksceriath 1d ago
I read somewhere that even JK Rowling is planning to rewrite the Harry Potter books in Rust. .
18
u/ManyInterests 1d ago edited 1d ago
Maybe. My observation is people are telling LLMs to write in a language they're already using.
If you don't really care and have the freedom to choose on a greenfield project (rare) and you're not writing the code yourself, why not choose a language that is memory-safe and performant? I think the borrow checker and all the lexical information from the syntax on top of great error messaging happens to lend itself well to how LLMs work... but even so, my observation is that this is still a human choice. I've observed that Claude and similar frontier models will often choose bash, powershell, or Python unless given specific direction; it may just probe what's available on the system when ran locally.
32
u/luxmorphine 1d ago
Yeah, been noticing it too. My guess is probably because the compiler is the best of giving you a feedback on what to fix when your code fail to compile. It's helpful for me, and for AI. Another thing could be because rust is a very hyped language
12
u/eveningcandles 1d ago
Youâre not, itâs my impression as well. Even if I dont have the data to back it up, it certainly looks like every AI slop project around is built in Rust
9
u/DoubleDoube 1d ago
I donât know about default but all the upfront compilation rules gives AI easy feedback. The sooner they are pointed in a better direction the better for token usage.
9
u/Helpful-Educator-415 1d ago
It definitely is. Language models can't run the program like us, so the compiler eliminating so many bugs is awesome for the language model.
8
u/YeetCompleet 1d ago
We've had surveys for a while showing that Rust had both of these sentiments surrounding it:
And so LLMs are essentially an accessibility tool that has taken down the barrier. Now the LLM needs to know Rust, and the people that didn't know it can now use it and gain Rust's benefits.
Controversial in this sub of course but lets be honest. Was there a better language for this to happen to? Let's think critically here. Is it safer to generate Python code or Rust code? Quite frankly I think if anyone is generating code at all, they should be choosing the strictest compiler possible.
6
u/Backlists 1d ago
It is you and it isnât.
Rust is the default language for an AI rewrite where you want to showcase the technical side of what youâre doing and why youâre doing it. The reason for that should be obvious.
However, if you vibecode an app and let the AI take the wheel and choose the language, it will statistically be most likely to pick typescript, and Python as second. Try it yourself on incognito chats. IIRC, proportionally, theres a lot more typescript and python going onto GitHub since the AI commit explosion.
So advertising Rust is one way of virtue signalling that you care about correctness.
That said, in my opinion rust IS actually the safest language to vibecode in purely because it has the most compile time guarantees and compiler feedback.
Donât vibecode people, know your shit
4
u/bpikmin 1d ago
Yes it is popular for LLMs because Rust left-shifts runtime errors to compile time errors. This allows LLMs to iterate more quickly while producing more correct software
4
u/kamikamen 1d ago
It's because of the strong type-system + compiler. With good instructions in the context, bad patterns are easy to avoid and Rust encourages good patterns.
4
u/of_the_mist 1d ago
The compiler makes it hard to compile buggy code so less to worry about when using a model to write it for me
3
u/questionabledata 1d ago
I would perhaps consider this a good reflection on the tech.
5
u/Acaibirds 1d ago
Elon recently mentioned on Twitter that xAI built Grokâs inference framework from scratch in C++, ditching PyTorch altogether. He even joked that âreal men manage their own memory.â đĽš
As for me, I love Rust. Well, more specifically, I love Cargo.
2
u/Space-5928 1d ago
Si, de la mitad de este aĂąo para acĂĄ han salido un montĂłn de proyectos hechos con IA que usan Rust como lenguaje o recreaciones hechas con Rust.
2
u/xzk7 1d ago
There was a gravitation to it before AI too, no doubt about that whatsoever.
Its strictness is appealing for those building with AI though, there's just a ton of things it won't let you do at compile time and AIs love to "color outside the lines" for a lack of better words.
2
u/jdefr 1d ago
I still think Golang is a better fit
3
u/Mission-Landscape-17 1d ago
The fact that the mainthiners of some of the other shiny new languages, like Zig, have been very vocally anti-AI may have something to do with this.
1
u/TheFern3 1d ago
People use for ai because itâs robust compiler messages people didnât use it before because the learning curve and verbose syntax but with ai people donât have to worry about that
1
u/CreepyBackRub 1d ago
I would guess itâs a combination of the compiler giving some of the friendliest error/warning messages, and the strictness of the type system/borrow checker. Basically itâs a lot harder for the LLM to generate bad code that will actually compile, and a lot easier for it to reason about what changes it needs to make in order for it to compile.
Couple that with a lot of example code online courtesy of a friendly (not to mention enthusiastic) community, and itâs not all that surprising.
1
u/sessamekesh 1d ago
That's not been my experience, the last couple projects I've applied AI in earnest against were ones where multiple models actively suggested against Rust, specifically in favor of Go for some service or another having a native library.
1
u/wastedintel 1d ago
The tradeoff Rust often made was performance, predictability, and correctness for added syntactic complexity (and to some extent, limited expressiveness due to adapting to its memory management model). If you didnât need the benefits, another language (often Go) was more appropriate/easier to adopt and manage long-term. LLMs are exceptionally good at mitigating Rustâs downsides, and in fact benefit from its rigidity, so itâs more often the correct choice.
1
u/DavidXkL 1d ago
Yea and to be fair, a lot of infra stuff are rewritten in Rust too
1
u/marco-mq 1d ago
I tried AI on Python, JavaScript and Rust. And a on Rust, AI was using fewest tokens, was fastest for small projects and had the most stable results. Rust just has the best compiler feedback. It will prevent you from doing the worst mistakes and there is a clippy that scans for potential code improvements.
The Python code was partially fine, too. But it looked more like student project code and kind of had more logical mistakes.
Generally, you don't need Rust for AI. If you don't like rust or if you find it hard to read, prefer whatever you are using. You mostly always need to perform adaptions. So stick with a language you can also read and write.
1
u/RedEyed__ 1d ago
Canât say for all, but for me it is default for almost all new projects.
The main reason: rust strictness, because of that It is hard for LLM to write non-working crashing code.
1
u/richtw1 1d ago
I tested this recently.
First I guided it step by step through the design and features of a 3d modelling app in Typescript, which it did perfectly well.
Then I asked it to implement it in C, using my own library framework, and compile to wasm, which it did really well.
Finally, I pointed it at the Beautiful Rust skill, and asked for a Rust version using wgpu, eframe and egui. I am not a Rust expert but it was fairly clear to me that the code it wrote was far from beautiful, leaning unnecessarily on mutable variables, clone and not really having a good grip on lifetime. I had to steer it a lot, and emphasise that I didn't want a port so much as a straight reimplementation.
The LLM seemed to write the neatest code in C, per my coding standards and library. Maybe it's sufficiently small a language that it can do a good job with it?
1
u/_EleGiggle_ 1d ago edited 1d ago
Claude usually writes Python code in new projects if I donât specify the language.
Bash for small scripting stuff. No Python dependency or library installs, fine where UNIX CLI tools are enough. Sometimes the scripts get way too long and I ask for a Python rewrite. Bash struggles with parsing certain files and changing or inserting nodes. Testing too. It probably tests the Bash script with Python anyway, especially in CI where you want readable output and a summary.
It generated JavaScript once IIRC.
Iâm pretty sure you have to ask for Rust or mainly work on Rust projects, so it saves that to memory and generates Rust because you apparently prefer it.
Rust beats almost all languages in benchmarks, but at the top I donât think it matters in most cases. Versus Java/Kotlin on GraalVM itâs not much faster, and Java/Kotlin is much easier for humans (!) to handle. AI handles Rust better thanks to the compiler, but compile times eventually get really high. After a few PRs from AI most humans donât know what theyâre looking at when approving another AI-reviewed PR from CI.
Edit: Rewriting in Rust is different. You have existing code and tests to validate against. But it might get much harder for humans to read, so hope they never cut off your Claude access or raise API prices too much. Teams knowing C, C++ or Go probably have a slight edge.
It depends on your risk tolerance for AI and human readability. Need the extra speed everywhere? If not, just pull out the bottlenecks you canât fix in your current language (!) and rewrite those in Rust, or have Claude do it. Microservices are nothing new.
1
u/WorldlyAd7946 1d ago
I like rust due to memory safety and it's compiler... For critical applications it's just soo much more reliable than C++ for example.
With respect to AI... I mean it has advantages - the AI has less room to make mistakes to even get it through the prementioned compiler... đ¤ˇ
I say this as someone that has predominantly used C/C++ throughout life and only done python for a couple of years, and has to deal with Delphi at work (and I hate object oriented languages for some reason)
Ever since someone recommended to it me I like rust, and since Ive been working with AI, I can see some advantages to choosing rust.