[Proposal]

James Dunne james.jdunne at gmail.com
Fri Jun 16 07:21:44 PDT 2006


Sean Fritz wrote:
> In article <e6u86a$226k$1 at digitaldaemon.com>, Frits van Bommel says...
> 
>>Andrei Khropov wrote:
>>
>>>------------------------------------------------
>>>template(T)
>>>{
>>>	T sqr( T x )
>>>	{
>>>		return x*x;
>>>	}
>>>}
>>>------------------------------------------------
>>
>>[snip]
>>
>>>This syntax also looks familiar to C++ guys ;-).
>>
>>If you're going in that direction, you might want to also make the outer 
>>braces optional in this case, as they don't really add anything.
>>
>>template(T) T sqr( T x )
>>{
>>	return x*x;
>>}
>>
>>I think this would look cleaner, as well as even *more* familiar to 
>>people used to C++.
> 
> 
> I dislike like this as it explicitly introduces the template parameter throught
> the redundant word "template" (this is one of my dislikes of C++ templates - the
> massive code bloat they introduce).  The current syntax:
> 
> 
>>T sqr(T) ( T x )
>>{
>>    return x*x;
>>}
> 
> 
> Is the way Java Generics do it, and there is no problem parsing it, as it also
> explicitly introduces T, but there may be arguments made that sqr(T)(T x) is
> harder to read because it depends on context instead of explicit declaration.
> The context is a bit harder to notice in this case due to using () as template
> delimiters instead of &lt; &gt;.
> 
> Sean
> 
> 

For my own research language I've adopted a mixture of Pascal and D 
syntax and I have to say I really like it:

// Generic function to add two 'T's and return a 'T':
function(T) addtwo(a, b : T) : T
{
	return a + b;
}

You get the 'function' keyword which is a great way to introduce 
additional syntaxes like generics support (T); it also looks readable, 
clear, and concise.  But that is just my opinion.

-- 
James Dunne



More information about the Digitalmars-d mailing list