September 09, 2022

On Friday, 9 September 2022 at 16:55:18 UTC, Puneet Goel wrote:

>

Please reconsider binary literal deprecation.

+1

funfact, PHP got them as well:

<?php
var_dump(0b1011);      // int(11)
var_dump(0b0011_1111); // int(63)
September 09, 2022
On Fri, Sep 09, 2022 at 11:10:16PM +0000, 0xEAB via Digitalmars-d wrote:
> On Friday, 9 September 2022 at 16:55:18 UTC, Puneet Goel wrote:
> > Please reconsider binary literal deprecation.
> 
> +1
> 
> funfact, PHP got them as well:
> 
> ```php
> <?php
> var_dump(0b1011);      // int(11)
> var_dump(0b0011_1111); // int(63)
> ```

PHP has all sorts of things I'm not sure is wise to emulate. Just because something is in PHP doesn't make a good argument for including it in D. :-D


T

-- 
A computer doesn't mind if its programs are put to purposes that don't match their names. -- D. Knuth
September 09, 2022
On Friday, 9 September 2022 at 23:04:17 UTC, Walter Bright wrote:
> That's because it's poorly implemented and overly complex. The implementation I showed in my presentation at Dconf is much simpler.

The implementation is awful, but nobody cares enough to fix it since it just isn't that user friendly. It is often less hassle to translate it to binary or hex than to bother moving up, adding the import, then moving back.

However, the newer imported!"std.conv".octal!433 pattern alleviates that somewhat... though it is wordy enough that you then get tempted to make an alias which means moving up again.

> If you're using a lot of octal literals such that this is an issue, one wonders, what for? The only use I know of is for Unix file permissions.

I keep hitting them in random C code I'm translating. Various unix things beyond file permissions and a hardware manual for a think i had to drive (an rfid chip) used them for various bit triplets too.

I often prefer using binary literals anyway, but changing something like 0o50000 to binary is a little obnoxious.
September 09, 2022

On Friday, 9 September 2022 at 18:20:56 UTC, H. S. Teoh wrote:

>

On Fri, Sep 09, 2022 at 05:52:37PM +0000, Max Samukha via Digitalmars-d wrote:

>

On Friday, 9 September 2022 at 16:55:18 UTC, Puneet Goel wrote:

>

[...]

I also oppose dropping binary literals. Although I don't use them often, the few times I do need them I'm very glad they are there. I consider it one of the niceties of D that C missed, and would be rather disappointed if we dropped it. It would be a pain to have to resort to a template just so I can use binary literals.

T

C23 is actually adding binary literals (and you could already use them with gcc and clang). Although I do agree with Walter about how they’re not very useful. They’re only practical for small numbers and at that point just learning what the small hex literals are in binary is not a big deal.

September 09, 2022

On Friday, 9 September 2022 at 23:43:49 UTC, Dave P. wrote:

>

They’re only practical for small numbers and at that point just learning what the small hex literals are in binary is not a big deal.

The nice thing is D lets you group the bits withunderscores.

So you might do like 0b11_111_101_001 which makes it a lot easier to manage and you can group something like a flags register the same way it appears in the documentation.

September 09, 2022
On 9/9/2022 4:43 PM, Adam D Ruppe wrote:
>> If you're using a lot of octal literals such that this is an issue, one wonders, what for? The only use I know of is for Unix file permissions.
> 
> I keep hitting them in random C code I'm translating. Various unix things beyond file permissions and a hardware manual for a think i had to drive (an rfid chip) used them for various bit triplets too.

octal!433 is really not much different from 0433. It could even be shortened to o!433, exactly the same number of characters as 0o433.

The reasons for adding language syntactic sugar:

1. its very commonplace

2. the workarounds are gross

Of course it's a judgement call, and I understand you see them randomly in C code, but does it really pay off? The downside is the language gets bigger and more complex, the spec gets longer, and people who don't come from a C background wonder why their 093 integer isn't 93.

> the newer imported!"std.conv".octal!433 pattern

Nobody would ever write that unless they used octal exactly once, which suggests that octal literals aren't common enough to justify special syntax.


> I often prefer using binary literals anyway, but changing something like 0o50000 to binary is a little obnoxious.

I first implemented binary literals in the 1980s, thinking they were cool and useful. They were not and not. I haven't found a reasonable use for them, or ever wanted them. (I prefer writing them in hex notation, as binary literals take up way too much horizontal space. After all, C3 is a lot easier than 11000011. The latter makes my eyes bleed a bit, too.)

Let's simplify D.
September 09, 2022
On 9/9/2022 4:43 PM, Dave P. wrote:
> C23 is actually adding binary literals (and you could already use them with gcc and clang).

C is regularly adding small window dressing features and not anything that would fundamentally improve the language :-/

> Although I do agree with Walter about how they’re not very useful. They’re only practical for small numbers and at that point just learning what the small hex literals are in binary is not a big deal.

Hex values are far easier to read, too. Have you ever put the tip of your pencil on the screen to count the number of 1's? I have. Binary literals are user unfriendly.
September 09, 2022
On 9/9/2022 4:53 PM, Adam D Ruppe wrote:
> The nice thing is D lets you group the bits withunderscores.

Yes, that is a great feature I copied from Ada, where it had lain forgotten. Now everyone is adding it!

> So you might do like 0b11_111_101_001 which makes it a lot easier to manage and you can group something like a flags register the same way it appears in the documentation.

I haven't seen CPUs that were documented in octal since the PDP-11, even though it didn't quite work with 16 bits. It was a holdover from the 36 bit PDP-10. 8 and 16 bit processors ever since used hex.

BTW, a 0 should go after the b, unless you've got an 11 bit flags register!

It's still easier to write as 0x7E9.
September 10, 2022
On Saturday, 10 September 2022 at 02:17:30 UTC, Walter Bright wrote:
> octal!433 is really not much different from 0433. It could even be shortened to o!433, exactly the same number of characters as 0o433.

You snipped the relevant point about having to change context to add the import. That's objectively not a big deal but subjectively proves to be a barrier to adoption.

(I do think it would be a bit better too if it was `core.octal` instead of `std.conv` so it brings in a bit less baggage too.)

> The downside is the language gets bigger and more complex

The question of bigger languages is with interaction between features. Octal literals are about the most trivial addition you can do since it doesn't interact with anything else.

> and people who don't come from a C background wonder why their 093 integer isn't 93.

This is a completely separate issue that nobody is talking about changing here. While I'd love for it to be good, it is probably practical to keep a deprecation in place so the C programmers can be educated.

> Nobody would ever write that unless they used octal exactly once

This is demonstrably untrue. Local imports are common in D, even when used repeatedly.

> Let's simplify D.

This doesn't achieve anything. If you carry on with this path, you're gonna force a fork of the language. Is that what you want?
September 10, 2022
On Saturday, 10 September 2022 at 02:22:53 UTC, Walter Bright wrote:
> Hex values are far easier to read, too. Have you ever put the tip of your pencil on the screen to count the number of 1's? I have. Binary literals are user unfriendly.

Bzzzzt! Wrong. That is precisely why we allow underscores in integer literals, of any kind.
If you think binary literals are user unfriendly you're using them wrong.