Metaprog can be abstruse
user1234
user1234 at 12.de
Mon Jul 4 08:24:01 UTC 2022
Example:
```d
auto genDecimalRanks()
{
import std.conv;
auto r = 1;
auto result = "[";
foreach (i; 1 .. 11)
{
result ~= to!string(r);
if (i < 10)
result ~= ", ";
r *= 10;
}
result ~= "]";
return result;
}
/// like
[1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000]
immutable decimalRanks = mixin(genDecimalRanks);
```
It takes much more space and time to write DDOC + the generator
than the space + time required to write the equivalent explicit
declaration without comments, i.e "self documenting".
So metaprog is not the panacea, do you think to that before
"meta-progrogramming", or do you "meta-prog" just because it's
nice ?
More information about the Digitalmars-d
mailing list