TLDR, you can do lower level tasks at speeds of plusminus C++ but it comes with a bunch of stuff for memory safety unless you explicity ask (e.g. for C interop) with the "unsafe" keyword. In a time where CVEs drop by the tens, it's become yet more relevant.
makes it much harder to have memory safety issues like use-after-free, double-free, type confusion, out of bounds write, or overflow.
But, you pay with a learning curve that's pretty steep because more stuff is strictly enforced to be verifiably compile-time safe.
It will of course not protect you from CVEs from logic errors.
Also the userbase can be a bit of a cult, think "I use arch btw", that's part of why you hear about it a lot
Because actual rust users don’t really care after a point. We care that it’s memsafe and very fast, or memsafe and can run natively on something, or memsafe and lets you say that you use Rust. If the only reason that you’re choosing Rust is memory safety you’re nuts, because we’ve got a whole planet full of memsafe langs that suck a lot less to work in and are just fine for 90% of what an app/web dev would want to do.
Not only a learning curve, but also to be enforced with rust ideas, rust-only supported architectures and funny experience when linking with another native code :D
Rust doesn't choose where to compile, it fully depends on LLVMs target architecture support. Rust can even compile to 7th generation consoles like PS3 (PPC64 ELF) and Xbox360 (PPC64 COFF/Xenon), tho they are not these targets specific and require a bit of fuckery to actually work. But they work!
What is wrong with macros, it's a very simple way to prevent code duplication, e.g if you are defining a struct with a lot of elements and want to rename the fields with serde, you can generate the definitions with a simple macro, and you can also define more complex macros that actually run code to generate stuff, and aren't just like more powerful C macros (macros by example)
The compiler has some strict enforcement that can even "block" if variable memory allocations can't be determined at compile time (buffer overflow protection?), the full lifecycle of a variable has to be "verifiable" (no use after free or null pointers).
For someone who once had a life altering malloc issue, it pretty much sell the language.
Life altering for me... It was a niche product and the demo (no second chances) to a customer failed because of a memory bug wasn't caught in the tests.
Yeah, except that every major Rust app uses the "unsafe" keyword to bypass those checks. Meanwhile, Fil-C can compile ordinary C code and is memory safe.
If malloc issues are the problem, use a higher level language with garbage collection.
Clean can reach the same spead as C. A lot of functional languages can be compiled. And you can build libraries if you whant. The pureness also alows for drastic obtimalizations that otherwise wouldn't be posible
If you need serious answer it's been like decade people talking about Rust. But it was usually used in some experimental projects, crypto startups and open source projects that try to rewrite something in Rust.
Rust is a programming language that forces memory safety by emposing strict rules on how you can use memory. (Only allowing 1 write access or multiple readers, no mix) It does have an escape hatch with unsafe.
It's especially useful in places where security is important like webbrowsers (where is was created) and operating systems. At those places it's definitely getting traction like on Android and Linux.
At the same time, other people already indicated that they are moving again away from it as it's too restrictive and doing a small change causes huge refactoring to keep the borrow checker happy.
Personally, I think it's a good replacement for C as everything interfaces with C and you can plug in new code in rust with your existing C code. Do you on the other end want to improve your C code gradually, C++ might be the better choice. It's also recommended by many people as replacement for C++, though I don't see that happening as you have to compromise your C++ design to create a C-API in order to interface with Rust. If anything, I expect more from Carbon for that. Though just like C is still around, while C++ is proven to be superior, C++ will stay here with rust, Carbon, Java, C# ... around.
Rust does not have a stable ABI. This is a pretty huge deal when trying to replace C as a huge part of what C does is provide valuable libraries and services to other languages.
If you are idk, Python, you can have your code directly call out to a C library and it'll just work. It can get a bit tricky when you depend on specific versions of a library, but that is a workable problem.
With a Rust library, you could write your Python to successfully pass binary data to it in a format the Rust library understands, RustC updates and suddenly your program stops being compatible with the exact same library version.
The "solution" to this is called "hourglass APIs", where you don't call Rust functions, but C functions implemented in Rust. Which means a lot of the advantages of Rust kind of die when used as a library language because end users of the library still have to deal with simple C constructs. You can't pass a Rust String from Rust to X language, you have to pass a C String.
C++ has a similar problem, but ABI breaking changes are way rarer.
Rust has been growing in popularity since LLMs became more and more mainstream.
Rust can write programs with speeds comparable to C/C++ but it has a bunch of added guardrails that ensures memory safety in compile-time.Thus far Rust was niche because working within those guardrails were really very frustrating and for a programmer, working with C/C++ was a much better developer experience.
Since LLMs write code now and they don't care about developer experience it makes much more sense to use Rust instead of C/C++. You basically have a very strict linter ontop of your low-level code built into the language.
it's mostly that rust is harder to write so the code that's out there is of a higher quality (supposed to be) so whatever the model ingested is of higher quality from the start. ai is a shit in shit out machine.
No, rust is demonstrably a better language for AI to write in
AI code agents run in loops that pass when errors clear. It's test driven development
When a compiler fails on code, that is a failed test
A language like Python, which doesn't do static typing, is worse for AI Agents because you can get a runtime error instead of compile time
So by doing the opposite by adding memory safety to compile time / linter, you prevent AI code that doesn't do proper memory safety (and some other fuck ups). Strict languages are better for AI Agents
For the record, I don't like vibecoding. But I'll at least stay informed about it
Everything you're talking about is language infrastructure and ecosystem. Really, actually, default language infrastructure and default language ecosystem. You can do typechecking in python. You can enforce also, if you want, create poison types which fail at compile time if you use them wrong. The language itself has little to do with this. So saying it's a demonstrably better language is a bit silly. You can set up an environment for just about any language that an AI agent can leverage as well as a default or presumed rust environment.
You can set up that, yes, but it requires more tools and vibe coders to actually know the reasoning for doing it, which — given they are usually not programmers, or don't want to bother reading the code — is unlikely to be done by them
i mean higher quality compared to what you could do in another language to bring in the same features/functionality. at the end of the day the ai is still basically trained on what programmers did up to the moment the training started.
you're not wrong, the ai will go into a sort of feedback loop when writing rust and compiling but the training also is a big part of why it does what it does. the model is not going to be perfect with only training so the test driven developpement style saves its ass on edge cases.
which forces programmers to write better code.. which ends up being higher quality code compared to what you could do to achieve same functionality in another language
You shouldn't let that dissuade you from learning Rust (or any language) if you actually want to learn it. Rust can be neat and does things differently from other languages, so even if you don't end up using it, time spent learning it is not wasted time
It was exploding in popularity before AI. Honestly it may be even more important now as AI is very good at finding security bugs, and ~70% of security bugs are from memory handling, and Rust completely fixes that problem without needing garbage collection like other memory-safe languages.
the compiler does not compile code that would give memory issues in almost all of your code. Furthermore, the type system encourages less lazy design and discourages bad practices. For example, enums in C are just an alias for a number, but in rust they can hold arbitrary values. You can only use those values when matching a variant, and you'll get a compiler error if you forget a variant! Stuff like this makes the language a joy to write, makes refactoring easier, and really gives credence to "if it compiles, it works".
If youre interested in learning i could give some pointers on where to start
with languages like C/C++ you are able to write more performant code, but at the expense of memory safety issues
Rust's goal is to allow you to write code with equal performance to C/C++ (can actually be better due to aliasing guarantees and errors as values) without the risk of memory safety issues
and it's a modern language, so it gets to enjoy the benefit of hindsight, and build in ergonomics like discriminated unions and traits.
I'll start by saying that paying jobs for Rust are slowly increasing but not very common.
Rust is special because it offers memory safety and performance without needing a garbage collector.
One of its biggest features is the borrow checker, which enforces ownership and borrowing rules at compile time. This prevents issues like use after free, dangling pointers, and data races before your program even runs.
For example, Rust won't let you modify a variable while an immutable reference to it is still being used. This prevents unexpected changes to data that another part of your code expects to remain unchanged.
fn main() {
let mut value = 10;
let reference = &value;
value = 20; // Compile error
println!("{reference}");
}
The compiler rejects this because "reference" is still being used when we try to modify "value". It even gives us a very helpful error message:
error[E0506]: cannot assign to `value` because it is borrowed
3 | let reference = &value;
| ------ `value` is borrowed here
4 | value = 20;
| ^^^^^^^^^^ `value` is assigned to here but it was already borrowed
5 | println!("{reference}");
| --------- borrow later used here
A few other things worth mentioning:
Memory safety: Rust uses ownership to manage memory, ensuring resources are properly allocated and released. This eliminates many common manual memory management bugs, such as accidentally freeing memory that's still being used.
Null safety and error handling: Null does not exist in Rust. Instead, Option<T> represents values that may or may not exist, while Result<T, E> handles operations that can succeed or fail. You have to explicitly handle both outcomes, commonly through "match" or the quirky looking syntax if let Some(t) = thing { ... } for Option and if let Ok(t) = thing { ... } for Result.
Concurrency safety: The type system catches many threading and data race issues at compile time. For example, it prevents multiple threads from modifying shared data without proper synchronization. This can occasionally be frustrating when seemingly sound code refuses to compile.
Zero cost abstractions: High level features compile into efficient machine code without unnecessary runtime overhead. You get things like iterators and generics without necessarily paying a performance penalty for using them.
Cargo: Built in tooling for package management, building, testing, and dependency management. Managing dependencies and building projects is generally very straightforward.
Rust definitely has a steep learning curve, particularly around ownership and lifetimes, but I'd argue C++ is a lot more complicated. You start to appreciate just how many things the compiler catches before they ever become problems.
Doing things that appear to be extremely unsafe is what makes C and C++ potentially so fast. C++, Go, Rust, and Java are all about the same speed for simple and safe code. The main difference between them being tailored to different uses.
Not really, having low level abstractions is what makes languages potentially fast, also C++ and Rust ideology are zero-cost abstractions, which very simplified is tradeoff for speed to compile time.
Go in your example, really prefer compile time over perfectly optimized abstractions. Java don't have a lot of low level abstractions.
Also yeah, languages with runtime gonna be slower due to garbage collection and other stuff. It's just happen so, that there aren't that many new languages without runtime, Rust is the last popular one, and C++ is kinda terrible and outdated in many ways. C is good, but don't have that many level abstractions.
Unsafe memory management is kinda low level abstractions, but it's rarely utilized.
Java? Fast???? You must be kidding. Let me remind you that Java isn't native code, it is interpreted by the Java Virtual Machine, which is a beast, plus it's dynamic dispatch which is necessarily slower than static dispatch
It compiles on demand. Simple code will benchmark similarly to C++. The optimizations are different, so it will be a little faster or slower for different tasks. The JIT can inline virtual methods based on live analysis, which is why it's sometimes faster.
it's the resolution of VGA mode 0x13, which was popular for its simplicity: just a flat pixel buffer at 0xA0000 with one byte per pixel as an index into a 256-color palette.
It's indeed not 4:3 (which would've been 320x240) but there was a time when there were non square pixels (which is why Dooms cacodemon looks like a sphere in the sprite, but was designed to appear as an ellipse by the designers and on the screens of the time).
I like graphics programming. Making games in c++ with openGL is a pretty fun inbetween of "CODE THIS FROM SCRATCH" and "I made a game in unity with prefabs :)". It's not too tough to grasp but still requires that you implement things like aabb collision by hand.
Though it was pretty annoying trying to find an audio player library because apparently one of the more popular c++ audio libraries has been not only abandoned but had it's online access points evaporated.
yknow despite having done stuff with SDL3 in the past, I never came across SDL mixer when I was looking up usable audio libraries.
The one I was rec'd by the openGL resource I was looking at was irrKlang whose download page currently reads "Downloads are only available for existing licensees anymore, sorry." for both the regular and pro version, mispelling included.
Personally I ended up using miniaudio since it was only a header and class file and the documentation made enough sense to me at the time.
Having done SDL programming in C and Rust, I would say Rust can get in the way a bit if you're not used to the memory safety. I love graphics programming it's so much fun.
I would argue 1. C doesn’t mean higher performance, in fact for a newbie it might be slower to do things in C for a variety of reasons, 2. Yes you want memory safety. You just do.
That said, C is great for learning, and I would 100% recommend learning it before rust (even though I would nearly always choose rust over C for projects)
1- Give me a single example where C loses in performance compared to other level languages. 2- rust std lib is full of unsafe calls. There are several stuff at kernel, driver level that are not memory-safe by design because ehm performance
Well, ripgrep vs grep. More broadly speaking highly concurrent (multithreading and/or async) applications (which are completely doable in C, but require substantially more work, and thus are discouraged by the language itself). Another example would be highly monomorphised code, such as rust’s iterators, chumsky’s parsers, etc… not strictly speaking impossible to do in C, but allows for a high level of abstraction and code reuse whilst remaining aggressively optimised in practice. C specifically struggles there, especially in the world of data structures, there’s a reason people are still to this day using linked lists for everything… That said I do agree a language like rust has a similar problem with self referential data structures.
2. Rust stdlib is full of unsafe calls because A. It’s built to expose a safe API on top of unsafe constructs (such as the ISA or syscalls or FFI), B because unsafe is not an anti pattern. Many people write unsafe code in rust, it’s not to be avoided like the plague, you just need to be careful.
147
u/Arnold_Rambo 3d ago
I am hearing a lot about rust, what's so special about it?
Is it's demand increasing?
75
u/HumanMan_007 3d ago
Rust is very cool but C is probably a better first language.
13
u/Bemteb 3d ago
320x200 is an interesting screen ratio. Might match the resolution of the monitor shown maybe?
9
u/kutac56 3d ago
Actually watched part of that one to learn how to use SDL for something. Was a pretty good tutorial
9
u/New_Salamander_4592 2d ago
I like graphics programming. Making games in c++ with openGL is a pretty fun inbetween of "CODE THIS FROM SCRATCH" and "I made a game in unity with prefabs :)". It's not too tough to grasp but still requires that you implement things like aabb collision by hand.
Though it was pretty annoying trying to find an audio player library because apparently one of the more popular c++ audio libraries has been not only abandoned but had it's online access points evaporated.
40
u/ilnarildarovuch 3d ago
7
u/dryroast 3d ago
Having done SDL programming in C and Rust, I would say Rust can get in the way a bit if you're not used to the memory safety. I love graphics programming it's so much fun.
7
u/BugFeaturesOnly 3d ago
Me: "I'm gonna build a 3D game engine from scratch in C!"
Also me 4 hours later: Staring proudly at a single red pixel on a black screen
6
u/SeriousPug 3d ago
Sometimes you don’t want memory safety in favour of high speed. That’s what C is for
2
u/Yesterday622 2d ago
Peek and poke? lol
0
u/[deleted] 3d ago
[deleted] — view deleted comment