A D vs. Rust example

Dukc ajieskola at gmail.com
Mon Oct 24 20:04:00 UTC 2022


On Thursday, 20 October 2022 at 13:37:07 UTC, Don Allen wrote:
> ````
> use std::cell::RefCell;
>
> fn main() {
>     let foo = RefCell::new(5);
>     let bar = || {
>         *foo.borrow_mut() = 17;
>     };
>     let baz = || {
>         *foo.borrow_mut() = 42;
>     };
>     bar();
>     println!("{}", foo.borrow());
>     baz();
>     println!("{}", foo.borrow());
>     }
> ````

Yes, I believe this shows maybe the biggest weakaness of Rust. I 
could live with a language having a syntax like that (still 
better than C++, at least the old standards), but it does slows 
down working compared to most other new-generation languages.

Too bad. Rust's error handling seems so advanced. I'm not talking 
only about the ability to be safe without a stop-the-world GC, 
but about it's ability to detect other errors too. A good example 
is it's UTF-8 string type. Not only it is guaranteed to point to 
valid memory, it is statically guaranteed to point to valid 
UTF-8! A D programmer needs to rely on contract programming 
instead. Although I think that placing a few asserts is still be 
a good idea even in Rust.

Disclaimer: the above is likely to be humbug because I have no 
usage experience of Rust, only studied it's docs.


More information about the Digitalmars-d mailing list