comp.lang.ada
 help / color / mirror / Atom feed
From: John Perry <devotus@yahoo.com>
Subject: Re: Adacore joins with Ferrous Systems to support Rust
Date: Sat, 12 Feb 2022 15:59:33 -0800 (PST)	[thread overview]
Message-ID: <383f5bfc-64b6-4d7c-95e4-4dd6461c5d6bn@googlegroups.com> (raw)
In-Reply-To: <c1a2b567-8dbe-4a9a-ae0d-800759a594cbn@googlegroups.com>

First, I agree with Alejandro about the reference/lifetime soup. The other day I saw an expression along the lines of &[&something] and thought, "what"? If I look & think hard enough, I can figure out what that means, but words would be so much nicer, and searching for the meaning of a word is a bit easier than searching for "[]".

On the other hand, again: the tooling and error messages are really very good. "cargo clippy" gives a lot of helpful advice/lint. I think one of the regular correspondents here sells or maintains one for Ada, but I can't remember the name.

Anyway, I want to walk back part of what I said about Rust's safety, related to a post in a reddit thread where someone writes, "having students develop in Ada lead to them jumping from exception to exception until it worked, while other students writing code for the same problem in Rust lead to them swearing for 4 days until their code compiled and then being surprised that their code works, 100% as they expected and not ever producing a runtime error until the end of the two week practicum."

   https://www.reddit.com/r/ada/comments/7wzrqi/why_rust_was_the_best_thing_that_could_have/

Maybe, but long term I'm not so sure.

Rust doesn't have a null in safe mode, so the idiomatic way to indicate an error is via a Result enum, which has two variants: Ok(result), where "result" is the desired result, or Err(msg), where "msg" is an error message.

   https://doc.rust-lang.org/std/result/enum.Result.html

The "smart" way to handle a Result is to "match" it, basically an Ada case statement. (I confess that I prefer this to the approach in Ada's standard library, where, for instance, if I try to look up a non-existent key in a HashMap, it errors out with an exception.)

In any case, handling the Result can be a little tedious (only a little but still!) so people often use the standard library's ".unwrap()" function instead. That means something akin to, "I'm confident the preceding expression had an Ok result, so just hand me the result. If it's an Err then go ahead and panic with Err's msg."

Not all Rust users think much about that "panic" part. Err's msg can be pretty bare-bones, and as the Rust Book itself states, using .unwrap() a lot can make errors hard to track down:

   https://doc.rust-lang.org/book/ch09-02-recoverable-errors-with-result.html#shortcuts-for-panic-on-error-unwrap-and-expect

Technically this doesn't violate Rust's guarantees, but it's better to use .expect(msg), where you add a (hopefully) useful msg which gets reported along with the panic message.

But a lot of Rust users default to .unwrap() all the same, which makes me think that issue about Ada users jumping from exception to exception may be a feature of a lot of Rust code, too. Depends on the self-discipline, I guess.

  parent reply	other threads:[~2022-02-12 23:59 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-02  8:57 Adacore joins with Ferrous Systems to support Rust Paul Rubin
2022-02-02 13:04 ` Luke A. Guest
2022-02-02 15:29   ` Marius Amado-Alves
2022-02-02 16:36     ` Luke A. Guest
2022-02-04 17:51       ` Stephen Leake
2022-04-18 16:01       ` Rene
2022-02-02 20:07     ` G.B.
2022-02-03 23:29     ` John McCabe
2022-02-11 17:40     ` amo...@unizar.es
2022-02-11 19:24       ` Luke A. Guest
2022-02-12 17:34         ` Alejandro R. Mosteo
2022-02-12  5:22       ` John Perry
2022-02-12 10:08         ` Marius Amado-Alves
2022-02-12 18:24         ` Alejandro R. Mosteo
2022-02-13  8:10           ` J-P. Rosen
2022-02-14 23:25           ` Randy Brukardt
2022-02-15  4:29             ` Paul Rubin
2022-02-12 23:59         ` John Perry [this message]
2022-02-18 13:24     ` Kevin Chadwick
2022-02-02 20:06   ` Paul Rubin
2022-02-03  1:34     ` Luke A. Guest
2022-02-03  2:20       ` Paul Rubin
2022-02-03  2:52         ` Luke A. Guest
2022-02-03  4:22           ` Paul Rubin
2022-02-03  9:54             ` Björn Lundin
2022-02-04  3:38             ` Randy Brukardt
2022-02-04  5:19               ` Paul Rubin
2022-02-03 11:30           ` Simon Wright
2022-02-03 12:51             ` Luke A. Guest
2022-02-04  3:20               ` Randy Brukardt
2022-02-04 10:28                 ` Luke A. Guest
2022-02-04 17:51                   ` Andreas ZEURCHER
2022-02-05  4:31                   ` Randy Brukardt
2022-02-02 16:19 ` Stephen Leake
2022-02-02 18:48 ` Gautier write-only address
2022-02-02 20:03   ` Paul Rubin
2022-02-02 20:45     ` Dennis Lee Bieber
2022-02-12  4:42 ` 25.BZ943
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox