dropping parentheses on template instantiation

Bent Rasmussen IncredibleShrinkingSphere at Gmail.com
Sun Oct 5 14:22:38 PDT 2008


I somewhat dislike @; but the reason why it is liked is maybe that it looks 
like a 1-slice into a theoretical type array.

It was (and maybe still is) possible to use @ as array index infix operator 
in Eiffel, i.e. a at i, but this is maybe an example of syntax compression 
moved one step too far.

Some comparisons

    Matrix!(real)(n,n);
    Matrix at real(n,n);
    Matrix[real](n,n);
    Matrix(real)(n,n);

D code has already improved syntax uniformity; adorably

    pure A[] mid(A)(A[] a, A[] b)

- Bent

"Andrei Alexandrescu" <SeeWebsiteForEmail at erdani.org> skrev i meddelelsen 
news:gcb2a2$1d0e$2 at digitalmars.com...
> Denis Koroskin wrote:
>> On Sun, 05 Oct 2008 22:18:26 +0400, Andrei Alexandrescu 
>> <SeeWebsiteForEmail at erdani.org> wrote:
>>
>>> I just realized something different. After making an informal review of 
>>> some code, I saw that a large percentage of template instantiations only 
>>> need ONE argument.
>>>
>>> This makes me think, with the old "!" notation, parentheses could be 
>>> dropped entirely without prejudice:
>>>
>>> auto covariance = Matrix!real(n, n);
>>> auto normalized = SparseVector!double(n);
>>>
>>> and so on.
>>>
>>> To the unbridled joy of the enemies of the Sad Pirate, the dot won't 
>>> work for template instantiation because without the parentheses it DOES 
>>> engender ambiguity.
>>>
>>> Now say we take the following route:
>>>
>>> 1) We find something different from shouting
>>>
>>> 2) We drop the parentheses for 1 argument
>>>
>>> That sounds like a possible winner. In this case the "#" becomes 
>>> considerably more attractive, in fact very attractive exactly because it 
>>> looks unlike any letter:
>>>
>>> auto covariance = Matrix#real(n, n);
>>> auto normalized = SparseVector#double(n);
>>>
>>> Ideas?
>>>
>>>
>>> Andrei
>>>
>>> P.S. The Sad Pirate is the emoticon
>>>
>>> .(
>>>
>>> It doesn't have an eye and is sad, too.
>>
>> Just to clarify things: Do you propose moving the first template argument 
>> outside of the parentheses *or* ditching them iff there is only one 
>> parameter? I mean, what does the original code look like, because there 
>> is ambiguaty in your statement (to me):
>
> Ditch parens if there's only one argument. In that case the extra 
> character becomes an enabling asset, not a liability.
>
>> const int n = 42;
>> auto covariance = Matrix!(real, n, n); <-> auto covariance = 
>> Matrix#real(n,n);
>>
>> *or*
>>
>> auto covariance = Matrix!(real)(n, n); <-> auto covariance = 
>> Matrix#real(n,n);
>
> The latter.
>
>> Other than that Vector at real or Vector#real both sound good!
>
> I agree. In fact "Vector at real" sounds like a good way of talking about 
> templates instead of "Vector instantiated with real". One reason for which 
> I think "this" is a poor choice (as opposed to e.g. "self") is that it's 
> very hard to talk about it.
>
>> (BTW, don't start new thread by repling to some other one, please)
>
> Just trying to keep various juice flavors separate. :o)
>
>
> Andrei 




More information about the Digitalmars-d mailing list