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.
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:
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.