News for hackers. Stuff that matters.
Re:Better C – A subset of D Programming Language by skocznymroczny on Tuesday April 28, 2020 @09:38AM (#23006813)
In D, you don't declare that a type X should have operations A, B, C. Instead, at the moment of template instantiation, you can verify if the provided type has operations A, B and C.
Re:Better C – A subset of D Programming Language by c-cube on Tuesday April 28, 2020 @11:02AM (#23007657)
That makes for terrible docs and discoverability, which is the problem here.

Maybe D should allow the user to name the return type (an existential variable) and static assert stuff on it:

`SomeVar f(…) with isRange!SomeVar` or whatever. `auto` just means "you have to read the implementation because it can be literally anything"

Re:Better C – A subset of D Programming Language by skocznymroczny on Tuesday April 28, 2020 @02:05PM (#23009912)
Well, it is visible in documentation, but even those can be hard to parse:

uint startsWith(alias pred = (a, b) => a == b, Range, Needles...)(Range doesThisStart, Needles withOneOfThese) if (isInputRange!Range && (Needles.length > 1) && is(typeof(.startsWith!pred(doesThisStart, withOneOfThese[0])) : bool) && is(typeof(.startsWith!pred(doesThisStart, withOneOfThese[1..$])) : uint));

Re:Better C – A subset of D Programming Language by gmueckl on Tuesday April 28, 2020 @07:51PM (#23013580)
You did pick a particularly nasty example for that one. I do agree that it is not so easy to read these constraints. It can also be a bit frustrating when you need to chase down why exactly a particular line of code doesn't meet such a constraint. Tests like isInputRange are themselves fairly involved expressions and in the worst case, you end up staring at those after a template instantiation failed.