Should I stop being interested in D language if I don't like to see template instantiation in my code?

mipri mipri at minimaltype.com
Wed Nov 13 14:23:40 UTC 2019


On Wednesday, 13 November 2019 at 14:01:13 UTC, BoQsc wrote:
> I don't like to see exclamation marks in my code in as weird 
> syntax as these ones:
>> to!ushort(args[1])
>> s.formattedRead!"%s!%s:%s"(a, b, c);

I'd suggest learning to love it, or at least getting to it, vs.
to<ushort>(args[1]) C++ syntax. Template *syntax* benefits are

1. D's is relatively quick to parse.

2. the ! is an attention getter so you can see that some special
action is taking place (although templates don't always require
this). Personally this is more of a comfort ("I'm *definitely*
doing some work at compile-time here, instead of at runtime like
other languages force me to") than an alert ("something weird is
happening!") though.

3. it's very clear what's a compile-time vs. a runtime parameter 
to
the template.

> I'm not sure why, but template instantiation syntax is 
> prevalent in the documentation examples of d lang libraries. It 
> almost seems like every other example contains at least one or 
> two  of them.

Templates are so beneficial that people put up with C++.

D uses them everywhere and if you persist in hating the
syntax you'll just hate a lot of the D syntax that you see.



More information about the Digitalmars-d-learn mailing list