Re: Idiomatic way to express errors without resorting to exceptions

2020-03-09 Thread Simen Kjærås via Digitalmars-d-learn
On Saturday, 7 March 2020 at 15:44:38 UTC, Arine wrote: The case when there isn't a value should be handled explicitly, not implicitly. Propogating a None value isn't useful Except when it is useful, and shouldn't be handled explicitly. I have code in D, C and C++ that looks like this:

Re: Idiomatic way to express errors without resorting to exceptions

2020-03-07 Thread Sebastiaan Koppe via Digitalmars-d-learn
On Saturday, 7 March 2020 at 15:44:38 UTC, Arine wrote: I feel as though that's it's greatest weakness. It makes the check whether there is or isn't a value hidden. The case when there isn't a value should be handled explicitly, not implicitly. Propogating a None value isn't useful and is

Re: Idiomatic way to express errors without resorting to exceptions

2020-03-07 Thread Arine via Digitalmars-d-learn
On Saturday, 29 February 2020 at 15:23:02 UTC, Sebastiaan Koppe wrote: Like I said, I don't use optionals when I care about errors. That is not what they are designed for. If I want to type-guard potential errors I will use SumType!(T, Error). It forces you to handle both cases, either at

Re: Idiomatic way to express errors without resorting to exceptions

2020-02-29 Thread Sebastiaan Koppe via Digitalmars-d-learn
On Saturday, 29 February 2020 at 13:40:11 UTC, Adnan wrote: On Saturday, 29 February 2020 at 13:03:21 UTC, Sebastiaan Koppe wrote: On Saturday, 29 February 2020 at 12:50:59 UTC, Adnan wrote: * Option!T from the optional package: Has even worse problem IMO. Not only it allows None + int but

Re: Idiomatic way to express errors without resorting to exceptions

2020-02-29 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 29 February 2020 at 13:40:11 UTC, Adnan wrote: On Saturday, 29 February 2020 at 13:03:21 UTC, Sebastiaan Koppe wrote: On Saturday, 29 February 2020 at 12:50:59 UTC, Adnan wrote: * Option!T from the optional package: Has even worse problem IMO. Not only it allows None + int but

Re: Idiomatic way to express errors without resorting to exceptions

2020-02-29 Thread Basile B. via Digitalmars-d-learn
On Saturday, 29 February 2020 at 12:50:59 UTC, Adnan wrote: I have a struct that has to arrays. Each of those must have the same sizes. So while constructing the array, if you pass two arrays of different sizes the constructor must return nothing. In Rust I could easily use Option. D has no

Re: Idiomatic way to express errors without resorting to exceptions

2020-02-29 Thread Adnan via Digitalmars-d-learn
On Saturday, 29 February 2020 at 13:03:21 UTC, Sebastiaan Koppe wrote: On Saturday, 29 February 2020 at 12:50:59 UTC, Adnan wrote: * Option!T from the optional package: Has even worse problem IMO. Not only it allows None + int but also it returns a `[]`. This API is not to my liking. You could

Re: Idiomatic way to express errors without resorting to exceptions

2020-02-29 Thread Sebastiaan Koppe via Digitalmars-d-learn
On Saturday, 29 February 2020 at 12:50:59 UTC, Adnan wrote: * Option!T from the optional package: Has even worse problem IMO. Not only it allows None + int but also it returns a `[]`. This API is not to my liking. You could say well Haskell has fmap for Optional etc, and I am aware of that, so

Idiomatic way to express errors without resorting to exceptions

2020-02-29 Thread Adnan via Digitalmars-d-learn
I have a struct that has to arrays. Each of those must have the same sizes. So while constructing the array, if you pass two arrays of different sizes the constructor must return nothing. In Rust I could easily use Option. D has no answer to Optional types as far as I am concerned. Is