Greenwashing

Meta jared771 at gmail.com
Fri May 29 14:57:52 UTC 2020


On Friday, 29 May 2020 at 13:20:52 UTC, Paul Backus wrote:
> On Friday, 29 May 2020 at 12:40:45 UTC, Meta wrote:
>> I'm going to step up the pedantry and say that this proves my 
>> assertion; Haskell (the language) gets along fine without 
>> exceptions, but they're there for you to use as a library, 
>> only if you want to.
>
> Forgoing exceptions in D would be a lot more palatable if we 
> had something like C++'s [[nodiscard]] and Rust's #[must_use]. 
> Currently, if you want to ensure that callers of your function 
> can't ignore errors by accident, your only option in D is to 
> throw an exception.

I agree, it would be nice to be able to express that in D. You 
can sort of emulate it at runtime:

struct MustUse(T)
{
     T payload;
     bool used;

     ref T use() { used = true; return payload; }
     alias use this; //Or, probably better, call use() manually

     ~this() { assert(used, MustUse.stringof ~ " must be used, but 
it wasn't"); }
}

MustUse!string read(File f) { ... }


More information about the Digitalmars-d mailing list