Regarding the proposed Binray Literals Deprecation
Steven Schveighoffer
schveiguy at gmail.com
Sun Sep 11 23:00:05 UTC 2022
On 9/11/22 3:20 PM, Walter Bright wrote:
> On 9/10/2022 12:00 PM, Steven Schveighoffer wrote:
>> https://github.com/schveiguy/poker/blob/master/source/poker/hand.d#L261
>>
>> This was so much easier to comprehend than the equivalent hex.
>
> assert(beststraight(0b10000000011110) == Rank.Five);
> assert(beststraight(0b10101111111110) == Rank.Ten);
>
> Are you sure the number of digits is correct? Does your card deck really
> have 14 cards in a suite? :-)
Not really relevant, but yes. I have 2 aces, one called `Ace`, and one
called `LowAce`. When checking for a straight, and an ace is present,
it's copied to the `LowAce` spot as well (A-2-3-4-5 is a straight as
well), because all I'm doing is searching for 5 consecutive bits.
I'm actually quite proud of the bit shifting code, I tried to find the
most efficient/clever mechanism to test for a straight given a bitfield.
Once I thought of it, it was simple to implement and understand:
https://github.com/schveiguy/poker/blob/6f70cf7ca74e19e78b470f81640a3ce34a95d0d3/source/poker/hand.d#L245-L256
>
> Me, annoying curmudgeon that I am, would write a little parser so I
> could write such tests as:
>
> assert(beststraight(hand!"A234567890JQK") == Rank.Five);
Sure, that's already there. but it's perfectly understandable with the
bit pattern as well. And I don't need to test the parser with this
unittest, just the function I'm testing.
Every unit test should test the smallest amount possible (sometimes it's
unavoidable to pull in more) to avoid coupling between parts of the code.
> and use HCDS for Hearts, Clubs, Diamonds, and Spaces.
>
> D is ideal for creating such micro-DSLs, such as this one:
e.g.:
https://github.com/schveiguy/poker/blob/6f70cf7ca74e19e78b470f81640a3ce34a95d0d3/source/poker/hand.d#L70-L73
Note that when I'm testing the higher-level functions, I do use this:
https://github.com/schveiguy/poker/blob/6f70cf7ca74e19e78b470f81640a3ce34a95d0d3/source/poker/hand.d#L461
> which makes adding test cases for the disassembler dramatically easier
> to read and compose.
>
Again, the test is easy to compose and understand -- because it's in binary.
The whole No True Scotsman line of argument is not convincing.
-Steve
More information about the Digitalmars-d
mailing list