Metaprog can be abstruse
Dom Disc
dominikus at scherkl.de
Mon Jul 4 13:03:55 UTC 2022
On Monday, 4 July 2022 at 10:19:36 UTC, Bastiaan Veelo wrote:
> 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;
>>> ```
>> Hi, to this alternative I'd say that it's not self documenting.
>> So it still has 50% of the initial problem.
> 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.
This advantage becomes much more clear in, let's say:
```d
immutable long powersOfThree = iota(27).map!(p => 3.pow(p)).array;
```
Handwritten this is a very long chain of arbitrary numbers and
you have to put a very close look, that those are indeed the
powers of three.
More information about the Digitalmars-d
mailing list