Why do C++ programmers are not interested in D?

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Sat Nov 23 22:12:27 UTC 2019

On Saturday, 23 November 2019 at 19:35:55 UTC, Mark wrote:
> But in my view it's not clear how far languages should take 
> their MP (metaprogramming) support. D has more MP support than 
> any other statically-typed language that I know of, but even D 
> hasn't taken it to the extreme:
> - It doesn't have AST macros and, as far as I know, there are 
> no plans to ever include them in the language.

Doesn't Nim have AST macros, though?  I haven't gotten around to 
trying Nim yet. Too many new compile-time languages...

> calls. I'm not up to speed on the current limitations of the 
> CTFE engine, but I believe W&A want compilation to be 
> deterministic, and this naturally restricts the operations 
> allowed at compile-time.

Yes, C++ have some more limitations than D, but is fairly close. 
More restrictions seem to be lifted with each version 
(constexpr). Except of course, D allows building code from 
strings. I personally think that is one step to far, and would 
rather have used some kind of limited AST building capability, 
but many people seem to use string mixins. The question remains 
though: are they being used as a last resort or are they used in 
situations where more structured approaches would have been 

One problem with string mixins is that source-to-source 
translation becomes very difficult. So then you cannot really 
improve the syntax, e.g. by machine translating all D2 source 
code to D3 source code(if it ever happens).

So there certainly are downsides to allowing this level of 
metaprogramming (string mixins/AST) in terms of being "forward 
compatible" (which requires the translation program to fully 
"understand" the old sourcecode).

The Go authors put a lot of emphasis on automatic 
source-to-source translation between versions. It will be 
interesting to see if they can keep delivering on that with Go2 
after they get Generics in.

It clearly is a big advantage though, in terms of evolving a 
language over time.

> I can perfectly imagine a C# programmer (even library author) 
> saying "I love generics, extension methods and lambda 
> expressions, but that's good enough for me. I can live without 
> `static if` and a full CTFE engine". That said, it's not like 
> I've done a survey among the C#, Java, C++, Go, Rust, or Swift 
> crowd.

C++ library authors have been using various involved 
template/multiple-inheritance techniques for the same effect. So 
they clearly see the value of being able to do it. And they also 
got "if constexpr" which is a limited version of "static if".

> Maybe most programmers (or at least library authors) in these 
> languages *do* wish for D-level MP support in their language. 
> But that's a question that needs to be investigated; the answer 
> is not obvious at all IMO.

Yeah, well, I want good MP support, but I also want Go-style 
source-to-source translation so that language syntax (and 
semantics) improve over time and isn't locked down forever.

A hard nut to crack perhaps.

More information about the Digitalmars-d mailing list