Is D painted into a corner?
Lance Bachmeier
no at spam.net
Fri Aug 29 18:44:00 UTC 2025
On Friday, 29 August 2025 at 02:48:21 UTC, H. S. Teoh wrote:
> On Fri, Aug 29, 2025 at 01:52:59AM +0000, Lance Bachmeier via
> Digitalmars-d-learn wrote:
>> On Thursday, 28 August 2025 at 18:47:19 UTC, Brother Bill
>> wrote:
>> > It seems like 'templates' are the 'Achilles heel' of D.
>> >
>> > Without starting a flame war, has D gotten to the point
>> > where ordinary mortals have difficulty coding in D with
>> > 'templates' such as 'cycle' requiring rewrites into
>> > 'myCycle'?
>>
>> Templates are in general a horrible way to program. Therefore
>> I don't use them very much. When I do, I don't do anything
>> complicated. But everyone has their opinion on that. I
>> similarly don't use attributes. I prefer simple code with a
>> simple language. Hard to avoid ranges in Phobos, which can be
>> crazy complex/inconvenient at times, but every language has
>> its warts.
> [...]
>
> Interesting how opinions differ on this. :-D I couldn't live
> without templates. I might be tempted to quit D if I couldn't
> use templates... ;-) but OTOH there are times when templates
> are overused where they aren't actually needed.
Templates are obviously useful in a lot of cases, but I don't
consider them fun to read.
Another thing I don't like is that functions like foo(T)(T x)
throw away relevant information. Then you decide to use a
template constraint, you read the code, and you realize it's
better to write out stubs for the relevant argument types instead.
Classic D code includes types like Matrix!double when you could
just use DoubleMatrix.
They're like macros in Lisp. Powerful in principle but routinely
a PITA when you actually use them. Now, if someone's coming from
C++, the story is different because templates are just how you do
it when you're writing C++. He who writes the most generic code
is the king in that world.
More information about the Digitalmars-d-learn
mailing list