Now that's a DIP that could use some love

Jonathan M Davis newsgroup.d at jmdavisprog.com
Thu Sep 17 21:39:54 UTC 2020


On Thursday, September 17, 2020 2:28:21 PM MDT Andrei Alexandrescu via 
Digitalmars-d wrote:
> On 9/17/20 3:58 PM, H. S. Teoh wrote:
> > On Thu, Sep 17, 2020 at 01:16:13PM -0600, Jonathan M Davis via
> > Digitalmars-d wrote: [...]
> >
> >> Honestly, IMHO, that makes the code far worse. You're just repeating
> >> the constraints in plain English, which requires more than double the
> >> code for each constraint and doesn't really make the error messages
> >> much easier to understand IMHO - especially when the constraints are
> >> already using traits that make what they're doing clear.
> >
> > [...]
> >
> >> It's like commenting every line to say what it does.
> >
> > Exactly, this breaks DRY.
>
> Not at all! What in the world...? The constraint is the mechanics, it
> often says little about the high-level requirements. Granted, sometimes
> the mechanism is simple enough to be sufficiently evocative. But would
> you really like the compiler error messages in terms of the LR step that
> failed?
>
> It's a funny coincidence this thread is going in parallel with a couple
> of other developments:
>
> * `each` has literally inscrutable constraints (I say "literally"
> because their documentation is not visible)
> * `equals` also has nigh unreadable constraints, see
> https://github.com/dlang/phobos/pull/7635/files
>
> If you (cut and) DRY that stuff, I'll eat it.
>
> I found these in literally the first two files I looked at in Phobos.
>
> I can't believe I need to argue this stuff. DRY? No, it's wet like a
> drowned rat.

The problems with each are that it supports too many things and that it uses
private traits in the public constraints. But even then, the actual template
constraints are pretty short, and the traits used are descriptive enough
that I wouldn't expect them to be hard to understand or that repeating them
in English text would help much. Their names are basically just a truncated
version of what I'd expect the English text to say anyway. Where things
really get ugly is all of the static if conditions, but those are internal
and shouldn't affect the user.

Either way, if each really just supported ranges and required that wrappers
or explicit conversions be used for anything else, then the private traits
wouldn't be required in the constraint, and the constraint would be
straightforward.

- Jonathan M Davis





More information about the Digitalmars-d mailing list