Template instantiation syntax

Benji Smith dlanguage at benjismith.net
Fri Oct 10 22:54:32 PDT 2008


bearophile wrote:
> 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 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

I think it's funny that, in the same post, you argue against optional 
parentheses while arguing for optional semicolons.

--benji



More information about the Digitalmars-d mailing list