Metaprog can be abstruse

Bastiaan Veelo Bastiaan at Veelo.net
Mon Jul 4 10:19:36 UTC 2022


On Monday, 4 July 2022 at 09:43:11 UTC, user1234 wrote:
> On Monday, 4 July 2022 at 09:40:45 UTC, Bastiaan Veelo wrote:
>> Not necessarily.
>> ```d
>> immutable decimalRanks = iota(10).map!(p => 10.pow(p)).array;
>> ```
>>
>> -- Bastiaan.
>
> Hi, to this alternative I'd say that it's not self documenting.
> So it still has 50% of the initial problem.

I can see your point, but it depends on how used you are to 
reading chains of range algorithms. I read this as "given the 
integers 0 to 9, use them as the powers of ten and put them in an 
array". There is a point to be made that this is more 
self-documenting than the hand-written alternative: Here it is 
obvious that the ranks cover all powers of 10 from 0 to 9 in 
order. In the hand-written alternative you'd either assume that 
is the case, or have to meticulously count all the zero's to be 
sure.

-- Bastiaan.


More information about the Digitalmars-d mailing list