[HN Gopher] The state of Rust trying to catch up with Ada [video]
___________________________________________________________________
The state of Rust trying to catch up with Ada [video]
Author : pjmlp
Score : 155 points
Date : 2025-02-10 08:30 UTC (14 hours ago)
(HTM) web link (fosdem.org)
(TXT) w3m dump (fosdem.org)
| skirge wrote:
| why Ada didn't take the world? It was literally first programming
| language taught at university.
| jdougan wrote:
| > It was literally first programming language taught at
| university.
|
| Do you mean "It was literally first programming language I was
| taught at university."? because the first language ever taught
| was more likely to be one of the autocoder/assembly variants,
| or FORTRAN.
| mkl wrote:
| Agreed. My mum learned basic Fortran at university in the
| early 1970s, before Ada existed. (It was done on punch cards,
| and they had to wait a day or so to find out if their
| programs worked!)
| tialaramex wrote:
| "First language" is generally taken as a term of art in this
| sector. It is the first language we're teaching students who
| we expect to learn other languages as well, so emphasis on
| "first" here unlike for say a "taster" course in another
| discipline where you're learning only say, Python, with no
| expectation you will ever learn other languages.
|
| Edited to expand: For a First Language you can choose to pick
| a language that you don't expect your students will actually
| end up using, for pedagogic reasons, just as we might spend
| time proving fundamental things in Mathematics even though
| those are already proved and you'll never do that "in real
| life" after studying, a language which has good properties
| for _learning about programming_ is not necessarily also the
| right language to actually write yet another web site,
| database front end, AI chat bot and video streaming service.
|
| I've spent considerable time thinking about this and I
| believe Oxford and Cambridge were right to choose an ML as
| First Language. The MLs have desirable properties for
| teaching, even if you expect your students to end up writing
| Python or C++ after they graduate. I am entirely certain that
| my exposure to an ML at University made it _much_ easier to
| pick up Rust than it was for people whose nearest previous
| languages were C and C++
| Tor3 wrote:
| It's indeed hard to imagine that the first programming
| language taught at any university would be Ada. That would at
| least mean that the university started teaching programming
| and computer science very late. There's been a number of main
| programming languages taught over the years. Back in the late
| seventies/early eighties, some universities in my region used
| Simula in their programming courses, for example.
| EuAndreh wrote:
| There are many other factors that influence language popularity
| besides technical quality, like: - marketing;
| - big companies using it; - familiarity; - history
| of the creators; - history of the influencing languages;
| - timing; - luck; - regional usage; - etc.
|
| Despite some programmers seeing themselves as fully rational
| making cold decisions, we're like everyone else.
| the_duke wrote:
| > - marketing; - big companies using it;
|
| These are the deciding factors.
|
| If you look at which newish languages have gotten popular
| over the last few years, it was Rust, Kotlin, Swift, Go and
| Typescript.
|
| Building a language and ecosystem around it takes a huge
| amount of resources, and often tedious work that doesn't
| happen if people aren't paid for it.
|
| The street cred of "hey, large company X is using it, it must
| be good" is also very important.
|
| (of course Swift and Kotlin are somewhat distinct as the
| platform languages for Android and iOS)
| Taikonerd wrote:
| > _The street cred of "hey, large company X is using it, it
| must be good" is also very important._
|
| Yes, and also, "large company X is spending lots of money
| on it, so they aren't just going to abandon it once it's no
| longer the newest, coolest thing."
| ajdude wrote:
| I think with the recent flurry of languages focusing on safety,
| Ada has been making a comeback (see: ada-lang.io, getada.dev,
| alire, etc).
|
| This presentation in particular was in the Ada dev room at
| FOSDEM (I gave a presentation in that room as well), and there
| were over 100 people there; we actually ran out of seats in the
| auditorium.
| regularfry wrote:
| FOSDEM was packed overall. I can't think of a subject track I
| went to that had spare seats. I noped out of more than one
| because I just couldn't get in.
| Yoric wrote:
| I gave a presentation in the Quantum Computing track and I
| couldn't sit down to attend the other presentations :/
| kreetx wrote:
| There were _a few_ where you could get a spot when arriving
| late, but, indeed, it was pretty packed overall.
| pjmlp wrote:
| Rule number one of FOSDEM, track what you want to see, seat
| close to the door, and always miss the last five minutes of
| a talk.
| wiz21c wrote:
| Because ADA is maintained by big actors who think ADA is for
| "mission critical" stuff and not our lowly web apps.
|
| Problem is, web is the new BASIC and many devs will start there
| and they will see rust first. And where's that ADA game engine
| ?
|
| ADA can definitely claim tons of successes and very powerful
| constructs, but mindhsare is clearly not one of its selling
| points.
| Lucretia9 wrote:
| c is the new BASIC.
| throwaway314155 wrote:
| With respect, Rust isn't a great choice for web either. At
| least, not for web _sites_. I would still argue it's not very
| good for 90% backend API development either, but that depends
| on what's being done in the backend.
| 59nadir wrote:
| Rust is a bad choice for web and a meh/bad one for game
| development. It's certainly not good enough at either to have
| much of a technical edge over Ada.
| conaclos wrote:
| At my engineering school they taught Ada. I never had the
| opportunity to learn Ada because they switched to Java a decade
| before I started.
| AndrewDavis wrote:
| My university had a model train set, hooked up to some
| ancient 386 machines (and we're talking late 2010s here) and
| it was used for a real time programming course which was
| taught in Ada.
|
| Unfortunately the lecturer that ran the unit retired the year
| I started my degree and by the time I had the prereqs
| required to do the course the faculty had run the course once
| without the original lecturer and it was apparently a
| disaster so they canned the unit until it could be rewritten
| from scratch, sans train set ... and in Java.
|
| I still think about missing out on programming a train set.
| Years later
| thoroughburro wrote:
| Sounds like finally satisfying that desire could be a fun
| Christmas project.
| tialaramex wrote:
| The university where I work used to teach Hard Real Time to
| electronics students with toy elevators. When (not if) you
| screw up your elevator smashes into the roof of the
| elevator tower and self-destructs the toy, reminding you
| that this is serious business and if you fuck up that badly
| in real life you'll be lucky if the victims live to sue
| you...
| karlding wrote:
| The University of Waterloo has a similar course, CS452:
| Real-time Programming.
|
| It's not quite the same as having physical access to the
| train set, but a student eventually wrote a simulator for
| the Marklin train set [0]. Another student wrote an
| emulator for the TS-7200 used for the class [1] if you
| don't want to test your kernel in QEMU.
|
| [0] https://github.com/Martin1994/MarklinSim
|
| [1] https://github.com/daniel5151/ts7200
| fransje26 wrote:
| > I still think about missing out on programming a train
| set. Years later
|
| Sounds like a nice hobby project to indulge in during your
| free time! It's easier than it has ever been, and it's a
| nice rabbit hole do dive into.
|
| They even have open-source DCC decoders nowadays!
|
| https://www.opendcc.de/elektronik/opendecoder/opendecoder_e
| ....
|
| https://ilabs.se/news/introducing-our-new-open-source-dcc-
| de...
| a-french-anon wrote:
| It hurts my eyes (more seriously, the Pascal family look lost
| vs the C one, it's a popularity thing) and from my
| understanding, it took too long to become truly usable in the
| FOSS world (a bit like CL).
| kevlar700 wrote:
| Better to hurt your eyes (which is nonsense unless a book
| hurts your eyes) than your brain. Optimised for the common
| operation of reading.
| lproven wrote:
| > It hurts my eyes
|
| This is a common complaint I read, and I have never
| understood it.
|
| My eyes are not strong: I wear spectacles of about -6.5
| dioptres.
|
| If text size is fairly small, it is _REALLY difficult_ to
| distinguish
|
| (...)
|
| from
|
| {...}
|
| ... on large screensful of text. And
|
| [...]
|
| ... is not much more visible. Making that significant is
| terse, yes, but Sendmail is terse. Terseness is not an
| unambiguous virtue.
|
| Secondly, indentation: I learned 2 or 3 languages in the
| 1980s before I learned C, and it's a given that you indent
| opening and closing control structures to match. That's how
| it works: you structure blocks of code to show the
| hierarchies.
|
| But most curly-bracket language coders have their own weird
| schemes where the opening { is in a totally different column
| from the closing }. And they fight like alley cats about it.
|
| https://en.wikipedia.org/wiki/Indentation_style
|
| _ONLY_ the GNU style listed there is sane.
|
| I mean at least Allman and Horstmann styles are consistent.
|
| It is much _MUCH_ easier to pick out
|
| BEGIN ... stuff...
|
| END
|
| ... than it is to try to pick out { and } in some random
| blasted column.
|
| And yet, all the fans squee at curly brackets. As smdiehl
| wisely said:
|
| << C syntax is magical programmer catnip. You sprinkle it on
| anything and it suddenly becomes "practical" and "readable".
| >>
|
| https://x.com/smdiehl/status/855827759872045056
|
| I never got it. It's obfuscatory. It is famed for being
| write-only. There's a competition to write the least-readable
| C!
|
| _C style hurts my eyes._
|
| Pascal and Ada are vastly more readable.
| secondcoming wrote:
| Indentation is readability thing. Curly braces are about
| scope.
| zozbot234 wrote:
| If curly braces are not visible enough, you can also use <%
| %>. Still less of an eyesore than BEGIN and END.
| masfuerte wrote:
| What language is that?
| zozbot234 wrote:
| It's just C/C++ syntax.
| masfuerte wrote:
| Thanks. I was aware of the trigraphs but the digraphs had
| passed me by.
| pjmlp wrote:
| Mostly,
|
| - Compiler prices
|
| - The few UNIX vendors that supported it like Sun, it was extra
| on top of C and C++ compilers, why pay more when C and C++ were
| already in the box
|
| - Hardware requirements
|
| Still, there are around 7 Ada vendors around.
|
| https://www.adacore.com/
|
| https://www.ghs.com/products/ada_optimizing_compilers.html
|
| https://www.ptc.com/en/products/developer-tools/apexada
|
| https://www.ddci.com/products_score/
|
| http://www.irvine.com/tech.html
|
| http://www.ocsystems.com/w/index.php/OCS:PowerAda
|
| http://www.rrsoftware.com/html/prodinf/janus95/j-ada95.htm
| DoingIsLearning wrote:
| The vendor list is really telling of the issues with Ada's
| adoption:
|
| - Of my quick scan, only AdaCore supports Ada 2012 (where a
| lot of the really good stuff is implemented) the rest are
| stuck on Ada 95.
|
| - None of the vendors seem to list transparent pricing.
|
| If you are only selling based on volume and through a sales
| rep then you are off the bat excluding most startups, SMEs,
| and just general bootstrap curious folks.
| pjmlp wrote:
| It works for plenty of other products, but yeah I do conced
| it could be better.
|
| There are at least two more supporting Ada 2012, if you go
| into their docs.
| BSDobelix wrote:
| The Community version (based on GNAT from the FSF) is free:
|
| https://www.adacore.com/community
|
| https://alire.ada.dev/
|
| But yes GNAT "just" supports Ada 2012, 2005, 95 and 83:
|
| https://en.wikipedia.org/wiki/GNAT
| ajdude wrote:
| You forgot Ada 2022 :)
| https://learn.adacore.com/courses/whats-new-in-
| ada-2022/inde...
|
| Adacore technically retired the Community version a few
| years ago, so the most up-to-date free version would be
| GNAT from FSF (which is what Alire brings in
| automatically with `alr toolchains --select`).
| pjmlp wrote:
| Going forward there is only one GNAT, and is under Apache
| 2 license, also a FOSDEM talk this year.
|
| Just clarifying for other folks.
| exitcode0000 wrote:
| Ada 2022 has some amazing features too - like user
| defined literals. You can now create custom string types
| : )
|
| https://learn.adacore.com/courses/whats-new-in-
| ada-2022/chap...
| kevlar700 wrote:
| Predicates are great but most of the good stuff including
| privacy, proper subtyping and abstract data types came with
| Ada 83. Rust can't hold a candle even to Ada 83 imo.
| oneplane wrote:
| Ada has practically no mindshare, Rust does. Just like
| say, Scala, things can be technically 'good', but without
| adoption it isn't going to get the attention and
| visibility to compete with everything that does.
| pjmlp wrote:
| Enough mindshare to keep 7 compiler vendors in business.
|
| How many would pay for a Rust compiler?
| LiamPowell wrote:
| I agree there's probably far more commercial support than
| Rust, but:
|
| - Ada is only a small part of what Green Hills offers.
|
| - PTC mostly isn't even a development tools company,
| their main products are PLM and CAD (WindChill and Creo).
|
| - I think RR is a one-man company.
| touisteur wrote:
| PTC still maintain PERC (for some definition of
| 'maintain'). At least I hope so.
| firesteelrain wrote:
| AdaCore does support Ada 95 and this was 7 years ago.
| Lucretia9 wrote:
| If the price is not on the website, you can't afford it.
| Lucretia9 wrote:
| Your first point cancels out your fourth.
| krashidov wrote:
| I don't know shit about law, but I'm assuming it's not
| allowed for someone to build their own compiler and make
| their own business out of the Ada programming language?
| touisteur wrote:
| Why would you assume that ?
| krashidov wrote:
| because I know nothing about the way licensing about
| programming languages work lol
| touisteur wrote:
| I don't think there's anything preventing anyone to sell
| an Ada compiler, tooling. It's an ISO standard and you
| can read its spec (the holy Ada Reference Manual) and
| rationale for free.
|
| I'd say the biggest hurdle is that Ada is a very complex
| language to implement. I've been writing Ada for more
| than 20 years, and writing static analysis tools for 5
| years with libadalang (an _amazing_ toolbox...) now and I
| still find it hard to grasp the whole combinatrics of
| features.
|
| Easy to use, but very hard to implement.
| Jtsummers wrote:
| The specification is open, if you want to make your own
| implementation you can.
| krashidov wrote:
| This sounds like a fun business to start
| kevlar700 wrote:
| I think Ada is seen as some esteemed language that only the
| military and space would have the expertise to use. I had that
| opinion for maybe a decade but it was very wrong. The other
| issue was that it is so powerful that compilers had bugs and by
| the time an affordable open source compiler came along I guess
| C++ was gaining libraries and the militaries don't release
| libraries.
|
| The ironic thing is that Ada was designed to be cost effective
| over a projects lifetime. C costs you a lot further down the
| line.
| pjmlp wrote:
| One of the reasons of the whole safety hype going on, is that
| companies have finally start mapping developer salaries,
| devops and infra costs, to fixing all those CVEs.
| aaronmdjones wrote:
| > I think Ada is seen as some esteemed language that only the
| military and space would have the expertise to use.
|
| I know Boeing is technically a space company these days, but
| they weren't when they created the 777. Several of its
| systems are written in Ada, including the cockpit interfaces,
| electrical generator systems, and primary flight computers.
| Maken wrote:
| Unix came with a C compiler and its own source code, that could
| be easily bootstrapped and ported to other architectures. You
| cannot beat that.
| froh wrote:
| "first mover advantage" of those who later won?
|
| ADA was way ahead of its time, thus compilers were slow and
| ressource (RAM) hungry, and worse: they were inaccessible for
| hobbyists or learners.
|
| In contrast, pascal/turbo pascal was ubiquitous, and then turbo
| c++. You easily knew someone who could organize a copy and
| "keys" for it.
| dathinab wrote:
| besides all the reasons others listed:
|
| - "the common dev" isn't familiar with it
|
| as well the hen/egg (half) problem of
|
| - if most users are "specialists" then you don't need
| compiler/tooling/doc with very good UX for non specialists, but
| until you have very neat UX even for non specialists you will
| not get a lot of traction with non specialists and in turn it
| might seem pointless to fix the UX
|
| I say half problem because in my experience fixing it is also
| beneficial for "specialists".
|
| This problem also overlaps with perceived (and sometimes
| actual) gate keeping and/or elitism.
|
| Basically the same reasons why e.g. Haskell is much less widely
| used then it could be (and why most usage is in companies
| mostly filled up with people from Universities which have it as
| a required (or strongly recommended) course.
|
| Just with more issues (listed in some of the other responses)
| added on top of it.
| estebank wrote:
| > I say half problem because in my experience fixing it is
| also beneficial for "specialists".
|
| This is critical. Once I realized that even experts didn't
| necessarily have homogeneous advanced knowledge of the
| _entire_ language, it became easier to justify to myself
| spending time on improving the diagnostics of uncommon errors
| for clarity and learnability. An expert requires less
| explanation, but they still require one.
|
| And I also suspect that spending time on better DX at the
| right time of the adoption curve has an outsized impact on
| it.
|
| The bad part is that it is a hard, slow, endless and somewhat
| thankless job (you're going against the grain of the compiler
| design half the time, adding logic that needs to be
| maintained, and for every case you handle ten more pop up
| elsewhere that need to be handled in a different way).
| guerby wrote:
| Many factors but one is interesting: the existence of a public
| test suite, ACATS http://www.ada-auth.org/acats.html
|
| This is a good thing to have a test suite for a language but
| from a business perspective it increases barrier to entry, why?
| 1/ you start your new compiler with 10000 bugs (the failing
| tests in the public test suite) 2/ you get no client since
| clients want a compiler passing the public test suite 3/ no
| client means no money and this until you fix the 10000 bugs.
|
| With programming languages that do not have a credible public
| test suite you can get away with shipping the compiler ASAP and
| get money from customers, then concentrate on fixing customer
| impacting bugs.
|
| All in all a blessing and a curse, life is full of compromises
| :)
| tialaramex wrote:
| Oh! It's about Pattern Types!
|
| I want Pattern Types for an entirely selfish reason, I want to
| write BalancedI8 and similar types -- as user defined types, but
| in stable Rust and have them Just Work(tm).
|
| BalancedI8 is similar to i8 (an 8-bit signed integer) and to
| NonZeroI8 (the same type but, with a niche where zero should be),
| instead of removing zero, which we often have a use for, lets
| remove the annoying most negative value i8::MIN
|
| Why "BalancedI8"? Because now that we've removed this most
| negative number (to provide a niche) the remaining value is
| symmetrical, it goes from -127 to +127
|
| Now, I profess that I want these types but I clearly don't want
| them enough to _do_ very much about it, so that 's not great.
| Yoric wrote:
| Having pattern types would be great!
| auggierose wrote:
| What are pattern types? Cannot watch the video, too slow.
|
| Edit: Thanks for the explanations. From what I see, pattern
| types are subtypes of a given type, such that the subtype
| predicate can be specified as a pattern match. This way,
| pattern types are subtypes that can be checked at compile time
| (at least, if the used pattern can be checked at compile time,
| I don't know if all Rust patterns are compile-time checked).
| amelius wrote:
| The term "pattern type" is more or less invented by Rust. See
| this old comment, and the first reply in particular:
|
| https://news.ycombinator.com/item?id=39570633
| kreco wrote:
| And from what I get it's basically the same idea as Ada's
| "subtyping"[0]. subtype Rainbow is
| Color range Red .. Blue; subtype Small_Int is
| Integer range -10 .. 10;
|
| [0] https://www.adaic.org/resources/add_content/standards/0
| 5rm/h...
| hackyhacky wrote:
| We could do that in Turbo Pascal, 35 years ago.
|
| To be honest, it wasn't particularly useful, because it
| requires runtime checks which panic if they fail.
|
| What is their practical use in the modern age?
| ajdude wrote:
| With Ada/SPARK (and hopefully Rust) this can be checked
| at compile time to formally prove code. You can also
| catch the runtime exceptions and handle them accordingly
| if you're not using SPARK.
|
| The presentation right before the Rust one[1] actually
| did a bit of a dive into this.
|
| I recently created a UUID library in Ada, and I'm able to
| validate an input string on the datatype level without
| ever having to worry about doing so in the function
| itself: subtype UUID_String is String (1
| .. 36) with Dynamic_Predicate =>
| (for all I in UUID_String'First .. UUID_String'Last =>
| (case I is when 9 | 14 | 19 | 24 =>
| (UUID_String (I) = '-'), when others
| => (UUID_String (I) in '0' .. '9' |
| 'A' .. 'F' | 'a' .. 'f')));
|
| Now my function simply needs to be:
| function From_String (From : UUID_String) return UUID
| with Pre => From in UUID_String;
|
| And I can code the function with the confidence that it
| won't be processing a malformed string.
|
| [1] I don't think the video is ready yet, but you can
| view the slides here: https://fosdem.org/2025/events/atta
| chments/fosdem-2025-4879-...
| tialaramex wrote:
| In Rust the bit patterns which are not occupied by a
| value are free for some other use, Rust calls this a
| "niche" and uses it extensively in its sum types.
|
| This lets us have all the performance advantages of using
| magic sentinel values occupying those bit pattern, but
| with the same ergonomics as for an ordinary sum type.
|
| For example in C a Unix file descriptor is just an
| integer. 0, 100, 1000 - all perfectly reasonable file
| descriptors. But, -1 is not a valid file descriptor, so
| Rust's OwnedFd is internally just an ordinary C-style
| integer, except, it's never -1 as a result Rust's
| Option<OwnedFd> is the same _size_ as the C integer, you
| 'll get the same _machine code_ as the C integer, but in
| C you need to remember to check it 's not -1 before using
| it, in Rust you won't make that mistake because that's
| not Some(fd) that's None.
|
| Rust does this with its references, Option<&T> is the
| same size as &T, depending on what exactly T is that's
| probably "really" a machine address in a CPU register,
| and so None is the same CPU register with an all-zeroes
| bit representation.
|
| My favourite _non-standard library_ use of this feature
| is CompactString. CompactString is the SSO (Small String
| Optimisation) made famous in C++ but applied to Rust 's
| strings. Rust's native String type is as simple as
| possible, thus no SSO, it's actually internally Vec<u8>
| plus rules to ensure it is always UTF-8 encoded text. SSO
| in C++ standard libraries means that "Dog" or "Cheese"
| are stored inline in the type itself, no need for a heap
| allocation. CompactString takes that to an _extreme_.
| While a typical C++ std::string might allow you to store
| "ycombinator.com" inside the 32 byte data structure,
| CompactString fits "https://ycombinator.com/" in its just
| 24 bytes!
|
| It does this by being able to distinguish whether that
| last byte is a valid final UTF-8 code unit, if it is then
| this is a 24 byte string, but if it's not then it signals
| how long the rest of the string is and how the other 23
| bytes should be interpreted.
| kccqzy wrote:
| Minor correction about C++ SSO: different C++
| implementations have different small string capacities.
| In clang and libc++, you can store 22 bytes of short
| string when the data structure itself is 24 bytes. This
| is more than what MSVC or gcc can do.
|
| https://devblogs.microsoft.com/oldnewthing/20240510-00/?p
| =10...
| pjmlp wrote:
| Just like bounds checking in Rust.
|
| Some type safety conditions can naturally only be checked
| at run-time.
|
| And actually, checks are done at compile time if the
| compiler is able to see what is being used on the spot.
| tialaramex wrote:
| Also, sometimes you can arrange that the "check" is just
| the natural way to express what you meant in the
| language, so whether it's a runtime check or not, the
| ergonomics are improved enormously, it feels natural.
|
| In Rust NonZeroI8::new(n).unwrap() is either a NonZeroI8
| or, if n was zero, it panics because we asked to unwrap
| the Option and that's None.
|
| What's inside NonZeroI8::new ? Literally a cast. When
| compiled this is nothing at all, no machine code is
| generated. It is relying on the fact that
| Option<NonZeroI8> has bit pattern 00000000 for None, and
| that's also the bit pattern for the integer zero.
|
| So if we ask at compile time,
| NonZeroI8::new(FOO).unwrap() for some constant FOO, the
| compiler will, at compile time, transform the FOO bit
| pattern, if it's all zeroes this code is just a runtime
| panic, and if it's on the clear through line (e.g. the
| only code in the main function) by default the compiler
| says well that's not going to work, here's a compiler
| error [if you actually want a program which just panics
| when run you can ask for that with a compiler setting,
| good luck to you].
|
| If FOO isn't zero then, still at compile time, now we've
| got a NonZeroI8 with value FOO
| naasking wrote:
| > To be honest, it wasn't particularly useful, because it
| requires runtime checks which panic if they fail.
|
| Checking at runtime is 100% still incredibly useful.
| That's how you enforce critical program invariants to
| avoid security vulnerabilities or prevent invalid states
| that could ruin the program's data.
| etrez wrote:
| * Splitting large enumerated types into smaller ones
|
| * Using the same range for arrays indexes, "for" loops
| parameters which index those arrays. In those cases a
| good compiler _removes_ the useless run-time checks!
|
| Ada range types can have bounds that are known only at
| run-time. It was not possible with Pascal.
|
| To see subtypes in action: another FOSDEM presentation:
|
| https://fosdem.org/2025/schedule/event/fosdem-2025-5148-a
| dve...
| Tomte wrote:
| According to the talk it's more about Dynamic_Predicates,
| i.e. arbitrary conditions on a type. He's showing an Ada
| type definition for prime numbers, not just simple
| subranges.
| Ygg2 wrote:
| They're called pattern types because the intention is to
| allow them to match a Rust pattern expression (more or
| less, no idea how conditionals would work).
| Lucretia9 wrote:
| Pattern matching is in all functional languages, afaik.
| mbStavola wrote:
| As an update to my previous comment in the linked thread,
| the aforementioned minimal version of pattern types have
| been merged and generic support is currently being
| implemented[0]. Slowly but surely, we're getting there!
|
| [0]: https://github.com/rust-lang/rust/issues/136574
| the8472 wrote:
| https://gist.github.com/joboet/0cecbce925ee2ad1ee3e5520cec81.
| ..
| Ygg2 wrote:
| There is a pdf of presentation in the link...
|
| Pattern types or liquid types or dependent types are a way to
| express a subset of a type. E.g. type
| NonNull = usize is 1.. type
| PokerNonFaceCard = u8 is 2..11
| sampo wrote:
| > I want to write BalancedI8
|
| So, you want an integer, but one value sacrificed to denote
| not-a-number? Is this what "niche" means?
|
| So that with these, you can have Option[integer8, None], an
| option type that either contains a -127 to +127 8bit integer or
| contains the empty value, and still consumes only 8 bits of
| memory? Or are there other uses for this?
|
| And Rust already has this, and with the memory optimization,
| but for some reason only the version where they sacrificed the
| value 0.
|
| https://doc.rust-lang.org/std/num/type.NonZeroI8.html
| Joker_vD wrote:
| The main use is not having to deal with INT_MIN, the two
| chief problems of which is that you a) you can't sensibly
| abs() it, b) most people tend to forget about point a). This
| problem in my experiences most commonly arises in naive
| implementations of itoa/etc. which tend to assume that they
| can just call abs() and concentrate on the positive half-
| range signed integers. Nope, you can't do this, not all
| negative integers have a positive counterpart.
| tialaramex wrote:
| Yes, I want to be able to make such types myself.
|
| You're correct that Rust provides NonZeroI8, which in fact I
| called out in my text. If you look at the source, you'll see
| that the Rust standard library is allowed to make this type
| but you can't in stable Rust,
|
| [rustc_layout_scalar_valid_range_start(1)] means, "Hey, Rust
| compiler, I promise it's fine to just assume I never have
| this value: 0". You absolutely could write BalancedI8.... if
| you're the Rust standard library. Unfortunately you aren't
| allowed to do that in your own stable Rust software because
| it needs these compiler internals.
|
| There were discussions about stabilising this idea, and they
| were knocked back because if you do that you're basically
| stuck with it forever.
|
| One day in the future NonZeroI8 could "just" be a Pattern
| Type, like the ones you can make at home, but today there are
| no Pattern Types and NonZeroI8 needs compiler magic.
|
| There are other Rust core types which you could make
| yourself, IPv4Addr for example is just a 32-bit value, you
| could make your own, but yours wouldn't be on everybody's
| Rust system. Option<&T> is just a sum type over &T and None,
| you genuinely could make your own, call it Maybe<&T> and it
| would work exactly the same - same optimisations even,
| although not all the compiler diagnostic messages would be as
| good if you use it wrong I think. But today NonZeroI8 isn't
| like them, it actually needs a sprinkle of compiler magic.
| edflsafoiewq wrote:
| They're sort of used in graphics APIs. When a value in [-1.0,
| 1.0] is quantized to an i8, the result is a BalancedI8: -1.0
| maps to -127, 1.0 to 127, and -128 is unused; if -128 is used
| in the dequantizer, it is treated the same as -127. This
| replaced the old scheme where -1.0 mapped to -128 in which
| 0.0 was unrepresentable.
|
| The value of encoding this case in the type system seems
| minimal to me though.
| noneeeed wrote:
| Nice!
|
| My first job was mostly SPARK Ada, subtypes were so useful,
| both in terms of making contracts clearer for the human and for
| the various analysis tools.
|
| Rust is high on my list of languages to learn when I can make
| some time, having something like this available will be great.
| eslaught wrote:
| Maybe not fully ergonomic yet, but this exists today (at least
| for max):
|
| https://docs.rs/nonmax/latest/nonmax/
|
| If you're really attached to it being min you'd have to copy
| that library.
|
| Edit to add: we actually use these in one of my main Rust
| codes; they're useful, but I'm not sure they're so useful I'd
| want them built into the language.
| tialaramex wrote:
| Yeah, the XOR trick+. It's very affordable on modern hardware
| (your CPU can cheerfully XOR two registers while doing other
| things, barely measurable) but it's more the principle of the
| thing. Maybe I should just put up with the XOR trick and stop
| thinking about Pattern Types but I don't think I'll be able
| to.
|
| + Just in case you've never looked inside those types, they
| have a constant value and when you want a NonFoo you just
| take a NonZero and you XOR it with that constant, in other
| respects they work the same way as any other wrapper type.
| This is one reason the NonZero types exist, they make the XOR
| trick very easy to do.
| kevlar700 wrote:
| Whenever I can use Ada. I wouldn't use anything else.
| cutemonster wrote:
| What do you build / have you built, using Ada :-)
| kevlar700 wrote:
| Hardware products like sensor and control devices. I also use
| it for desktop tooling whenever a script wants a for loop.
| Unfortunately I use Flutter for GUI stuff because I hate js
| and because it has Android/IOS plugins that I would have to
| write if using Gnoga.
| nicce wrote:
| How is Ada without touching anything commercial?
| nickdothutton wrote:
| Ada was my first (non hobby use) language. Mostly on VAX/VMS with
| LSE as the "IDE", and I use the term IDE loosely :-). Although I
| encounter it rarely I'd encourage anyone to take a look.
| BSDobelix wrote:
| Ada with VMS, so that thing was 100% uptime then?
| Lucretia9 wrote:
| FYI, re the ranges in rust, you can do a range minus 10 in Ada, I
| use it in my SDL2 bindings.
| weinzierl wrote:
| I am always confused about the terminology. I know RangeTypes or
| RangedTypes from Pascal, but I think in Rust they are something
| else. The talk mentions SubTypes in the ADA context which I know
| from an OO context, but again it seems to be different. Then
| there are Refinement Types which seem to be more powerful but
| subsume the others. And now we also have Pattern Types.
|
| Can someone bring order in these concepts?
| Lucretia9 wrote:
| Ada has ranges and subtypes. type Angles is 0
| .. 360; subtype Acute_Angles is range Angles'First .. 90;
|
| Subtypes can be used with the parent type without conversions.
|
| Pascal only has subranges, iirc.
| fuzzy_biscuit wrote:
| I'm seeing a lot more Ada posts on the front page recently. Was
| there a big investment in Ada recently or an acquisition where
| its marketing machinery is starting to chug along? Or was there a
| meaningful release or something?
| bluGill wrote:
| There was an interesting conference where Ada was presented.
| Ada marketing has gotten better over the years as well. Still
| not enough that I'm trying it, but it remain intrigued.
| jghn wrote:
| My assumption has been that Rust's rise to prominence here has
| led people to investigate & reflect more on prior art in the
| realm of "safety" in the PL world. This leads them to Ada. And
| as there's a general trend in HN to look at less traveled roads
| it starts popping up here. the Baader-Meinhof phenomenon starts
| to kick in and creates a feedback loop
| coliveira wrote:
| No, if it was for the bandwagon in social media, everybody
| would be forced to use Rust. However companies that work on
| government contracts have for a long time used Ada, and they
| have a lot of software and investment there. So, with the
| recent government advisories, the Ada tech is coming back to
| fill that opportunity.
| andrewl-hn wrote:
| Even with administration change in the US there is a long-term
| initiative across multiple agencies to eventually move to more
| robust software, and a part of it is the push towards more safe
| programming languages (where safe means fewer memory issues,
| fewer vulnerabilities, less bugs in general, etc.). Similar
| government initiatives now start in Europe and elsewhere in the
| world, too.
|
| This regulatory change is not new, it has been going on for
| years and will take more years to finish. And even without a
| regulatory pressure, the migration would happen eventually.
| Look at the cars. As they get more features like adaptive
| cruise control and various driver assistance features, the need
| for software that runs with no lag and is reacting to
| surroundings correctly and quickly becomes absolutely critical.
| Car companies now can go out of business simply because their
| software is buggy. The car vendors now produce more software
| than ever, and they are in dire need for better programming
| tools than ever.
|
| Languages like Java, Scala, C#, Go, etc. cover many scenarios
| like cloud services and, for example, car entertainment system.
| But for devices, microcontrollers, real-time low latency
| systems etc. C and C++ have been the go-to languages for
| decades, and now it is starting to change, because turns out it
| is very, very hard to write correct, bug-free, safe, and secure
| software in these languages.
|
| Rust is one language that is getting into this market: Rust
| Foundation established a Safety-Critical Rust Consortium last
| year, for example, and Ferrocene compiler has a bunch of
| certifications done already. Ada is another option that would
| work for many such use-cases, too. The selling point of Ada is
| that it's been around for a long time and many vendors already
| have established compilers and tools with all appropriate
| certifications and qualifications done for all sorts of
| industries.
|
| So, it's not really "Ada is interesting" and more "Languages
| that can replace C and C++ are interesting".
| imglorp wrote:
| The new administration has removed the memory safe
| programming languages memo.
|
| https://web.archive.org/web/20250118013136/https://www.white.
| ..
| _a9 wrote:
| The Whitehouse website gets cleared for the incoming
| administration.
|
| The page was moved to:
| https://bidenwhitehouse.archives.gov/oncd/briefing-
| room/2024...
| steveklabnik wrote:
| A lot of this movement continued to happen under the
| previous Trump administration; we have no idea what is
| going to happen, there are good arguments that it may go
| away, but also ones that argue it will accelerate or
| intensify. We'll see.
| Lucretia9 wrote:
| That's why Toyota moved to Ada, because their C or C++
| software caused crashes.
| 999900000999 wrote:
| Am I a bad programmer if rust is really difficult for me. I
| desperately want to learn a low-level language, since I think
| I'm missing something hanging out with my buddies C#, Python
| and NodeJS.
|
| C and C++ are too difficult, Rust is also hard. I think my
| best bet is Zig at this point.
| knowitnone wrote:
| Why is Zig easier than C/C++/Rust?
| coaksford wrote:
| No, Rust gives you a lot to wrap your head around very
| quickly, and it took me three or four epiphanies to get it,
| and I tried to learn and stopped twice before I was able to
| get far enough along with it that it became easy to think
| about and work with. It doesn't make you bad programmer,
| but I'd still suggest giving it another shot every 6 months
| or so as your time allows, and see if you're getting
| farther each time. As long as you're still learning each
| time you bounce off of it, it was probably time well spent,
| most Rust concepts will show up in other languages, and the
| ones that won't are still useful paradigms to be aware of
| so you can contrast it with other paradigms as you get more
| experience with those.
| 999900000999 wrote:
| I think where I'm getting stuck, is my favorite
| programming language C# tends to make a bunch of safe
| assumptions for you.
|
| These assumptions just aren't made with rust.
| api wrote:
| Rust has a steep initial learning curve followed by a
| plateau of enlightenment.
|
| The language has a lot of corners though -- not so much
| messy edge cases like C++ but just emergent complexity from
| its sophisticated grammar and type system.
|
| As with all such languages: you do not have to make use of
| all language features everywhere, and in fact you should
| not.
| zozbot234 wrote:
| Rust is very different from Python or C#, let alone NodeJS.
| I'm not sure what exactly is so difficult about Rust for
| you, but the basic feature-set of Rust as "your first
| programming language" (i.e. no prior experience with C/C++)
| is one where the main emphasis to begin with should be on
| passing stuff by value and explicit copying, almost like a
| functional language - avoiding both references and interior
| mutability. These latter features should be looked into
| _after_ you 've become familiar with the basics, so as to
| avoid any confusion.
| throwaway314155 wrote:
| Surely the reason the learning curve is hard has more to
| do with syntax than with grokking basic FP concepts such
| as immutability. Right?
| WalterBright wrote:
| The D programming language is far safer than C/C++, with
| the same amount of power. The syntax/semantics are such
| that it's very easy to learn if one is familiar with C/C++.
|
| For example, although one can use pointers in D with
| abandon, it's better to use slices, where array bounds
| overflows cannot happen. Array bounds overflows are the #1
| cause of security bugs in shipped C/C++ software.
| throwaway314155 wrote:
| > if one is familiar with C/C++.
|
| > C and C++ are too difficult
| 999900000999 wrote:
| I think we might have chatted here before.
|
| I want to like D, it definitely came up in my research
| but I just don't see the ecosystem as vibrant enough to
| lead to where I want it to .
|
| Either building cool things, or better employment
| opportunities.
|
| It is encouraging to see a language so loved folks are
| proselytizing for it.
|
| My vote is for Haxe! But that's also a very high level
| language.
| WalterBright wrote:
| The people who do use D really like it. It's a mature
| language with solid compilers.
|
| I haven't experienced a memory corruption problem with it
| in maybe a decade, and I write D code every day. That's a
| big change from my days writing C and C++.
| WD-42 wrote:
| No, Rust is definitely hard. One of the best memes I've
| seen about rust goes like "Other languages have a garbage
| collector, with Rust you are the garbage collector."
|
| I also haven't had as much fun learning another language in
| a long time. Keep with it! It's worth it.
| switchbak wrote:
| C is small enough as to be very valuable to know. It's not
| the "high level assembler" that it was originally sold as,
| but as a conceptual model it's invaluable. It's also very
| valuable to run through CVEs, bug reports and such to find
| out how it falls down, and why safer languages have value.
| You can learn all that without even learning it to such a
| degree that you can write code in it.
|
| I know you said C seems too hard - I felt the same way some
| 30 years ago. Then I learned Pascal, and found learning Ada
| to be a bit of a breeze after that. After that, coming back
| to C was a different experience - very natural. You don't
| have to force anything, and you can learn whatever you want
| whenever you want (or not at all).
|
| Sometimes your capabilities can quickly level up in
| unpredictable and exciting ways - which I find to be one of
| the most fun parts of programming. And it tends to unfold
| like a horizon - you learn low-level stuff, then you get
| interested in high-reliability software, or real-time
| systems, or highly parallel / functional systems, etc. This
| is all great, and no one brain is big enough to hold it all
| - so have fun!
| the8472 wrote:
| If you have written multithreaded C# code which encountered
| deadlocks, race conditions and had to build a mental model
| of which thread is responsible for what and currently
| "owns" a resource and is allowed to modify them... then you
| already kind of know a bunch of things implicitly that rust
| makes explicit and can transfer that knowledge.
|
| At least that's how things clicked for me when I came from
| Java and I already had to debug lots of concurrent code
| before.
|
| Similarly, if one has fought with a garbage collector and
| thought about efficient memory representations, where
| things get allocated and deallocated that transfers to some
| extent.
|
| If you have been living blissfully in effectively-single-
| thread-land, then yeah, there'll be a bunch of new concepts
| to digest.
| 999900000999 wrote:
| At least for the work I typically do, including my
| hobbyist projects in Unity, I almost never have to use
| threads. Praise be to Async, which has abstracted a lot
| of this.
|
| I couldn't really grass programming until I found
| JavaScript. Even now my criteria for learning a language
| is one of two things .
|
| One, do I want to build something and this language would
| be the best tool .
|
| Or, two, is this language going to make me a ton of
| money.
|
| I really want to find a good use case for Rust that isn't
| superseded by what I can do in the languages I already
| know. I might take some time to make a game in Rust one
| day...
| zozbot234 wrote:
| > Or, two, is this language going to make me a ton of
| money.
|
| I don't think _any_ language per se is ever going to make
| you a ton of money. Even COBOL is not enough to make a
| ton of money. What might make you a ton of money at some
| point is being highly skilled at developing in _some_
| broad area where that particular language happens to be
| used.
|
| > I couldn't really grass programming until I found
| JavaScript.
|
| This is a bit surprising to me, because JavaScript is not
| at all an easy language to work with. You might want to
| look into TypeScript as a way to make quicker progress in
| that same domain, with Rust as more of a side-project to
| help you grok lower-level programming in general.
|
| > I might take some time to make a game in Rust one
| day...
|
| Game development in Rust tends to be especially
| challenging, since the main competition is C++ - another
| low-level language. Take a look at this example of a very
| simple Breakout game in Bevy, one of the most well-known
| game engines (though still very much at a highly
| experimental stage!) https://github.com/bevyengine/bevy/b
| lob/latest/examples/game... - this might help you realize
| the level of effort that's typically involved.
| 999900000999 wrote:
| I've been a salaried software engineer for a long time at
| this point.
|
| JavaScript just clicked. A lot of more complicated things
| you need to understand for c and c++ are just handled for
| you.
|
| To be fair I was technically using Unity Script, which
| has everything in a nice game engine sandbox. Want to
| move a cube, takes 1 line of code.
|
| I am working with Typescript on my latest project. It
| definitely helps when dealing with more complex projects.
| My current project is basically a website built in React.
|
| I still like Unity, but I don't trust the company so I'm
| looking for a new engine.
| zozbot234 wrote:
| > I still like Unity, but I don't trust the company so
| I'm looking for a new engine.
|
| Then the obvious choice is arguably Godot, which supports
| a similar "script-based" model.
| 999900000999 wrote:
| Godot has it's fair share of issues.
|
| Maybe I'll see if they fix C# web exports.
| eikenberry wrote:
| > The selling point of Ada is that it's been around for a
| long time and many vendors already have established compilers
| and tools with all appropriate certifications and
| qualifications done for all sorts of industries.
|
| This makes it sound like the field is dominated by
| proprietary/closed-source tooling. That is a huge red flag
| for the health of the language if true.
| rad_gruchalski wrote:
| Well, yes. But that's the feature in this context. The
| point is: places where Ada is used require certain levels
| of qualification and certification, all the way down to the
| compiler. You have to be able to prove that that binary
| fragment was produced by that particular code fragment.
| Think aircraft, nuclear reactors, rockets.
|
| So this tooling is already certified and it fills the
| "compiler + various verification tools" space. Otherwise
| you'd have to certify your tool chain yourself every time
| it changes.
|
| Say you are building an aircraft. The whole software stack
| is part of the aircraft certification, all the way down to
| the compiler. A complete aircraft is a system composed of
| other systems which themselves are composed of other
| systems. Eventually, there's a software system. Systems are
| certified independently and for a complete configuration.
|
| Of course, requirements get stricter as the criticality of
| the component increases. Not every component has such
| strict requirements as discussed above. But a lot of them
| do.
| LiamPowell wrote:
| The popularity of Rust has caused a lot of people to start
| taking safety more seriously. Ada is _the_ safety language for
| everything except memory and thread safety (they 're pretty
| safe still, but not completely like in Rust).
|
| I think some of it also comes from the number of new
| programming languages that have come out over the last few
| years. It's common for people to point at Ada as a reference
| for how to address problems that come up in C-like languages
| since Ada already solved so many problems in the 80's.
| kevin_thibedeau wrote:
| People have gotten fed up with smug rustaceans shouting about
| 40 year old technology.
| unshavedyak wrote:
| If only that 40 year old technology could have captured
| attention in the last 40 years.
| rightbyte wrote:
| I don't think an Adacian missionary has ever knocked on my
| door. Rustafarians were twice a week at some point.
| sophacles wrote:
| Maybe the rust folks realized that 40 more years and
| billions of dollars wasted on "we'll get pointers right
| this time and not leave the same old gaping holes in our
| new software" left people receptive to new things?
|
| They probably have another good reason to advocate too -
| 90% of anti-rust sentiment is "Gross, people like using
| it so much they tell others that they like it".
| spoiler wrote:
| IMO The language has merits regardless of a few (if not
| _very few_ ) bad apples in the community, and its
| technical merits should be the primary lense for
| evaluating it as a choice.
| throwaway314155 wrote:
| > 90% of anti-rust sentiment is "Gross, people like using
| it so much they tell others that they like it".
|
| More like "Gross, people like using it so much they imply
| (or just outright say) other languages are inferior."
|
| edit: apparently I'm "posting too fast", so I'll reply in
| an edit. What you (sophocles) said is effectively
| equivalent to "other languages are inferior", although I
| appreciate how you twisted the words up like that.
| Computers can be used effectively in a wide variety of
| languages. Do some languages age poorly? Sure. But not
| all of them.
| sophacles wrote:
| Nah, that's just the listener's ego overreacting to
| someone acknowledging that the obsolete, and factually
| inferior language they like is in fact obsolete and
| factually inferior. For a long time the world bought into
| C is best for X, Y and Z things and it's the only real
| choice... so people did that human thing and tied their
| identity to using that particular language, their
| subconscious has decided that they are being called
| inferior because they think the tool is their value
| rather than their ability to reason deeply about what
| computers are going to do.
| jghn wrote:
| I'm more fed up with smug rustaceans acting like everything
| Rust does is somehow novel. Just because *you're* not aware
| that a language feature already existed earlier doesn't mean
| Rust invented it.
| zozbot234 wrote:
| The whole point of Rust was to take developments in
| programming language theory from 20 years ago or so and
| make them practical for widespread use. Practically nothing
| Rust does is new, because "new" stuff means that the
| overall implications of that language feature have yet to
| be figured out. Which is bad if you want to keep your
| language elegant and easy to learn.
| jghn wrote:
| > Practically nothing Rust does is new
|
| That's my point in a nutshell. It's a cool language. But
| there's a growing number of converts for whom this is
| their first introduction to these concepts, and they
| don't seem to have the intellectual curiosity to dive
| deeper.
|
| I also see this behavior with Typescript and "powerful
| type systems"
| spoiler wrote:
| People will point out _features they like_ about Rust,
| sure. But I 've never seen anyone be smug about it, or
| claim they're novel features.
|
| Edit: Maybe these types of low quality comments exist on
| social networks, but... Isn't that just the norm for social
| networks? You can say the same about cooking advice on
| social media, or "life hacks" content, etc
| escobar_west wrote:
| Is there another language out there which encodes lifetime
| semantics and affine types besides Rust? AFAIK there isn't
| (happy to hear otherwise though).
| dismalaf wrote:
| I think Rust opened up a ton of interest in languages that are
| as fast as C++ but safer... The fact that Ada was doing a lot
| of stuff that Rust is trying to do now but decades earlier is
| particularly interesting.
| throwaway81523 wrote:
| I would say Ada got a lot nicer when Ada 2012 was released, and
| interest picked up since then. Around the same time, C++ got a
| lot nicer with the release of C++11.
| m463 wrote:
| Self driving cars?
| LiamPowell wrote:
| My broad feelings on many of the issues in Rust, including what's
| presented here, is that they come from starting with a C-like
| language as a base. The memory safety and thread safety features
| in Rust are very impressive, but many other things feel like
| they're lacking and non-safety features that were added later
| feel tacked on rather than being a core part of the language.
|
| I feel that if Rust had started with a language like Ada and
| applied their innovations there then we would have ended up with
| a much nicer result.
| orf wrote:
| "Don't let perfect be the enemy of good" - how much of Rust's
| success comes from the fact that it started from a C-like base?
|
| Doing it differently might end up with a better result from a
| purist viewpoint, but I'd wager that adoption would have been
| far worse.
| LiamPowell wrote:
| Probably true, although I wonder how much comes from acting
| like C semantically and how much comes from looking like C.
| If Rust had taken Ada and made it look like C then would it
| still be so popular?
|
| My guess is that it would be since there's already a steep
| learning curve for a C developer to pick up Rust. For a
| developer who's willing to go through all that I don't think
| a few more new concepts would be a major issue.
| estebank wrote:
| Or it could have killed it on the vine because the syntax
| was too esoteric and would have pushed the target
| demographic away before they even tried it. It's hard to
| test the counter factual in this case.
|
| A common topic of conversation in the rust project is the
| concept of "weirdness budget": the idea that you can only
| be so different from what your expected userbase already
| knows before you become too hard to learn. I don't think
| you could introduce the borrow checker on a language like
| Erlang if you're aiming at systems programming. But _now_
| you could make a language that is slightly more weird
| (introducing other features) than Rust when _targeting
| existing Rust programmers_.
| tialaramex wrote:
| > starting with a C-like language as a base
|
| Which C-like language do you believe was the base of Rust?
|
| If you're judging because the syntax _looks_ like a semi-colon
| language that 's just a thin disguise, to make it easier to
| onboard people from those languages.
| LiamPowell wrote:
| Not a specific C-like language, but that family of languages
| in general and the design decisions from them:
|
| A number is just a number even if two numbers represent
| completely incompatible things. If one integer represents a
| chmod value and one represents a number of files then you can
| add them together and the compiler will do nothing to stop
| you even though adding the two is always nonsensical. There's
| ways around this by creating your own types, but it's not a
| trivial process. In Ada I can just declare two different
| numeric types with identical ranges (type A is range 1..200)
| and the two will be incompatible.
|
| Somewhat related to the above, all array indexes are just
| numbers. In Ada we can define a type and then use that type
| as an index of an array type, so if a value is the index type
| then it must be a valid array index. In Rust if I declare an
| array as having 5 elements then pass it to a function where I
| try to access element 6 then nothing will try raise an error
| at compile time.
|
| Continuing on from the last point, arrays are only indexed by
| numbers rather than any discrete type. In Ada and enumeration
| is a valid type to use as an array index, or a range from 5
| to 15, or -123 to 7. I'm sure this is something you can do
| with a generic in Rust, but it's going to be more clunky than
| having native language support.
|
| Structs are just basic collections of fields. In Ada we have
| discriminated records that allow for some struct fields which
| can only be set at instantiation to control things like the
| number of elements in an another field which is an array. An
| example of where this could be used is in a ring buffer which
| is fully contained within a simple struct without the need
| for extra memory allocation. (I'm aware this conflicts with
| the other examples about arrays, in short there's a second
| type of array declaration with a variable subrange as an
| index). Maybe you can do this with generics in Rust, but it's
| not as clean, especially if you want to, for example, add a
| procedure to the ring buffer that takes another ring buffer
| as a parameter.
|
| These are just off the top of my head as someone who's only
| briefly looked at Rust, I'm sure there's many more examples.
| The exact syntax might not match C, but many of the concepts
| come directly for C and derivatives.
|
| The Ada examples I've given exist in other languages too in
| various forms, I just happen to be an Ada dev so I know
| exactly how they work there.
| tialaramex wrote:
| Well you say "that family" but you only give examples of
| why Rust isn't Ada.
|
| Is the situation that you consider there are two families
| of languages, "Ada" and then "All of the other programming
| languages" and you've decided to label that second group C?
|
| On that basis I agree, Rust has a "C base" as do Fortran,
| Logo and the Standard ML of New Jersey, but I don't think
| that's a useful way to understand anything about
| programming languages.
|
| > In Rust if I declare an array as having 5 elements then
| pass it to a function where I try to access element 6 then
| nothing will try raise an error at compile time.
|
| https://rust.godbolt.org/z/4eMTTMar4
|
| Looks like a compile time error to me. I suspect you wrote
| a function which takes a _slice reference_ not an _array_.
| In Rust these types are named &[T] and [T; N] and sure
| enough we don't know the value of N in a slice because
| well, it's not part of the type. Ada can't magically know
| this either, in Ada you've probably been writing an array
| here, and if that's what you meant you can do that in Rust
| too with similar effect.
|
| You can't do it in C (the array types do exist in C, but
| they decay to pointers at the edge of any function, so we
| can't pass these types between functions) but you can in
| Rust.
|
| > arrays are only indexed by numbers rather than any
| discrete type
|
| I guess you're thinking about core::slice::SliceIndex<[T]>
| ? This is (at least for now and perhaps forever) an
| unstable trait, so, you're not "allowed" to go implement
| this in stable Rust, but if you did anyway you can
| cheerfully implement SliceIndex for your own type, Rust
| won't barf although you can probably undermine important
| safety features if you try because none of this is
| stabilized.
|
| Far from being "only numbers" core::slice::SliceIndex<[T]>
| is already implemented for the ranges (both kinds) and for
| a binding pair (lower_bound, upper_bound)
|
| So in terms that maybe seem more obvious to you, we can do
| foo[(Bound::Unbounded,Bound::Unbounded)] as well as
| foo[3..=4] and foo[3..] in addition to the obvious foo[3]
| -- these are all defined on slices rather than arrays
| though because in practice that's what you actually want
| and we can just decay the array to a slice during
| compilation.
|
| Overall I still think it really is the syntax that threw
| you off.
| eximius wrote:
| You can do everything you're saying in Rust.
|
| 1. https://docs.rs/dimensioned/latest/dimensioned/
|
| 2. https://doc.rust-lang.org/std/ops/trait.Index.html
|
| 3. Maybe const generics? e.g., Foo<N: 3> where Foo { array:
| [u32; N] } or something. You could also do this with less
| typed-ness with Foo::new_with_capacity(n) and some private
| size management.
|
| It definitely takes aesthetically from the C-family of
| languages in the same way that Java and Go are all braces
| and semicolon languages. I can't exactly minimize this -
| because I am comfortable with languages that look like this
| and less comfortable with some languages that don't, so I
| recognize the effect is very real - but it doesn't affect
| the features of the language much.
| the8472 wrote:
| > Somewhat related to the above, all array indexes are just
| numbers.
|
| Create your own type[0] encapsulating arrays, and then
| implement the Index[1] with a custom Idx generic.
|
| > In Ada and enumeration is a valid type to use as an array
| index, or a range from 5 to 15, or -123 to 7
|
| That's what TFA is about.
|
| [0] https://doc.rust-lang.org/rust-by-
| example/generics/new_types... [1] https://doc.rust-
| lang.org/std/ops/trait.Index.html
| rcxdude wrote:
| Rust started with ocaml as a base, then evolved in a more
| C-like direction later on, mainly as a familiarity with the
| target programmers thing. It wasn't originally envisioned as
| the systems language that it became, it was much more high
| level, with a planned GC and everything, then the lifetimes
| stuff got developed and the contributers at the time pushed it
| into more and more control in the hands of the programmer.
| runekaagaard wrote:
| I'm often wondering about if an elixir-like language for Ada
| could make it more popular.
| dpc_01234 wrote:
| BTW. What's the best way to go over/keep track of all available
| FOSDEM talks videos?
| madushan1000 wrote:
| check here https://review.video.fosdem.org/overview
| throwaway81523 wrote:
| I didn't watch the video but I read the pdf transcript. I noticed
| that the contract example (if x > 50 then x+50 > 100) can fail
| because of integer overflow. This is an area that Ada seems to
| take much more seriously than Rust does.
|
| Anyone know what happened with Adacore and Ferrocene? Are they no
| longer working together? It sounded like a good collaboration
| earlier on, given the Rust juggernaut.
|
| Also I notice no mention of anything like SPARK for Rust.
|
| I still feel like Rust and Ada are designed for differing
| domains. The archetypal Ada app in particular might malloc some
| memory (and possibly fail) during an initialization phase, but
| post-initialization, must never fail, which for among other
| things basically says never use malloc. The post initialization
| part is basically a control loop using those fixed buffers to
| keep a jet engine spinning or whatever.
|
| Rust's archetype application on the other hand is a web browser:
| tons of dynamic allocation, possible memory exhaustion depending
| on what the user tries to do, and the requirement is to never
| fail ungracefully, as opposed to never failing at all. "Never
| fail at all" is not exactly more stringent or complicated: it
| just means you're not allowed to even attempt certain things,
| because they might fail.
___________________________________________________________________
(page generated 2025-02-10 23:01 UTC)