From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.6 X-Received: by 2002:a37:a855:: with SMTP id r82mr3923895qke.645.1644710374426; Sat, 12 Feb 2022 15:59:34 -0800 (PST) X-Received: by 2002:a81:a9c6:: with SMTP id g189mr8136900ywh.274.1644710374164; Sat, 12 Feb 2022 15:59:34 -0800 (PST) Path: eternal-september.org!reader02.eternal-september.org!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 12 Feb 2022 15:59:33 -0800 (PST) In-Reply-To: Injection-Info: google-groups.googlegroups.com; posting-host=2601:3c3:400:b30:5bbb:11d1:c956:9424; posting-account=JSxOkAoAAADa00TJoz2WZ_46XrZCdXeS NNTP-Posting-Host: 2601:3c3:400:b30:5bbb:11d1:c956:9424 References: <87o83pzlvm.fsf@nightsong.com> <87d2e0c1-c851-43e2-a085-fad30e475e35n@googlegroups.com> <70f72b7e-1f3f-4942-b6aa-1044430bdcd9n@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <383f5bfc-64b6-4d7c-95e4-4dd6461c5d6bn@googlegroups.com> Subject: Re: Adacore joins with Ferrous Systems to support Rust From: John Perry Injection-Date: Sat, 12 Feb 2022 23:59:34 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader02.eternal-september.org comp.lang.ada:63500 List-Id: 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 wor= ds 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 go= od. "cargo clippy" gives a lot of helpful advice/lint. I think one of the r= egular correspondents here sells or maintains one for Ada, but I can't reme= mber the name. Anyway, I want to walk back part of what I said about Rust's safety, relate= d to a post in a reddit thread where someone writes, "having students devel= op 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 the= m swearing for 4 days until their code compiled and then being surprised th= at 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 "resu= lt" 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 H= ashMap, 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 in= stead. That means something akin to, "I'm confident the preceding expressio= n had an Ok result, so just hand me the result. If it's an Err then go ahea= d and panic with Err's msg." Not all Rust users think much about that "panic" part. Err's msg can be pre= tty bare-bones, and as the Rust Book itself states, using .unwrap() a lot c= an make errors hard to track down: https://doc.rust-lang.org/book/ch09-02-recoverable-errors-with-result.ht= ml#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 al= ong with the panic message. But a lot of Rust users default to .unwrap() all the same, which makes me t= hink 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 gue= ss.