Rebind template(bug?)

Engine Machine via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Aug 22 11:54:05 PDT 2016


On Monday, 22 August 2016 at 18:48:12 UTC, ag0aep6g wrote:
> On 08/22/2016 08:04 PM, Engine Machine wrote:
>> How do you seriously think this is cleaner/simpler? You have 
>> two
>> classes. Their is no uniformity between them. You have 
>> uniformity
>> between all the derived classes then have a special case for 
>> the base
>> class. A certain easy to follow pattern is set up but 
>> needlessly break
>> it for one case. Why?
>
> It avoids the relatively obscure (and badly named, by me) 
> InstantiateOrEmptySeq template.
>
> You can take this further with template constraints. Gives it a 
> more uniform appearance at the price of some repetition:
>
> ----
> class T()
> {
>     int x;
> }
>
> class T(A...) : T!(A[0..$-1])
>     if (A.length > 0 && A[$-1] == "Animal")
> {
>     int y;
> }
>
> class T(A...) : T!(A[0..$-1])
>     if (A.length > 0 && A[$-1] == "Dog")
> {
>     int z;
> }
>
> class T(A...) : T!(A[0..$-1])
>     if (A.length > 0 && A[$-1] == "Pug")
> {
>     int s;
> }
> ----
>
> I wouldn't say that this is obviously, objectively, 
> significantly better than the version with the helper template, 
> though.
>

Yeah, but a name means nothing. Change it if you want ;)


> By the way, it's not obvious to me what this whole thing 
> achieves in practice. And whatever benefit there is, it has to 
> be weighed against the cost of the added complexity.

What it achieves is a uniform way to create a hierarchical 
relationship without excessive verbosity. Now, the static ifs are 
probably the most verbose part, a static switch would help:

static switch (A)
{
    case "Animal":
    return;
    ...
}


But only slightly.

> I don't mean to say that this is not worth pursuing. Just a 
> friendly reminder that over-engineering is something to look 
> out for, from someone who is prone to over-engineering himself.


Ultimately it is just syntax, it does nothing over what D already 
does. It doesn't create anything new. In some cases it 
simplifies. If it does, then great, if it doesn't then don't use 
it. While I would prefer a totally different syntax, I also like 
to keep things organized. Having multiple classes floating around 
for certain things is just not needed so there should be an 
option.




More information about the Digitalmars-d-learn mailing list