template syntax

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Jan 30 20:12:13 UTC 2019


On Wed, Jan 30, 2019 at 07:17:38PM +0000, dronord via Digitalmars-d wrote:
[...]
> Templates are traditional is {} or <>.
> 
> !(exclamation mark) sense/perceive as stop symbol, by my mean.
> 
> < and > is nice construction. May be add it in D?)
[...]

The choice of ! for template instantiation may perhaps be challenged,
but seriously, < and > for templates??!  That's one of the absolutely
worst design choices C++ has ever made, which has made C++ infamous for
being unlexable until it's parsed, not to mention produced utterly
horrific unreadable template syntax.

Take for example this D snippet:

	auto myFunc(alias less, Args...)(Args args) { ... }
	myFunc!((a, b) => a < b)(...);

Try writing the second line with C++'s < and > syntax, and you get the
monstrosity:

	myFunc<(a, b) => a < b>(...);

The real fun begins with nested templates:

	myFunc<nested<(a, b) => xform<(x, y) < z>(a) > xform<(x, y) < z>(b)>>(...);

Now your <'s and >'s have become unreadably ambiguous and virtually
impossible to parse.

With !, it may not look so pretty, but at least it's not ambiguous:

	myFunc!(nested!((a, b) => xform!((x, y) < z)(a) > xform!((x, y) < z)(b)))(...);


Please, let's leave C++'s < > mistake in the dustbins of history. Such
suffering ought not be inflicted upon our future generations.


T

-- 
"Hi." "'Lo."


More information about the Digitalmars-d mailing list