3 ms·
I don't know Ada / SPARK, and I've been trying to figure this out. Based on the hallucinations I got from ChatGPT, it seems Ada itself is nowhere near as powerf
by whytevuhuni 1y ago
I don't know Ada / SPARK, and I've been trying to figure this out. Based on the hallucinations I got from ChatGPT, it seems Ada itself is nowhere near as powerful as Rust in safety, while Ada with SPARK disallows some things I was considering to be quite basic, such as shared aliasing of data.
For example, it seems it's not possible to get a sub-string slice reference to an original unbounded string. In rust, a &str -> &str signature is trivial.
So it seems Ada still relies on discipline, while SPARK does not have the zero-cost abstractions that C++ and Rust have.
If that's true (is it?), then I'd definitely choose C++/Rust over Ada any time, since performance is very important to me.
- pjmlp 1y agoLess ChatGPT and more language reference manuals, ChatGPT isn't an ancient oracle knows it all, even though Microsoft's marketing sells it as such. Ada has as much zero cost abstractions as C++ and Rust have, and one of the reasons of Ravenscar is even what to turn off for bare metal deployments, and real time OS deployments.
- anthk 1y agoSeriously, if these people use ChatGPT to seek new knowledge, we are doomed. They are utterly clueless.
- Ygg2 1y agoTo be fair to ChatGPT, trying to find good documentation for Ada +/- Spark hasn't been quite as smooth sailing as trying to find something for C++. > Ada has as much zero cost abstractions as C++ and Rust have. Couldn't find anything about it (see above), but does Ada come with any monomorphization tricks?
- pjmlp 1y agoWhat does that to do with zero cost abstractions as described originally by Bjarne Stroustroup? The way generics are implemented in Ada compilers is implementation specific.
- Ygg2 1y agoHow exactly are you going to implement generics in a way that's: > What you don’t use, you don’t pay for. And further: What you do use, you couldn’t hand code any better. without monomorphizing the generics?
- pjmlp 1y agoBy letting the compilers decide the best way to implement them. Also I find funny this point of view on Ada, given the poor examples WG21 has added into the C++ standard library, that will never be fixed due to never-ending ABI drama.
- Ygg2 1y agoLook. I'm not against Ada. Not my favorite language but definitely huge step in the right direction. With that said. How does: > By letting the compilers decide the best way to implement them. Get you to zero cost generics. What if implementor just says "let them eat memory" and boxes the generic.
- pjmlp 1y agoBy the same way std::regexp gives you zero cost abstractions in handling regular expressions in C++.
- anthk 1y agoFFS, ChatGPT doesn't even has a clue on what is talking about.
- fpoling 1y agoPeople often have no clue either explaining why LLMs are so successful.
- Agingcoder 1y agoBoth Ada and spark have zero costs abstractions, they’re designed to run on embedded platforms. Spark is a different use case from rust - it’s a full prover, and the goal is formal verification, typically in contexts where human life is at stake ( say, you’re writing software for an artificial heart , to take an extreme example ). This comes at the cost of being less flexible, but they’ve been slowly evolving spark so that it can handle increasingly complex cases .
- shakna 1y agoI don't think a single point there is true. Ada has had shared aliases since 1995. Its had zero cost abstractions since before then. Slicing memory from a string is in the intro manual, for example. my_var(2 .. 6) Ada doesn't rely on you to be disciplined. [0] Memory safety comes with SPARK. Its a theorum prover. [0] https://blog.adacore.com/memory-safety-in-ada-and-spark-through-language-features-and-tool-support https://blog.adacore.com/memory-safety-in-ada-and-spark-thro...
- whytevuhuni 1y agoBut doesn't this copy the entirety of that slice? That's not what I meant, I was referring to a shared reference, akin to &str in Rust or std::string_view in C++.
- LegionMammal978 1y agoDoing it normally should create a copy of the value, as far as I can tell. Unless you use it to create a renamed variable or by-reference parameter, the same way you can create references in C++. I think the closest thing to a &str in Ada would be an "access String" or "access constant String", which you would get either from an allocated "String" or from a declared "aliased String". You'd create a subslice with "string(x..y)'Access". Though I'm not sure whether that actually works without explicitly declaring an array of "aliased Character", the Manual is dense (as with C++, it's nearly meaningless unless you already know what it's supposed to mean) and the tutorials generally avoid talking about access objects.
- whytevuhuni 1y agoThank you! I assume 'Access types are not memory-safe, right? Is there a SPARK equivalent which still does not copy (i.e. it only references) that is memory safe? To be more specific, how would one implement something like a "Get_First_Word" or "Trim_Whitespace" without copying?
- LegionMammal978 1y ago
- micronian2 1y agoA few days ago, I had ChatGPT compare Rust and Ada. It tended to penalize Ada for its runtime checks and access values (aka pointers). However, ChatGPT didn't account for the fact that many of Ada's runtime checks would need to be manually implemented by developers in other languages. An Ada compiler, can often optimizes these checks away, knowing where they're genuinely needed and where they can be removed. This often explains why speed comparisons between C and Ada code can be misleading, as they rarely factor in the extra manual effort required to make C code equivalently robust with necessary safety checks. Regarding access values, I listed out some of Ada's various restrictions. Its scope rules prevent referencing objects at deeper levels, objects must be explicitly marked aliased to create an access value to them, and there's far less need for access values (for instance, no pointers are needed to pass parameters by reference). Additionally, Ada offers the ability to dynamically size some objects and reclaim their memory without explicit memory allocation. After I highlighted these details, ChatGPT admitted it had unfairly evaluated Ada, concluding it's a very safe and robust language, albeit using different techniques than Rust.