Idiomatic way to express errors without resorting to exceptions

Sebastiaan Koppe mail at skoppe.eu
Sat Mar 7 18:47:12 UTC 2020


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 
> computationally demanding as each subsequent call will need to 
> do a check to see if it has a value as it results in an 
> optional type (for binary operators). So something like `a + b 
> * c` is now much more expensive than it appears. This is 
> exactly the kind of abuse of operator overloading that the 
> feature is shunned for.

What can I say? If you don't like the semantics, don't use it. I 
have found value in it.

> Anyways not sure what you mean here with the code below. If 
> "first" here returns an optional type, you can't call 
> "doSomething" like that without first checking if the value 
> exists. Optional just doesn't allow it and Nullable will throw 
> an exception.
>
> ```
> list.first.doSomething(); // error
> ```

You are right. Nowadays you need a `.oc` call in between. Also, 
doSomething cannot be a free-standing function (sadly).


More information about the Digitalmars-d-learn mailing list