Template instantiation syntax

Tiago Carvalho merlin3000 at gmail.com
Fri Oct 10 17:54:56 PDT 2008


"bearophile" <bearophileHUGS at lycos.com> wrote in message 
news:gcordd$2tdi$1 at digitalmars.com...
> Walter Bright:
>>Most template instantiations are one simple argument.
>
> Probably my code is more general than the average code written in D, so it 
> often contains complex templates, so the statistics for my code may be 
> unusual. From a short survey in my code, it seems about 30-40% of template 
> instantiations have one argument.
>
>
>> Why not?
>
> - Because it's a special case, so it adds complexity to the language. More 
> complexity has to be justified before being added.
> - It has a corner case, that is the nesting of template instantiations. 
> And I don't know if there are other corner cases.
> - Often I have code like:
> if (!IsAA!(Sometype)) ...
> that will became:
> if (!IsAA!Sometype) ...
> The first ! is a negation, and the second is a template instantiation. 
> Maybe it's not ambiguous for the parser, but for my eye it requires a 
> moment to tell their semantics apart. While the Name!(...) is somehow 
> parsed as a single gestalt by my eyes, so I don't mismatch it for a 
> negation much. This may be just a personal thing.

It might be better to use some symbol that is not actually in use. The @ 
suggestion seems to be a better choice for cases like this were first look 
might be ambiguous.

 if( !IsAA@( Sometype ) ) ...
if( !IsAA at Sometype ) ...

At least for me it looks pretty readable and easy to understand.


> - It save little space, just 2 characters (), and they are easy to type, 
> unlike on some keyboards characters like {} and especially ~, that 
> requires ALT+126 to me.
> - The current syntax works :-)
> - I think there are currently more important things to work on for you :-)
> - So for me it's like the ability of removing the () at the end of 
> function calls, it introduces ambiguities for the user without giving back 
> much good. So instead of seeing the () removed from some template 
> instantiations, I'd like to see the () put back as compulsive in function 
> calls :-) And I think there are 5+ persons around here that agree with me 
> on this.
>
>
>> That would seriously damage the compiler's ability to identify,
>> diagnose, and recover from syntax errors correctly.
>
> I presume Scala uses other tricks so solve such problem, then, because it 
> has optional semicolons.
> Anyway, I am not a designer of a very complex language, so if you say so I 
> trust you :-) Even if sometimes I disagree with your opinions, I have high 
> regard for your capabilities and work :-)
>
> Bye,
> bearophile 




More information about the Digitalmars-d mailing list