News for hackers. Stuff that matters.
Re:Why Rust helps even if you have to use a lot of `unsafe` by fnfjfk on Wednesday August 02, 2023 @11:07AM (#36971923)
Option/Optional/Maybe is the most obvious one, as a basic example have you interacted with a API that sends some JSON where a field can be null or not? How would you represent that and distinguish it from a field that is always a string?
Re:Why Rust helps even if you have to use a lot of `unsafe` by TillE on Wednesday August 02, 2023 @11:18AM (#36972076)
That's just std::optional<> vs std::string, isn't it?
Re:Why Rust helps even if you have to use a lot of `unsafe` by fnfjfk on Wednesday August 02, 2023 @11:42AM (#36972435)
Yes, and std::optional is a janky implementation of a sum type in a language that doesn’t have them. The ergonomics are bad, and it is easy to make your program blow up if you forget a check.

In a language with sum types like Rust, Kotlin, and Swift, if you’re following the default “happy path” of coding, you are not allowed to forget a check. The compiler will not let you.

Re:Why Rust helps even if you have to use a lot of `unsafe` by Thaxll on Wednesday August 02, 2023 @11:10AM (#36971965)
Not many options, pointers most likely.