Better error messages - from reddit

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Mar 4 17:19:32 UTC 2019


On Mon, Mar 04, 2019 at 04:49:25PM +0000, Sebastiaan Koppe via Digitalmars-d wrote:
> On Monday, 4 March 2019 at 15:47:12 UTC, H. S. Teoh wrote:
> > This is why I'm starting to think sig constraints are not the genius
> > idea they first appeared to be. The basic problem is that when you
> > write a sig constraint, you're basically saying "I only accept
> > template arguments if they don't cause an error, otherwise it's not
> > my problem and somebody else can pick up the tab", whereas the
> > essence of user-friendly error-reporting is "I accept everything
> > that looks like it ought to work, and if something breaks, I'll tell
> > you why it didn't work".
> 
> It's even worse. There might be another sig constraint that is
> perfectly happy. It might even be in another library. Your function
> has no way to know that. Ergo, error messages are hard.

Yep.  This can be good or bad: allowing this flexibility *can* mean that
the other library can extend your function without you needing to be
involved.

Of course, this flexibility comes at a pretty steep price.


> With Rust a type declares to conform to a trait explicitly. Error
> messages are easy.
> 
> With D it seems we are reinventing traits, poorly. And all because we
> wanted to avoid naming them?

No, I think the original reasoning was that allowing arbitrary boolean
clauses in sig constraints is more expressive than allowing only a
subset of expressions (e.g., implementsTrait!T).  It's necessarily not
wrong per se, but the extra expressive power does come at a price. And
we've been paying for it over and over.

It's just like the tradeoff between stack machines and Turing machines.
Turing machines are powerful enough to express anything you might want
to compute, but it comes at the price that certain seemingly-simple
things become undecidable. If you're willing to give up a certain degree
of expressiveness, you can eliminate (some of) the undecidable problems.


T

-- 
Today's society is one of specialization: as you grow, you learn more and more about less and less. Eventually, you know everything about nothing.


More information about the Digitalmars-d mailing list