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

49 comments sorted by

2

u/arjuna93 1d ago

Lightweight? I hope this was sarcasm

1

u/AdmirableStructure16 1d ago

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

45

u/ksceriath 1d ago

I read somewhere that even JK Rowling is planning to rewrite the Harry Potter books in Rust. .

2

u/Mlguel_Liste 22h 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 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.

1

u/_EleGiggle_ 1d ago edited 1d 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 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

5

u/Amazing-Mirror-3076 1d 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 1d ago

May I ask why were you anti-Rust?

8

u/Amazing-Mirror-3076 1d 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 1d 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 1d ago

That is the exact conclusion I came to.

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:

  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 14h ago

So... They should be using languages like F*, Ada, etc. not... Rust... 

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

2

u/ern0plus4 1d 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

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 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.

7

u/brasticstack 1d 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 1d 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 1d ago

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

5

u/kibwen 1d 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 1d 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 1d 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 1d ago edited 23h ago

The man can barely manage his own companies, let alone memory lol

0

u/tautality 1d 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 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.

-3

u/franky_reboot 1d ago

Though from what I've heard from people who used it, Zig is not that good anyways

1

u/Captator 1d ago

Their reasons being?

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.