What are the prominent downsides of the D programming language?

H. S. Teoh hsteoh at quickfur.ath.cx
Tue Sep 29 16:57:52 UTC 2020


On Tue, Sep 29, 2020 at 04:11:29PM +0000, Dukc via Digitalmars-d wrote:
[...]
> -Using templates and defining simple ones is easy and tidy. But
> defining really good templates tends to get difficult. Look at Phobos
> source code: complex template constraints.
[...]

IMO, overly-complex and opaque sig constraints is a sign that the
template was not properly designed. A lot of the complex constraints in
Phobos leak implementation details and really should belong in static
ifs inside the function body.  This malady is often accompanied by an
excessive number of overloads of the template function, many of which
have no obvious reason why they are separate overloads, the reason
having to do with implementation details that the user really shouldn't
need to see or know about.

Properly-written sig constraints should be very straightforward and
simple to understand -- it should accept all types in the class of
logically-acceptable types.  Any types in that class that cannot be
accepted due to implementation details or case-specific reasons really
should be handled by static asserts in the function body, accompanied by
a message explaining why that type cannot be used -- rather than
obscure, unreadably complex sig constraints that, when they fail,
generate equally obscure, unreadably-long template-not-matched error
messages.


T

-- 
Those who've learned LaTeX swear by it. Those who are learning LaTeX swear at it. -- Pete Bleackley


More information about the Digitalmars-d mailing list