15 ms·
A comparison of Ada and Rust, using solutions to the Advent of Code
- jonathanstrange 1y agoI'd love to use Ada as my primary static language if it had broader support. It's in my opinion the best compiled language with strong static typing. Although it has gained traction with Alire, it unfortunately doesn't have enough 3rd party support for my needs yet.
- andsoitis 1y agoWhat 3rd party things would you like to see?
- jonathanstrange 1y agoIt's just everything and the kitchen sink, I'm afraid, from a NATS server and client library over cross-platform GUIs including mobile, common file format reading and writing like Excel, Word, and PDF to post-quantum cryptography. I'm unfortunately in the business of Lego-brick software development using well-maintained 3rd-party libraries whenever possible. It's the same with CommonLisp, I love it but in the end I'd have to write too many things on my own to be productive in it. I envy people who can write foundational, self-contained software. It's so elegant.
- etrez 1y agoYou have Alire crates for generating Excel and PDF streams/files. Of course you want everything else ;-).
- init1 1y agoYou can generate bindings using a gcc -c -fdump-ada-spec <header.h>. They typically work well enough without needing additional tweaks but If it's more involved you can ask Claude to make a shell script that generates bindings for whatever C library you wanted to use and it works reasonably well. In my opinion, don't make thick bindings for your C libraries. It just makes it harder to use them. For example I don't really like the OpenGL thick bindings for Ada because using them is so wildly different than the C examples that I can't really figure out how to do what I want to do.
- tgv 1y agoIf you have some time to fool around, try it for Advent of Code. I did last year, and while I'm not going to seriously consider it for my day job, I found it worthwhile.
- yoyohello13 1y agoInteresting that Ada has an open source compiler. For whatever reason when I looked at it years ago I thought it was proprietary compilers only so I never really looked at it again. Maybe I’ll look again now.
- Jtsummers 1y agoGNAT has been around for 30 years. There were some limitations with (one version of?) it due to it being released without the GPL runtime exception, which meant linking against its runtime technically required your programs to also be released under GPL. That hasn't been an issue for a very long time either, though.
- sehugg 1y agoGNAT has been around since the 90s, based on GCC. My university did some work on the compiler and used it for some undergrad courses like real-time programming. IIRC there was an attempt to use Ada for intro to programming courses, but I think they chose Pascal and then eventually C++.
- PaulKeeble 1y agoAda has some really good ideas which its a shame never took off or got used outside of the safety critical community that mostly used it. The ability to make number types that were limited in their range is really useful for certain classes of bugs. Spark Ada was a relatively easy substandard to learn and apply to start to develop software that was SIL 4 compliant. I can't help but feel that we just went through a huge period of growth at all costs and now there is a desire to return, after 30-years of anything goes, to trying to make software that is safer again. Would be nice to start to build languages based on all the safety learnings over the decades to build some better languages, the good ideas keep getting lost in obscure languages and forgotten about.
- Veliladon 1y ago> The ability to make number types that were limited in their range is really useful for certain classes of bugs. Yes! I would kill to get Ada's number range feature in Rust!
- pjmlp 1y agoThat feature is actually from Pascal, and Modula-2, before making its way into Ada. For some strange reason people always relate to Ada for it.
- Veliladon 1y agoFor me it's because I learned Ada in college. 18 year old me couldn't appreciate how beautiful a language it is but in my 40s I finally do.
- awesome_dude 1y ago2000-2005 College was teaching Ada? 2005-2010 my college most interesting (in this direction) language was Haskell. I don't think that there was any other language (like Ada) being taught)
- commandar 1y agoTangentially related, one of the more interesting projects I've seen in the 3D printing space recently is Prunt. It's a printer control board and firmware, with the latter being developed in Ada. https://prunt3d.com/ https://prunt3d.com/ https://github.com/Prunt3D/prunt https://github.com/Prunt3D/prunt It's kind of an esoteric choice, but struck me as "ya know, that's really not a bad fit in concept."
- LiamPowell 1y agoI wrote about some of the reason for choosing it here: https://news.ycombinator.com/item?id=42319962 https://news.ycombinator.com/item?id=42319962
- bigstrat2003 1y agoI found it kind of odd that the author says Rust doesn't support concurrent programming out of the box. He links to another comment which points out you don't need Tokio for async (true enough), but even that aside async isn't the only way to achieve concurrency. Threads are built right into the language, and are easier to use than async. The only time they wouldn't be a good choice is if you anticipate needing to spawn so many threads that it causes resource issues, which very few programs will.
- quietbritishjim 1y ago(Honest question from non Rustacean.) How does the cancellation story differ between threads and async in Rust? Or vs async in other languages? There's no inherent reason they should be different, but in my experience (in C++, Python, C#) cancellation is much better in async then simple threads and blocking calls. It's near impossible to have organised socket shutdown in many languages with blocking calls, assuming a standard read thread + write thread per socket. Often the only reliable way to interrupt a socket thread it's to close the socket, which may not be what you want, and in principle can leave you vulnerable to file handle reuse bugs. Async cancellation is, depending on the language, somewhere between hard but achievable (already an improvement) and fabulous. With Trio [1] you even get the guarantee that non-compared socket operations are either completed or have no effect. Did this work any better in Rust threads / blocking calls? My uneducated understanding is that things are actually worse in async than other languages because there's no way to catch and handle cancellations (unlike e.g. Python which uses exceptions for that). I'm also guessing things are no better in Ada but very happy to hear about that too.
- IshKebab 1y ago> There's no inherent reason they should be different There is... They're totally different things. And yeah Rust thread cancellation is pretty much the same as in any other language - awkward to impossible. That's a fundamental feature of threads though; nothing to do with Rust.
- quietbritishjim 1y ago
- imglorp 1y agoThe author indicates some obvious differences, including the fact that Ada has a formal spec and rust doesn't -- rustc seems to be both in flux as well as the reference implementation. This might matter if you're writing a new compiler or analyzer. But the most obvious difference, and maybe most important to a user, was left unstated: the adoption and ecosystem such as tooling, libraries, and community. Ada may have a storied success history in aerospace and life safety, etc, and it might have an okay standard lib which is fine for AOC problems and maybe embedded bit poking cases in which case it makes sense to compare to Rust. But if you're going to sit down for a real world project, ie distributed system or OS component, interfacing with modern data formats, protocols, IDEs, people, etc is going to influence your choice on day one.
- vollbrecht 1y agoRust has now a donated spec that was provided by Ferrocene. This spec style was influenced by the Ada spec. It is available publicly now on https://rust-lang.github.io/fls/ https://rust-lang.github.io/fls/ . This is part of the effort of Ferrocene to provide a safety certificate compiler. And they are already available now.
- gkbrk 1y agoThis is only meaningful if Rust compiler devs give any guarantees about never breaking the spec and always being able to compile code that adheres to this spec.
- pornel 1y agoBy that criteria there's no meaningful C++ compiler/spec.
- beeflet 1y agoHow so? There are compiler-agnostic C++ specs, and compiler devs try to be compatible with it. What the GP is suggesting is that the rust compiler should be written and then a spec should be codified after the fact (I guess just for fun?).
- Zak 1y agoI found the inclusion of arrays indexed on arbitrary types in the feature table as a benefit of Ada surprising. That sounds like a dictionary type, which is in the standard library of nearly every popular Language. Rust includes two.
- pixelesque 1y agoIt's not a dictionary, that's a totally different data structure. In ADA you can subtype the index type into an array, i.e. constraining the size of the allowed values.
- Jtsummers 1y agoThe Americans with Disabilities Act doesn't cover subtyping the index type into an array. Ada, the language, does though. EDIT: Seems I'm getting downvoted, do people not know that ADA is not the name of the programming language? It's Ada, as in Ada Lovelace, whose name was also not generally SHOUTED as ADA.
- tialaramex 1y agoThere does seem to be a strain of weird language fanatics who insist all programming language names must be shouted, so they'll write RUST and ADA, and presumably JAVA and PYTHON, maybe it's an education thing, maybe they're stuck in an environment with uppercase only like a 1960s FORTRAN programmer ?
- DontchaKnowit 1y agoMaybe who cares?
- msla 1y agoYou, apparently.
- bitwize 1y ago
- deleted 1y ago[deleted]
- Surac 1y agoVery nice text. As i am very sceptical to Rust i apreciate the comarison to a language i know better. I was not aware that there is no formal spec for rust. Isn't that a problem if rustc makes changes?
- usamoi 1y agoIt depends on who you are. For implementers of third-party compilers, researchers of the Rust programming language, and programmers who write unsafe code, this is indeed a problem. It's bad. For the designers of Rust, "no formal specification" allows them to make changes as long as it is not breaking. It's good.
- Surac 1y agoMedical or Miltary often require the software stack/tooling to be certified following certain rules. I know most of this certifications are bogus, but how is that handled with Rust?
- detaro 1y agoFerrocene provides a certified compiler (based on a spec they've written documenting how it behaves) which is usable for many uses cases, but it obviously depends what exactly your specific domain needs.
- steveklabnik 1y agoA few things: 1. There is a spec now, Ferrocene donated theirs, and the project is currently integrating it 2. The team takes backwards compatibility seriously, and uses tests to help ensure the lack of breakage. This includes tests like “compile the code being used by Linux” and “compile most open source Rust projects” to show there’s no regressions.
- SabrinaJewson 1y agoFerrocene is a specification but it’s not a formal specification. [Minirust](https://github.com/minirust/minirust https://github.com/minirust/minirust) is the closest thing we have to a formal spec but it’s very much a work-in-progress.
- jll29 1y agoThis write-up shows that while Ada may have some cultural and type-related disadvantages compared to Rust, Ada seems to generally win the readability contest. What is missing from the comparison is compiler speed - Ada was once seen as a complex language, but that may not be the case if compared against Rust. In any case, thanks for the post, it made me want to try using Ada for a real project.
- init1 1y agoWhat exactly is a "type-related disadvantage"? As far as I'm aware, Ada has a much more expressive type system and not by a hair. By miles. Being able to define custom bounds checked ordinals, being able to index arrays with any enumerable type. Defining custom arithmatic operators for types. adding compile and runtime typechecks to types with pre/post conditions, iteration variants, predicates, etc... Discriminant records. Record representation clauses. I'm not sure what disadvantages exist.
- debugnik 1y agoReferences and lifetimes are where Rust wins over Ada, although I agree that Ada has many other great type features. Access types are unable to express ownership transfer without SPARK (and a sufficiently recent release of gnatprove), and without it the rules for accessibility checks are so complex they're being revamped entirely. And access types can only express lifetimes through lexical scope, which combined with the lack of first-class packages (a la OCaml) means library code just can't define access types with reasonable lifetimes. Also, I appreciate that Rust is memory safe by default and without toying with a dozen pragmas. Ada needs a profile that guarantees that code can't be the source of erroneous execution and constrains bounded errors further.
- johnisgood 1y ago... and formal verification is where Ada / SPARK wins over Rust. I mean, we can go on but I think it quite ends there, as far as safety goes. :D There is a reason for why Ada is used in industries that are mission-critical. > Ada needs a profile that guarantees that code can't be the source of erroneous execution and constrains bounded errors further. Not really, you can just use Ada / SPARK and it is all checked at compile-time. Look for my comments where I mention Ada.
- tialaramex 1y agoIn Case Study 2, near the end it says "if the client may need to know SIDE_LENGTH, then you can add a function to return the value" Which yeah, you can do that but it's a constant so you can also more literally write (in the implementation just like that function): pub const SIDE_LENGTH: usize = ROW_LENGTH;
- EverydayBalloon 1y ago[dead]
- garethrowlands 1y agoOn strings in Ada vs Rust. Ada's design predates Unicode (early 1980s vs 1991), so Ada String is basically char array whereas Rust string is a Unicode text type. This explains why you can index into Ada Strings, which are arrays of bytes, but not into Rust strings, which are UTF8 encoded buffers that should be treated as text. Likely the Rust implementation could have used a byte array here.
- debugnik 1y ago> Ada String is basically char array Worse, the built-in Unicode strings are arrays of Unicode scalars, effectively UTF-32 in the general case. There's no proper way to write UTF-8 string literals AFAIK, you need to convert them from arrays of 8, 16 or 32 bit characters depending on the literal.
- gjadi 1y agoHow is the internal representation an issue? Java string are utf16 internally and it's doesn't matter how you write your code nor what's the targeted format.
- debugnik 1y agoIt's an issue because there's nothing internal about the representation in Ada: They're regular arrays of Character/Wide_Character/Wide_Wide_Character, and string literals have different type depending on the width required to represent it as such. Also, string representations very much matter if you're coding with even the slightest amount of mechanical sympathy.
- tialaramex 1y agoI mean you can index into Rust's strings, it's just that you probably don't want that: "Clown"[2..5] // is "own" Notice that's a range, Rust's string slice type doesn't consider itself just an array (as the Ada type is) and so we can't just provide an integer index, the index is a range of integers to specify where our sub-string should begin and end. If we specify the middle of a Unicode character then the code panics - don't do that. Yes, since AoC always uses ASCII it will typically make sense to use &[u8] (the reference to a slice of bytes) and indeed the str::as_bytes method literally gives you that byte slice if you realise that's what you actually needed.
- ummonk 1y agoI’d disagree that both languages encourage stack-centric programming idioms. Ada encourages static allocation instead.
- foxes 1y agoThe word for types depending on a value is dependent typing. Eg lists of size N, numbers in a range, are all what you call dependent types. Idris - cosmetically looks like haskell, Lean and a bunch of other languages have this feature https://en.wikipedia.org/wiki/Dependent_type https://en.wikipedia.org/wiki/Dependent_type
- MangoToupe 1y ago[flagged]
- deleted 1y ago[deleted]