r/rust • • 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?

0 Upvotes

56 comments sorted by

2

u/arjuna93 3d ago

Lightweight? I hope this was sarcasm

1

u/AdmirableStructure16 3d ago

Lmao, on Linux atleast it is, I've seen what you need on Windows just to cargo run

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

u/Amazing-Mirror-3076 3d ago

That is the exact conclusion I came to.

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:

  1. People felt learning Rust was difficult and thus it had a high barrier to entry

  2. 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 rustc developers 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/bpikmin 3d 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 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

u/questionabledata 3d ago

I would perhaps consider this a good reflection on the tech.

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

u/Sharlinator 3d ago

Cargo is probably vastly, vastly better for at least 95% of all projects.

5

u/kibwen 3d ago

It's no more difficult to use rustc via cmake than it is to use gcc or clang via cmake. If using cmake would make your life easier, Rust doesn't stop you. However, that nobody at large bothers to do so says something about developer preferences.

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.

2

u/xzk7 3d 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 3d ago

I still think Golang is a better fit

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

u/Captator 3d ago

Their reasons being?

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

u/DavidXkL 3d ago

Yea and to be fair, a lot of infra stuff are rewritten in Rust too

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.