On Wednesday, November 13, 2019 7:01:13 AM MST BoQsc via Digitalmars-d-learn 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'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. > > It look horrible, and I'm feeling like I'm being forced/coerced > to learn from examples that do not provide alternatives to the > template instantiation syntax. Even if the alternative examples > were provided, why would anyone want to have syntax as ugly and > weird as current template instantiation syntax with exclamation > point in the middle of the statement with all other things that > come with it.
D uses !() rather than <>, because it's not ambiguous, allowing for the parser to be context-free (whereas a language like C++ or Java has to actually process the context in order to know whether something like the >> in vector<Tuple<int, float>> is a template instantation or a shift operation; parsing is _much_ cleaner if it can be context-free). D then allows the parens to be dropped when there's only one template argument, which is why you get stuff like s.formattedRead!"" instead of s.formattedRead!(""). Regardless of the syntax though, like C++'s standard library, D's standard library uses templates quite a bit, and it's extremely common for D code in general to use templates. I don't know why you think that using an exclamation point for template instantiations is ugly, but if you can't stand it, you're not going to be happy with D, because you're going to see it quite a lot in typical D code. - Jonathan M Davis