www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - D equivalent to Rust or Scala's Optional and Result and best practice

reply dangbinghoo <dangbinghoo gmail.com> writes:
hi,

It seems that now we have `Optional` and `Result` packages in 
Dub, are these enough or fully equal to Rust or Scala's 
error-handling and pattern-matching?

if these are enough for real-code, any best practice advice?

thanks!
Oct 18 2021
next sibling parent reply James Blachly <james.blachly gmail.com> writes:
On 10/18/21 12:03 PM, dangbinghoo wrote:
 hi,
 
 It seems that now we have `Optional` and `Result` packages in Dub, are 
 these enough or fully equal to Rust or Scala's error-handling and 
 pattern-matching?
 
 if these are enough for real-code, any best practice advice?
 
 thanks!
 
Not quite the same as tagged algebraic union ("sum type" == Rust enum) are not (yet?) a language feature. That being said, I recently integrated mir's Algebraic and Nullable into a project. Integration was pretty easy, and the code was clear and easy to understand. That being said, the terminology of "Some", "None", "Result" and "Err" in Rust are yet easier to understand. http://mir-core.libmir.org/mir_algebraic.html Finally, in addition to `mir.algebraic`, `sumtype`, `Optional`, and `Result` packages, I would add that Tchaloupka's `expected` package looks great: https://code.dlang.org/packages/expected
Oct 18 2021
parent dangbinghoo <dangbinghoo gmail.com> writes:
On Tuesday, 19 October 2021 at 00:01:47 UTC, James Blachly wrote:
 On 10/18/21 12:03 PM, dangbinghoo wrote:
 [...]
Not quite the same as tagged algebraic union ("sum type" == Rust enum) are not (yet?) a language feature. That being said, I recently integrated mir's Algebraic and Nullable into a project. Integration was pretty easy, and the code was clear and easy to understand. That being said, the terminology of "Some", "None", "Result" and "Err" in Rust are yet easier to understand. http://mir-core.libmir.org/mir_algebraic.html Finally, in addition to `mir.algebraic`, `sumtype`, `Optional`, and `Result` packages, I would add that Tchaloupka's `expected` package looks great: https://code.dlang.org/packages/expected
thanks, all is great, but it's better if we have an article explaining how to combine these for real-world project.
Oct 18 2021
prev sibling parent Soulsbane <paul acheronsoft.com> writes:
On Monday, 18 October 2021 at 16:03:53 UTC, dangbinghoo wrote:
 hi,

 It seems that now we have `Optional` and `Result` packages in 
 Dub, are these enough or fully equal to Rust or Scala's 
 error-handling and pattern-matching?

 if these are enough for real-code, any best practice advice?

 thanks!
There is https://code.dlang.org/packages/optional plus a couple more available in packages.
Oct 18 2021