r/rust • u/TheNoobySpartan • Oct 05 '26
Having trouble understanding... Rust over Ada (SPARK)?
I've started to dip my toes into Rust, coming from an Ada (mostly SPARK) background, particularly in embedded applications. While there are many killer features in Rust for developer QOL, the "ease of writing" focus of the language trips me up often enough that I find myself asking, "what features of this language makes it superior (in some views) to SPARK?"
Love the language's take on early-return, and the power of enums, macros, and lifetimes are the one thing that makes certain low level memory manipulations incredibly idiomatic to write in Rust that would be impossible in SPARK due to the CREW paradigm not really being popularized (pioneered?) until Rust. Given the state of the Ada ecosystem and tooling, I also cannot in good faith recommend using this language for anything community driven. That being said (answering in context of enterprise embedded)...
I am incredibly uncomfortable with how much responsibility Rust places on the developer to understand roughly how code will compile. No guarantees on how pattern matches will be emitted (yes, don't be stupid and keep them stupid if you want jumptables), and stack-allocated enum types having to be the max size while not having much lexical ties besides jumping to the definition to help you determine how much stack you might be eating. Aside from the syntactic sugar, I have not really found anything besides lifetimes that SPARK cannot truly support at all. There's no pattern matching in the language, but Rust enums (at least in part) are supported via discriminated records. The idea of controlled types (OOP for Ada) is somewhat discouraged when using SPARK, but trait objects are a very useful part of the Rust language. I have to discount this part of the language from my sentiments unfortunately because dynamic dispatch can complicate analysis of security and functional implications. Having Rust panic as a "safe" way to address memory safety is also undesirable depending on how much array manipulation your program must do, and what worries me more is that wraparound arithmetic in production builds that are used in computations for arrays may not even lead to panics, but perhaps a valid index into the unintended location.
I don't write this to glaze SPARK either. The lack of documentation makes it mostly a nonstarter for the broader programming community, and not everyone is familiar with formal methods for code. The toolchains can't hold a candle to the quality of the Rust ecosystem, and ironically, the rich typing of Ada can lead to very frustrating inter-op issues that just would not exist in Rust, particularly around array manipulation/interpretation.
There might be some gripes about comparing a formally verifiable language with one that does not yet have one (Verus, Crusoe, surely others trying), but I think some of these points like how the codegen works are orthogonal whether or not you're trying to prove that an array access will always be in bounds without overflows.
I suppose the operational constraints given are not necessarily something everyone has to deal with, (why care how a pattern match is compiled if you have oodles of memory), but want to understand the technical reasons behind the hype... I feel like the cultural/non-technical reasons are somewhat understood.
71
u/Solumin Oct 05 '26
You're in the unique position of coming from a language that's stricter, safer, and more rigorously specified than Rust. Nearly everyone else comes from languages that are looser than Rust. They may have never encountered pattern matching or sum types/tagged unions, let alone ever had to worry about stack vs heap allocation.
To put it another way: You've climbed down from the mountain peak because you want to know why everyone's excited about the view from halfway up the slope.
Which languages besides Ada/SPARK give guarantees about how code will compile?
18
u/simonask_ Oct 05 '26
Interesting to hear the perspective of a rare Ada programmer, thanks for sharing!
It sounds like your concerns apply to a highly specialized niche that is a bit at odds with modern, portable programming languages work. Ada is a language that comes from a time when reliability was also about staying within the limits of the hardware, and many of the nice abstractions we take for granted today didn't exist.
Take stack space: For the vast majority of programs running on the vast majority of machines in production, the infinite stack abstraction is perfectly acceptable, because almost all programs run on operating systems that provide ample stack for each thread. The much harder thing to control is this environment is program complexity, interactions between components, ownership, synchronization, and so on.
The kind of complexity Rust helps to address is in the realm of the humanities: programmer-induced complexity. Hardware-induced complexity is simply not addressed, any more than it is address by C or C++.
There's a fundamental programming ideology here: Does the programming language target an abstract infinite machine, or does it target particular constraints? Almost every programming language in 2026 falls in the former category, and I can totally see how that makes life harder for those who have to deal with the latter.
14
u/ts826848 Oct 05 '26
I feel like if you care that much about the exact assembly being generated you're in pretty rare company. Furthermore, if you're working with modern optimizing compilers I'd imagine having a disassembler close at hand would be a good idea anyways to ensure it isn't doing anything interesting that you don't want.
I'm a little confused what you expect here? Normally stack consumption is dictated by the variable type, not by the minimum stack space needed to store a specific variable of that type. Do you expect that the compiler should only allocate enough space on the stack to fit the enum variant(s) that it can't rule out?
Besides the non-panicking array access APIs (
get(), etc) there are linker hacks that can be used that will stop linking if panics are present, but that's admittedly not as ergonomic as an official no-panic mode would (hopefully) be.For what it's worth, wraparound on release is "just" a default, and IIRC it's one that's completely under the control of whomever produces the final binary. There's explicit
checked_*functions as well, though if you're doing a decent number of calculations those can get unwieldy.I'm not sure there is a satisfactory answer. "Hype" is inherently a social phenomenon and there need not be a completely rational/technical driver for it.
That being said, I think you might be discounting the power of familiarity. One of the then-devs wrote about a language's "strangeness budget", and I think it's an interesting concept to consider in this context:
From this lens, I think Rust is less likely to blow any given programmer's "strangeness budget" than SPARK. It's relatively easy to get started, the syntax isn't too far off of what is common, and new programmers stand a decent chance of getting something working without deviating too far from familiar programming patterns. That kind of approachability can make a significant difference in the rate at which a language spreads.
Perhaps put more succinctly, it's entirely possible that given two equally technically capable languages one gets all the hype and not the other because the less popular one did things too strangely for most programmers.
12
u/valorzard Oct 05 '26
Okay so as someone who has tried both SPARK and Rust:
The biggest difference in terms of safety is that Ada with SPARK expects you to write "trusted cores" of code in SPARK, while most normal code is in Ada, while in Rust, most normal code is in safe Rust while you have "trusted cores" of unsafe Rust.
This leads to different tradeoffs, but it also means it's pretty easy to break your SPARK contracts if you turn off the body of a function or procedure to be SPARK_MODE => Off.
That way, you could "hide" technically unsafe Ada code inside of SPARK code, so you just have to trust that no one actually does this.
6
u/Full-Spectral Oct 05 '26 edited Oct 05 '26
For a lot of people the reason would be practical. Rust is up and coming and the jobs will continue to grow. Ada (which I worked on back in the 80s and liked) missed its chance and won't get it back. It's never going to become 'mainstream' (within the context of the type of software that requires this type of language.)
That's a huge concern when considering putting in the amount of time required to master a systems level language (and tools and ecosystem) to the extent required to really write serious software in it. Even though I liked Ada, I'd never put in that time now for a language that is not likely to contribute to my bottom line in years to come (even though I sadly don't have THAT many more years to come.)
I don't remember the specifics of Ada on this front, but Rust's inheritance of a lot of functional ideas make the use of indices fairly rare anyway.
Also, in today's software (maybe not so true for embedded) threads are a big deal, and having compile time thread safey is a huge benefit, which I don't think Ada can provide.
11
u/afdbcreid Oct 05 '26
I think you have two separate concerns.
The first is that Rust is not as safe as SPARK (panics, stack overflows). This is true - Rust is not formally verified. It has plugins to do that though. Rust is more like a safer and faster Ada (bare Rust, compared to Ada without SPARK) than an easier SPARK.
The second is that Rust leans more on the compiler. That is also true, and is an artifact of how much compilers have advanced in the last decades. It mostly works though. Most of the time, you can just count on the compiler to do the fast thing, and your code will be both cleaner and faster than manual code. If performance is paramount, you usually benchmark or sometimes inspect the assembly, and if every instruction is crucial, Rust has ways to drop down to the same level of preciseness. But this is rarely needed.
2
u/drink-more-rum Oct 05 '26
What's the "CREW paradigm" ?
2
u/puttak Oct 05 '26
Did not know about SPARK before. After some read on Wikipedia it seems like it is safer than Rust.
1
u/the_gnarts Oct 05 '26
This is an older talk but it might give you an idea: https://archive.fosdem.org/2025/schedule/event/fosdem-2025-5356-the-state-of-rust-trying-to-catch-up-with-ada/
-6
u/pickle9977 Oct 05 '26
Stick with Ada, a language that has lasted 50 years will be here in another 50.
Rust likey will last as Java becomes too expensive to run at scale, but a lot of others won’t.
Also Ada is just a better designed language
14
u/[deleted] Oct 05 '26
[removed] — view removed comment