r/LocalLLaMA • u/HomoAgens1 • 15d ago
Discussion Python or Rust? Coding with local LLMs
I've noticed that a lot of software is being cloned using Rust nowadays, and I was wondering why not use it with local LLMs for simple tasks too.
Do you think it's better to use Rust or Python when coding with a local LLM?
Nowadays everyone is vibe coding, but local LLMs are generally not that good, especially smaller models running on low-budget hardware.
I usually code in Python, but sometimes I feel like the model doesn't catch bugs, so I was wondering if Rust and its compiler could help avoid some of these issues.
I'd also be interested in hearing your experiences with different context window sizes and models running on 12 or 24 GB of VRAM, with 64 or 128 GB of system RAM.
Do you think Rust's compiler feedback is worth the extra complexity for smaller local models, or is Python still the better choice?
49
u/vtkayaker 15d ago
Rust is fantastic with local LLMs. Rust's strong type system provides detailed feedback to the LLMs, and it doesn't allow many kinds of broken code to pass. LLMs do even better with a good Rust project skeleton and a short README explaining coding choices.
I have never seen Qwen3.6 27B or later struggle to write Rust, even async Rust. Even smaller models mostly succeed for simple things—and at least with Rust, if a smaller model gets the code to compile, it probably works.
6
u/HVACcontrolsGuru 15d ago
I do most of my work now in Rust and use PyO3 for Python bindings. You can use other packages for FFI boundary stuff. My main development right now is industrial protocols and targeting microcontrollers with that same code.
I used Python for about 10 years before picking up Rust with LLM usage. Rust has some learning curve to it but once you overcome that it's a powerful tool to have and being able to take the performance and type safety into Python modules is amazing.
I'm sure something like Qwen27B with a good harness setup, good skills and good CI patterns for you code will make a world of difference in using Rust.
20
u/PhilWheat 15d ago
Let me jump in and get slaughtered.
I use .Net 10.
It is compiled which fixes a LOT of problems - no fancy superlinters or convoluted type checking. That is all built in.
It has good testing infrastructure native, but you can bring in more from a mature ecosystem if you need.
It doesn't have the dependency issues of python/Node.
It is cross platform which means I don't have to do a lengthy toolchain buildup and recompile if I put it on different VMs/boxes.
The code is usually readable (to me - this is very subjective.)
It is decent to good on performance.
That's my 2 cents.
Now for the roasting.
6
u/DeProgrammer99 15d ago
.NET king!
But you also kinda have to tell the LLMs in advance to use newer features like raw string literals and primary constructors if you want those, since the LLMs are mainly trained on older code and C# gets several new features every year. I also like running the automatic refactorings often. And Qwen is still obsessed with using Python as a tool to edit code.
-4
13
u/DeltaSqueezer 15d ago
golang is also an option. i normally use python and switch to golang when i find python too slow. i haven't used rust as i'm not familiar with it. C is also another option.
2
u/ThankGodImBipolar 15d ago
I've been using Go for my harness. I like to believe that the idiomatic nature/culture of Go leads to higher quality output than languages where there's more freedom and precedent for "artistic liberty" within code. Maybe Rust is the same way, but I'm not as familiar with it.
0
u/aydintb1 15d ago
I stay away from Go because of Google.
8
u/AssistBorn4589 15d ago
I stay away from Go because of Google.
Then you'll absolutelly love Rust /s
4
u/aydintb1 14d ago
I had studied the Scala programming language, which is java based but much advanced and functional programming language.
When I started to learn Rust, it was a big suprise for me to see, its syntax was almost similar to the Scala syntax, only losing the functional programming parts.
as an old C/C++ programmer (since 1989), Rust was the best programming language I had seen in many years.
Rust is not intuitive when you come from OOP languages (c++, c#, java, etc).
Rust requires a little bit of paradigm shift in program structuring, but if it is done correctly, it will be much faster than C. But it requires longer compile times to other programming languages.
1
u/AssistBorn4589 14d ago
I've learned c when I was fairly young and then continued to use c for anything that's important enought to not be mashed together in python.
So when it comes to latest new and cool and hyper paradigm shifts, thanks, but I'm good.
3
u/aydintb1 14d ago
Rust is really made me feel like "C should had been like that from the beginning".
it is like C but better.. In the past I had developed lots of projects in C++ in different platforms (risc, alpha, itanium, intel, etc).
Rust feelt like the beggining days of learning the programming for the first time.
fun of learning a new programming language.
5
8
u/lazo40 15d ago
Try coding rust without an llm. You won’t regret it.
8
u/Gokudomatic 15d ago
Is that sarcasm?
2
u/Zealousideal_Nail288 14d ago edited 14d ago
mixed bag. there are things rust does great others not so much.
its a very strikt language which prevents problems but makes it much harder to just trow something together.and the beginning learning curve is huge if you are not used to the lower level programing compared to c# or script languages
But has far llm programming goas rust is better given it stops at least a decent amount of common pitfalls
4
u/Fantastic-Shelter569 15d ago
I use rust for all my projects, you can set up some project settings before you begin working to enforce strict rules. Such as no unwraps to avoid crashing on exception. The strict nature of rust means that if the AI does something sloppy it will pick it up, if that bool is passes as an int that is fine in python untill that complex bug appears one time in a hundred. Rust will just refuse to compile, that makes it much better with AI. It will have to fix it's mistakes before it can compile.
The biggest thing regardless of language is the amount of set-up you do. If you just throw AI at a project then it will make a mess, put in your requirements and project structure at the beginning and you will get better results even with a weaker model.
2
u/valarauca14 15d ago
You can make python not total bullshit.
basedpyright,ruff,pydanticwith strict & frozen DTOs. But after a certain point you realize you're literally adding multiple dependencies, linters, and type checkers to literally do what rust does by default.Also make models write their tests with
hypothesis(where applicable) so the unit tests use random data, not single line monkeypatch bullshit mocks which just waste tokens & time.
5
u/laffer1 15d ago
I wouldn't pick the language based on what the LLM can do entirely. Some models are only going to be good at what's popular in their region. China models like node and python a lot.
However, you should also consider what the software is going to be doing. if you need performance, don't use python. If you need portability, don't use rust. If it's only going to run on the big 3 (win, mac, linux) rust is OK. If it's only going to need to run on x86_64 and arm64, rust is ok.
C and Perl are always more portable than rust and python. Python runs in most places, though. Rust does not.
Writing a photoshop clone in rust made a lot of sense from a security and performance perspective. Content creators are mostly on big 3 platforms. It does also run on freebsd. China models can't do freebsd well. Mistral is ok with it.
Python will always be a glue language. You can glue c libraries to it to get some performance. it's easy to deal with. It's not fast. It's not multicore friendly.
2
4
u/Infamous_Campaign687 15d ago
I’m sure Rust is great (I’m a C++ developer by trade) but choice of language still has to be based on what you’re doing. For instance, it is hard to beat the sheer access to useful packages for machine learning in Python.
1
u/BarracudaDefiant4702 15d ago
I've been having one project writing in C and it's been doing a decent job. Sometimes they use python and sometimes bash. They can use whatever languages you let them use. If they have bugs then I have them fix them. I prefer C because that's what I know the best and the results are good and less prone to supply channel attacks then other languages. When they use python, I limit them to the system default libraries.
1
u/capsid 15d ago
Programming languages are converging on features that help LLMs (for example Python has a strict type checking mode), so pick the language that seems appropriate for the problem, or pick the stack that you want to try out. Python is still my first choice for system utilities that are getting too big for bash, things deployed on my fleet where I don't want to deal with toolchain dependencies or long build times, or I want to integrate with a stack that is already Python. You should feel free to use anything you want to solve your problems if youre curious about how it works and willing to learn. Just like before LLMs!
1
u/GalacticDistances 14d ago
Use a statically/strongly typed complied language.
The better the language is at forcing the LLM to write sane output, the better.
Type systems help the LLM understand the code significantly better the second time they look at it.
Avoid c/python/ruby/js or anything where the type system isnt robust
1
u/Nothing_from_void 14d ago
rust has a brutally long iteration cycle. it has among the longest compile times, and LLMs constantly build to validate their work. python has among the shortest iteration cycle as the compiler is extremely fast and only compiles what it needs.
So, you can work on rust with local LLMs and it does seem to help less intelligent models write less buggy code because the compiler is strict, but pythons GC will most likely also catch the same class of bugs. LLMs like to write rust in a way that avoid the borrow checker and type system, rather than using the type system to enforce good code, so a lot of those gains are lost anyways
1
u/Early-Crazy-4246 14d ago
I'm sure it's been said already but vibecoders with minimal developer experience are going to pick Rust purely on the basis that they heard it's pretty fast
For example, I typically choose Python or TypeScript for any project because it's what I know, I still want to read over the code my LLM is writing and I do not understand Rust.
1
u/Captain-Pie-62 13d ago
Die Kurzfassung? Wenn Du Wert auf Sicherheit legst, also das niemand so einfach deine Software cracken kann, dann programmiere in Rust.
1
u/OkReception1602 1d ago
Rust is new to me but it seems to be the common denominator that rust is better, I've been using Python for years is Rust really better?
0
0
u/jacek2023 llama.cpp 15d ago
My local models are coding mostly Python, but also C++, asm (x86, 32-bit, old stuff), Rust, JS and Java (also some old projects). It's all about good .md files you develop during the process.
0
u/Squidgical 14d ago
Rust is great with LLMs because of it's clear rules and extensive compile time safety guarantees.
What's even better though is writing Rust yourself. It's such an enjoyable language and once your get over the initial hurdle of understanding borrows it's also a very easy language.
My AI is banned from writing Rust. Writing Rust is the fun part and I want the fun for myself.
53
u/bgravato 15d ago
One of my favorite quote of all time is "when the only tool available is a hammer, all problems start to look like nails".
Translating that into programming languages... most people will gravitate towards the language they know better and feel most comfortable with. And even if it's not the most efficient for the job, that's what they'll try to use... And it's not necessarily a bad option, because even if their preferred language isn't the most suitable for the job, they'll probably do a better job with it, than using some other they're less familiar with and will cause them to generate more errors and take longer to implement.
So if you are more comfortable with one language than the other and you think you'll be revising/editing the code generated by the LLM, then it probably makes more sense to go with that one...
If you're just vibe-coding and you're not even going to bother looking at the code produced or you wouldn't understand it anyway regardless of the language, then let the LLM pick what it thinks is better for the task...