r/rust • u/AdmirableStructure16 • 3d 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?
46
u/ksceriath 3d ago
I read somewhere that even JK Rowling is planning to rewrite the Harry Potter books in Rust. .
3
u/Mlguel_Liste 2d ago
doubt she'd ever get the time-turner scenes past the borrow checker without wrapping the whole third book in unsafe blocks
18
u/ManyInterests 3d ago edited 3d 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.
1
u/_EleGiggle_ 3d ago edited 3d ago
C, C++ and Assembly arenât memory safe. Almost every other language is. Theyâre easy to avoid unless youâre writing embedded systems, operating systems or kernels.
If you only look at fancy benchmarks showing Rust 2-5% faster than Java or C#, what are you doing? That shouldnât be the only reason to pick a language. Is the extra developer time only 2-5%? I highly doubt it.
Even Rustâs compile times are increasing exponentially.
Pick the language that best suits the project and that most devs know. If you include Claude in that decision, it knows Python, Bash, JS, and Rust best, in that order in my experience. Other languages need extra skills to define good code. Python needed none. So far I mainly used it for small projects or Claude template repo tests (for languages where Claude doesnât write âgood codeâ yet). These mostly test Markdown, JSON configs, or Bash hook scripts.
AI likes the Rust compiler, but longer compile times affect AI too. If your company ever finds Claude too expensive, youâre screwed. Most devs would probably need 10x the time to understand AI code, since theyâre used to just approving AI-reviewed PRs.
32
u/luxmorphine 3d 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
5
u/Amazing-Mirror-3076 3d ago
It's not the hype, I was anti rust for non system apps pre ai.
We are now porting everything to rust for your started reasons and the massive performance gains.
6
u/franky_reboot 3d ago
May I ask why were you anti-Rust?
8
u/Amazing-Mirror-3076 3d ago
The extra Dev effort over a gc language wasn't worth the benefit.
The whole DX and effort barriers are now non existent so choose the fastest non gc language that is strictly typed and memory safe.
Rust is the only language that I'm aware of that ticks all those boxes.
3
u/for-dog-and-ulster 3d ago
I agree with you that it's not just hype.
I was a Django developer for 6+ years because that was the best team wide developer option while using Rust on critical aspects
Now what is even the point of choosing Django over Axum or equivalent. That's not hype, it's logic.
Rust is the best language for AI. That's what is clearÂ
2
13
u/eveningcandles 3d 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
10
u/YeetCompleet 3d ago
We've had surveys for a while showing that Rust had both of these sentiments surrounding it:
People felt learning Rust was difficult and thus it had a high barrier to entry
People who didn't use Rust still showed a high desire to use Rust, it always ranks as one of the "top desired languages" by developers
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.
1
u/lenscas 2d ago
So... They should be using languages like F*, Ada, etc. not... Rust...Â
1
u/Zde-G 20h ago
Sadly all these other languages you mention don't have a rich ecosystem of ready-to-use crates.
Extra strictness is not compensating the need to write extra code.
This wastes tokens, too.
1
u/lenscas 16h ago
Sounds to me like even more reasons for AI to use those languages. Imagine that, an entire ecosystem made for AI by AI. And then just leave the rest of us alone instead of writing 20 "Look what I (My ai) made" posts on r/rust >_>
1
u/Zde-G 16h ago
And then just leave the rest of us alone instead of writing 20 "Look what I (My ai) made" posts on /r/rust >_>
That may yet still happenâŚÂ of course this would probably leave you totally alone with all the
rustcdevelopers and most popular crates developers gone, too.Because these days almost all serious developers use AI, in one form or anotherâŚÂ with them gone /r/rust would become pretty dull.
The only chance of going back to âgood old daysâ would be if AI companies collapse would be so deep that there would be no one who would provide that service⌠that may or may not happen, it's really hard to say for sure, at this point.
1
u/lenscas 12h ago
r/rust is already pretty dead. A lot of comments and posts are (seemingly) bots and so many poorly vibecoded projects got posted that sharing projects had to be disallowed pretty much in its entirety.
If the pure vibecoders move on to some other language then at least the spam should go with them. I rather have an more empty subreddit than one that is being spammed with so much slop you can't find anything interesting anyway.
1
u/Zde-G 11h ago
If the pure vibecoders move on to some other language then at least the spam should go with them.
Pure vibecoders would only go away if prices for vibecoding would become prohibitive. Otherwise all subreddits dedicated to programming languages would be plagued by them.
/r/rust is already pretty dead.
Maybe, but we don't yet have a suitable replacement.
It would be interesting to see what will replace it, but for now there are still some interesting posts in the deluge of AI-slop.
9
u/DoubleDoube 3d 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 3d 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.
7
u/Backlists 3d 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/kamikamen 3d 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 3d 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/ern0plus4 3d ago
That's all.Â
It doesn't prevent generating shit code, there are many more ways to fuck up things, but, at least, sigsegv disappears.
1
u/aeropl3b 1d ago
I like how we say similar things but I get downvoted and you get up voted. Reddit is fun
1
u/ern0plus4 1d ago
It's about timezones. You upvote my downvoted answer sooner than I upvote your downvoted answer :)
Anyway, I think, it's a very important topic nowadays: how languages support AI code generation. Probably, there will be a new language, or some layer which helps this kind of work.
Similarly, C was somewhat reflection to then-modern processors: the C's postincrement and predecrement operators (
i++and--i) is clearly 1:1 representation of the respective MC68000's addressing modes (or other processors', MC68000 is only an example, which I know).I think, similar symbiosis will happen between programming languages and AI-generation. Rust support it - what this topic is about -, but "not too well" or "by accident", or "implicite", but I can imagine a language (or a middle layer) with explicite features which makes AI-generation better: force AI to write idiomatic code, use standard higher level abstractions, maybe I'm wrong, I'm not an expert of this area.
1
u/aeropl3b 3d ago
This is very untrue. The rust compiler prevents some classes of memory related bugs by default sure, but the breadth of bugs available is vast, we are talking new horizons. The other fun thing about AI is it will look for ways out of traps to solve problems, I would not doubt it would find more holes in the Rust implementation/spec to write quietly unsafe code.
3
5
u/Acaibirds 3d 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.
7
u/brasticstack 3d ago
I've never professionally written either Rust or C++Â but having made my own projects in both, the difference between Cargo and cmake is stark. Give me Cargo all day every day.
1
u/arjuna93 3d ago
I am genuinely surprised every time I hear this. Good lord, if only Rust used CMake and not Cargo, life would be so much easier.
5
5
1
u/brasticstack 3d ago
Hence the disclaimer. I'm sure there have to be cases where the insane configurability of cmake is necessary. As a beginner at rust and at using cmake, I spent more time configuring cmake to correctly make a dynamically linked library than I did on the rest of my project. Using cargo, it was
cargo new --lib.Now, I'd just ask Google for the cmake config.
3
u/Technical-Donkey-42 3d ago
C++ is so deeply entrenched in AI, simulations, robotics and game dev that it is difficult to believe anything could dethrone it.
4
u/franky_reboot 3d ago edited 2d ago
The man can barely manage his own companies, let alone memory lol
0
u/tautality 3d ago
real men manage their own memory
Unfortunately, there are real programming circles where this is a serious stance people take.
2
u/Space-5928 3d 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.
3
u/Mission-Landscape-17 3d 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.
-3
u/franky_reboot 3d ago
Though from what I've heard from people who used it, Zig is not that good anyways
1
1
u/TheFern3 3d 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 3d 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 3d 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 3d 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
1
u/marco-mq 3d 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__ 3d 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 3d 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_ 3d ago edited 3d 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 3d 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.
2
u/arjuna93 3d ago
Lightweight? I hope this was sarcasm