Is Rust a good AI language?

What do you mean? When I say "natural language" I mean language that humans understand and use. Could be typed text, could be speech, heck could be sign language or morse code. They can all be used to craft the prompts we use today. How do you imagine using AI without communicating with it, in natural language?

The real funny thing: you are not even wrong. At least not what is called “wrong” by normal people.

That phrase may be both “mostly correct” (if you define “mement” as historian would: mere 50 or 100 years) and “dramatically wrong” (if you would look from human perspective, where 50 to 100 years would be comparable to the duration of someone's life)

Industrial Revolution started in the middle of XVIII century. Even Second Industrial Revolution in the end of XIX century. Number of horse-driven carriages fell below number of cars in the middle of 1920th in US and after world war II in many other countries (Poland was, famously, using cavalry in world war II).

Same here. The first e-mail on ARPANET was sent in year 1971 – yet letters were sent and received for decades… in fact there are many things in many countries that are still can only be done via letters, and couldn't be done via e-mail.

Please don't make me laugh so hard. I may crack a rib.

Sure. Closer to the middle of XXI century.

Sure. Today we must keep in mind that something that looks “almost ready to be accepted” is produced by someone who doesn't know what's s/he's doing… and we shouldn't accept code till it's actually good in the hope that you may convince someone to fix it after admission… that was always a very bad idea, AI just made it mandatory to reject code that looks suspictious.

Rust is the short-term future. While vibe-coding is fine for the code that's destined to be thrown away. AI works pretty well for these things.

Just not expect AI to write anything you plan to support for longer than about six months…

What an odd assertion.

If this AI thing is going to be so smart why would it need Rust? Why would it not just use C or assembler or craft executables in binary?

After all that is the long standing argument of C and C++ devs. Many of them claim that bugs and security issues in those languages are "skill issues", that you don't need the safety wheels. of Rust, you only need better programmers.

As it happens I feel far more confident in AI generating Rust than any other language. Because Rust is so fussy about types and lifetimes and such that the AI has a lot less chance of sneaking surprises in there. Sometimes my AI friend has to try many times to get here Rust creations to compile.

AI is not “smart”. That's the problem. As Demis Hassabis (Google DeepMind CEO) puts it: Today's large language models are phenomenal at pattern recognition. But they don't truly understand causality. They don't really know why A leads to B. They just predict the next token based on statistical correlations.

That's why they work beautifully for small snippets, starts striggling with code sizes approaching thousands of lines and the whole thing starts falling apart when you approach millions lines of code.

And because that's inherent limitation of the whole approach we couldn't expect that to be lifted any time soon.

That still doesn't make them useless… just means these proclamations of us stopping writing code are a bit… premature.

We just don't know whether they are 20 years premature or 200 years premature… would only know when reliable, self-correcting, AI would be actually made.

Today AI works with Rust better than with JavaScript or Python because Rust compiler acts as better, more air-tight for the mindless AI beast… but even that cage is not air-tight, it has leaks. When your program grows AI would find a way to make it misbehave.

As deeply amusing as I find the path this conversation has taken, I fear it's no longer even vaguely Rust related. I think once the singularity was mentioned, it was all doomed.

But if AI programming completely replaces the manual writing of code, then who cares what language it uses? I couldn't care less if it wrote in Rust, C, or Turbo Pascal.

I think the comparison to Jai is perhaps the most apt.
Rust had < 2000 stars when it was 1.5 years old I believe.

I don't think there is a large community outide the core developers of the languages (jai and mojo) that use them seriously at this point.

I don't follow mojo closely - install the tool chain every half year to see where they are.
Many breaking changes when I did that in the past - so you have to be very interested in the language itself to use it.

If Modular ran out of funding the language would be dead - but that is not the case.
I think they received 100M+ in funding initially - and have a valuation of ~800M today.

What I mean is, we’re already pretty close to programming by talking to AI just like we chat with ordinary people. AI is like a universal compiler.

I agree with most of your points.

The question is, I guess, how is it substantionally different from using prompts? They are, essentially, just a formulations of the tasks to do - something that we very much do with ordinary people, if we work in a normal team with actually working processes.

Well, first of all it's still a big 'if'. Automobiles had replaced horses, surely, but they still needed drivers - and for the most part need them to this day; likewise, AI may become capable of writing code, but after that it will still need a reviewer who can understand and correct this code.

And second, AI - at least, the kind of AI which is pushed for at this time - is actually prone to the exact same 'skill issues' as humans are, since it doesn't have any kind of strict reasoning to actually prove the correctness of its results. So it will benefit from a safety rails of a language like Rust, just as the living programmers.

Is it really so that current AI is only mediocre at writing Rust as compared to any other mainstream language?

Shamefully I have not written any code for four months now. It started when I noticed the team around me was having trouble debugging the system they have been creating for two years. Or even demonstrating in a clear way to outsiders that it was working. What they needed was some human friendly GUI visualisations that showed when it was doing. And they needed it in a hurry. for some demonstrations coming up.

Not knowing anything about doing graphical/GUI stuff in Rust and having such a short deadline I turned to AI. In no time at all I had four little apps using slint and WGPU that show 2s and 3d data visualisations in real time. They run on Linux, Mac, Windows and in the browser using WASM. They about to some thousands of lines of code.

I have hardly looked at any of that code but what I have seen looks kind of reasonable. None of this is mainstream product for us and I don't expect the need to develop it further. So everything has worked out very well.

Admittedly I have no experience of getting AI. to generate any other language. But from what I follow of things I don't get the impression it's any worse in Rust than any other language.

I think it is a good AI language already. Claude writes good rust code and i use it daily. :robot:

Programming in natural language seems to me like an impossible task. Programming languages reflect computers being deterministic machines that execute a finite set of simple instructions. I'm not sure how natural language which is not very deterministic or finite would map to that.

LLMs are also deterministic—the absurdly large amounts of data involved and the pseudorandomness introduced in the process may appear as if they aren't—and act as a sort of convoluted proxy to the language of your choice.

I believe LLMs in general are being used to accomplish an impossible task and being marketed as an impossible tool. Bigger datasets may result in a closer approximation at the cost of even greater resource consumption. Ultimately, you as a human who can understand computers will always be able to do far better than a computer that appears to understand humans.

That's the trouble with current AI: what it produces is not “correct”, but “is looking kind of reasonable”.

In a dozen of “make it compile patches” that I had to review that were done with AI in last month three (!) were of the sort “this test fails to compile to let's “fix” it by removing some verifications”.

That's what I would expect with a junior developer, too, because it's “looking kind of reasonable” to remove CHECK_EQ from constexpr function (it's C++, not Rust) — except when you know that in our codebase CHECK_EQ was specifically made constexpr-compatible to catch compile-time errors, too.

The big difference: I have to explain that to junior developer once — but have to explain it to AI every time it tries to do that. There are simply no reliable way to change AI's “world model”, for existing AI doesn't have one. You can add such things to the prompt, but then you'll find out that when your prompt is becoming big enough to include enough such “interesting facts” about large enough codebase it also become large enough for AI to start ignores bits and pieces of it.

That's the key thing here: because you can not teach AI anything reliably any code written with AI starts developing more and more small unfixable warts[1] as codebase grows. Slower when your code is very close to what “average code found on internet” looks like, faster if your code is non-trivial, very fast if your code is tricky and does something that not a lot of code on the internet does.

And that leads to crazy phenomenon: when you “try AI” you, naturally, do something that others have already done (to know whether what AI produces is good or not) and AI simply nails it, does everything perfectly. And then you try do something new (because people wouldn't pay you for something that was already done, now, would they?)… and AI starts doing mistakes left and right, it starts corrupting your perfectly valid code… pretty soon the only option is to throw that slop away and write code from scracth.

If you accept the fact that everything that AI ever produces should be thrown away, eventually… you may find surprising amount of one-off tasks that may do with AI. And it works really well.

Just realize that at some point you would either have to actually read and try to understand what AI created, every single line (coz you can not trust any of it)[2]… or be ready to throw away what you have created and start from scracth.

Even with that limitation AI is surprisingly useful… but it's very far from “we would stop writing code by hand, soon”.

P.S. The moment of truth for a lot of people wouldn't be when AI would destroy their codebase, but when people realize that “good models” would bring them bill of about $2000 per month, not $20 that they are paying now. For $2000 per month you may hire perfectly good junior developer in India — and said developer would grow and would become better… while AI would stop becoming better when AI bubble would burst.


  1. Well… unfixable by AI, I mean: human can fix these, but then it's no longer AI-written code, but human-written one — and often it's slower to fix all these warts than to not use AI in the first place. ↩︎

  2. And at this point “AI written code” becomes a technical debt just like any other solution that favors short-term gains in place of long-term supportability. ↩︎

That is a huge assumption :wink:

I see Rust as primarily a systems programming language. I don't think AI is likely to be useful for writing systems programs, at least in the near term. AI doesn't really understand anything, rather it is very good at guessing based on the training data it has been fed.

However Rust can also be used for application programs, and it may be useful in some situations for that.

I also wonder if it may be able to help automate the translation of C++ or C code to Rust code (say). That seems a reasonable possibility, I don't know how much human intervention would be needed.

So no difference to humans.

I beg to differ. What AI produced for me did what I asked it to do and its users are happy with it. Ergo it is correct plus or minus some omissions or ambiguities in what I asked. Which were soon put right with a bit of prompting along. Pretty much what I would get if I put the same requirements to a human programmer.

You could question the quality of the implementation. Is it DRY or is it CLEAN, idiomatic, easy to extend or maintain etc. These are all kind of vague requirements and I'd wager my AI results satisfies them as much as if I'd written the code myself in the time available.

So what is "not correct" in this picture? We are working in Rust here so a quick check that there is no "unsafe" going on removes any worry about a whole class of surprises. It's Rust, it compiles, it works, right? :wink:

You could also question what happens if I were to start scaling up the size and complexity of the things. At what point does everything start turning to shit? Well, I worry about that as well. Except that is not on the table for what I have done so far. Also projects getting tangled in a mess and floundering as they grow is common among human creations as well.

That is the subject of a multi-million dollar DARPA project Translating all C to Rust. also there was some news from Microsoft about a similar research project they have.

I was amazed how well AI translated some of my C code to Rust. Including some gnarly macros. It was not very big mind.

No difference to some humans. The ones who try to pass HR hundreds of times till they are accepted by accident.

Very roughly speaking LLMs are doing what Daniel Kahneman called “System 1” thinking in his book, Thinking, Fast and Slow. And they actually do that better than humans!

But humans are supposed to have also “System 2” thinking, critical thinking, self-doubt thinking.

That's actually what is distinguishing mammals from alligators (and the reason why alligators couldn't be trained while cats or dogs could).

And yes, it's true that there are a lot of humans who don't like to use slow and costly “System 2” thinking.

They are not very good programmers.

That just means that what was “looking kind of reasonable” was also correct… this time. Pat yourself on head and hope you'll get more such happy accidents in the future. Prepare a plan B for the moment when it would stop happening.

Well… LLMs can be used to prove that this joke only works on humans. Poke LLM enough and it would find code that looks correct, compiles… and yet doesn't work.

And because there are no thinking involved it's often easier to simply throw it away and start from scratch, at this point, than try to understand “logic of failure” — because there are no logic, behind all that.

Rust, in that case, works as a substitute for the much needed world model that LLM is intrinsically lacking. And it's pretty good one, better than world model offered by python… but it's still made for human-scale attempts to produce something that's looking well, but doesn't work.

LLMs can find ways to produce code that compiles but doesn't work much faster than humans…

Wrong question. It starts “turning to shit” from the first prompt, from the first line.

Right question: when would you realise it have turned into shit?

And the answer is simple yet distressing: when you would notice it — it would be too late. When AI-written code starting to visibly misbehave it usually have enough hidden flaws that fixing it is more-or-less impossible.

We have all legacy code that falls aparts when you touch it, aren't we? That happens because it contains hidden flaws where world models of different authors contradicted and where the whole thing works because existing usage doesn't hit these corner cases where these contradictions.

Now enter agent that doesn't even have the world model and where the only thing that keeps the whole thing together are few tests (“does it compile” is also a test, here). When would you nortice it's accumulated some problems? When tests wouldn't be sufficient to taper over lack of understanding.

By this time it's much too late to try to save such codebase. It's not even possible to discover flawed but existing logic (like one may do with legacy human code), for there is none.

It has extremely “wide” mind. It's the very definition of “I've forgotten more than you'll ever know” idiom. It's amazing.

And yet it's amazingly destructive, in similar way to how ancient scientist may be amazingly destructive because he still remembers many things but forgets to tie his shoelaces before attempting to run and thus falls and break the leg.

And sometimes it even "fixes" the tests by making the implementation wrong. You really have to be on the lookout and review everything it produces.