[SRS] Breaking News: The inverted result type!
monkyyy
crazymonkyyy at gmail.com
Sat Jun 27 10:20:33 UTC 2026
On Saturday, 27 June 2026 at 09:53:06 UTC, Richard (Rikki) Andrew
Cattermole wrote:
> ```d
> struct InvertedResult(ErrorCause, DataType) {
> ErrorCause error;
>
> alias error this;
>
> DataType data;
> }
> ```
breaks ufcs
You may think that 7 lines of nested if statements is the height
of usability, **but NO**
```d
struct GooderResult(ErrorCause, DataType){
ErrorCause error;
DataType data; alias data this;
}
auto gooderresult(A,B)(A a,B b)=>GooderResult!(A,B)(a,b);
```
now users can just ignore the error entirely, without truthyness
or an opinion on the subject, or inline handleing; and as we all
know from the important thread of the philosophy of software
design and walter, the best error is one that is defined to not
exist
Therefore d style should evolve towards this:
```d
auto safedevide(int a,int
b)=>gooderresult(b?"":"/0",b?a/b:int.max);
```
and for the rare cases you want to fail(why fail when you could
just succeed? masochist)
```d
auto CRASH(T)(T t){
assert(t.error,t.error.to!string);
return t.data;
}
```
Or more realistically:
```d
auto replacefailure(T,S)(T t,S replace)=>t.error?t.data:replace;
```
More information about the Digitalmars-d
mailing list