On Tuesday, 10 July 2012 at 09:24:42 UTC, Don Clugston wrote:
On 10/07/12 09:49, renoX wrote:
On Monday, 9 July 2012 at 11:40:37 UTC, Gor Gyolchanyan wrote:
[cut]
You're right. This is a bit advanced code sample, which uses
templates,template constraints, contract programming among syntax
advantages of D.

Hum it show the power of D sure, but IMHO it also show its syntax
deficiencies..

For me this "real[d] bezier(size_t d, Number)(Number[d][] p, Number t) if(d > 1 && isFloatingPoint!Number)" is difficult to read, and a better
syntax would be:
real[d] bezier!(size_t d && d > 1, Number &&
isFloatingPoint!Number)(Number[d][] p, Number t)

The template parameter would be indicated in a !() (as in a call), and the template constraints inside the template parameter: this way the template parameters are clearly indicated and separated from the
function parameter.

renoX

Well it used to work vaguely in that way, but it gets very ugly once you leave the simplest cases. Even that one you've listed is hard for me to read.


IMHO, the "normal" way is even harder to read..


And the idea that constraints apply to individual parameters is wrong. If you have a constraint that depends on two template parameters, where do you put it?

int bezier (int A, int B)(int t) if ( A + B == 10 )


How about:
int bezier!(int A, int B; A + B == 10)(int t) ?

I think that grouping together template parameters and constraints helps the readability YMMV.

BR,
renoX

PS: Sorry for the multiple posting, the posting didn't seem to work so I retried..





Reply via email to