How about a special null template parameter?

poliklosio via Digitalmars-d digitalmars-d at puremagic.com
Sat Aug 20 06:45:59 PDT 2016


On Friday, 19 August 2016 at 18:25:06 UTC, Engine Machine wrote:
> So we can create types relationships easier:
>
> class Type(T) : Type!null
> {
>    int x;
>    static if (T is Dog)
>        int y;
> }
>
> Type == Type!null (!null implicit, only if defined in the above 
> way. Essentially an alias is created for us automatically)

This syntax would be very confusing to a non-expert. It is a 
special case of an existing features (inheritance and templates), 
which makes it hard to learn about, as all resources are going to 
discuss those other features first, and only the most detailed 
readings are going to contain this detail. Moreover, it does not 
introduce a keyword or any other name, so it is almost impossible 
to Google. Try googling something like "template<class T> class a 
class b: public a<b>", and see which result contains "curiously 
recurring template pattern". It is hard to find, isn't it?

Moreover, as indicated by another poster, null is already a valid 
template parameter, making it even more confusing. Also it is 
unclear when the interpretation would be as you propose.

You need to appreciate the difference between write-only code and 
code that can be easily read, reviewed and understood.

Dlang has already went too far in inventing pieces of non-obvious 
syntax for template features. Lets not make the situation worse.

Distill what you want to do, see what use cases are covered by 
other features and libraries, name your thing accordingly and 
then propose.


More information about the Digitalmars-d mailing list