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

Dukc ajieskola at gmail.com
Wed Nov 13 14:59:57 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);

No pressure to use templates. D is designed to be multi-paradigm, 
and in many was combines the advantages of c++ and c# even if you 
use just traditional imperative or object oriented ways. For 
example, C# has array bounds checking, C++ has raw type casting, 
but D has both. And neither of the mentioned languages have 
`scope (exit`. Granted, some other new language, like Go, might 
be even better if you don't care about templates.

That being said, I think you definitely should learn about 
templates. First, it let's you understand code written by others, 
and secondly you can evaluate whether you really want to code 
without them. There are problems you simply cannot deal with as 
efficiently as you can with templates. For example, if you write 
a math function you want to work with both integers and floats, 
you basically have four options:

1: Code duplication.
2: Runtime casting of the argument to the type the function is 
implemented in, wasting computational power. Traditional 
object-oriented solution falls in this category.
3: Using a macro preprocessor. Macros are unaware of code 
semantics and thus are known for making codebases buggy and hard 
to maintain.
4: Templates. Same code size bloat as with options 1 and 3, but 
otherwise basically no downsides.


More information about the Digitalmars-d-learn mailing list