Regarding the proposed Binray Literals Deprecation

0xEAB desisma at heidel.beer
Sat Sep 10 15:21:50 UTC 2022


On Saturday, 10 September 2022 at 02:22:53 UTC, Walter Bright 
wrote:
> Hex values are far easier to read, too.

“easier to read” is not “easier to comprehend”.
Comprehensibility really depends on the use-case.

But if we assume one’s working with binary flags or something 
similar (which probably was the reason to use binary literals in 
the first place), why would we write them in a different notation?

To give an example:
I can’t translate hex literals to their binary form in my head 
(in reasonable time).

And I never even had to do so – except for an exam or two at 
school.
Wanna know how I did it? – I wrote down the 
`0=0000`…`1=0001`…`F=1111` table…

I understand that “I’ve written binary literals in hexadecimal 
form since 30 years” is a reasonable point of view. But that 
doesn’t really help anyone who doesn’t have the strong mental 
connection between them and their binary meaning.

Writing binary literals using “bitshifting” notation in C didn’t 
provide great readability either. (We did so in the 
microcontroller programming course at school.)
But I’d consider `(1 << 7) | (1 << 1)` way more comprehensible 
than `0x82`.

On the contrary, if our use case is RGB channels (where the 
individual binary bits don’t matter and we instead think in 
“whole” numbers), of course it would be inconvenient to use 
binary literals here. (As always: use the right tool for the job!)

> Have you ever put the tip of your pencil on the screen to count 
> the number of 1's? I have.

No, I haven’t.

Thankfully numeric literals are group-able using underscores (in 
D and binary ones in PHP at least).
I actually find myself rather counting digits of decimal number 
literals (when not using D of course or in real life).

Well, I have to admit I haven’t had to deal with code “abusing” 
binary literals so far…


More information about the Digitalmars-d mailing list