Why is D unpopular?
Ola Fosheim Grøstad
ola.fosheim.grostad at gmail.com
Fri May 6 07:20:20 UTC 2022
On Friday, 6 May 2022 at 05:58:37 UTC, Siarhei Siamashka wrote:
> On Thursday, 5 May 2022 at 23:06:26 UTC, Walter Bright wrote:
>> It was D that changed that perception. Suddenly, native
>> languages started implementing CTFE.
>
> Is CTFE really that useful? Generating code as a part of the
> build process has been in use since a very long time ago. Any
> programming languages (perl, python, php, ...) or tools (bison,
> flex, re2c, ...) could be used for this.
I find it to be useful for parametric types that initialize
constant tables. If the program does constant lookups those
values can be turned into constants known at compile time. Or
like in the example I gave further up where you compute the
length of delay lines at compile time so that you can make sound
effects allocation free.
In general CTFE would be most powerful in combination with AST
manipulation to construct new types. D uses string mixins for
this puropose which is macro-like in nature, so this partcular
use case for CTFE is macroish IMHO.
For code gen I actually think having a Python script can lead to
more readable code, because then you see the generated code as
part of your program and debugging is straight forward. Such code
is seldom modified in my experience so I sometimes just inline
the Python script as a comment.
So overall, for me CTFE is most useful for computing constants.
More information about the Digitalmars-d
mailing list