September 17, 2022

On Saturday, 17 September 2022 at 21:57:41 UTC, Preetpal wrote:

>

On Saturday, 17 September 2022 at 21:39:59 UTC, Walter Bright wrote:

>

On 9/17/2022 10:22 AM, Loara wrote:

>

The point is that a lot of people comes from C/C++ and they're used to use binary literals

Not really. C11 doesn't have binary literals. C++ added them quite recently.

FWIW, C#, Java, JavaScript, Python and Ruby all have binary literals.

Also, Emacs Lisp, Fortran, Go, Haskell, OCaml and Rust. It's hard to find a language without this feature (every single language that came to mind had it).

September 18, 2022

On Saturday, 17 September 2022 at 20:09:02 UTC, 0xEAB wrote:

> > >

People often complain that D has too many features.

Do they really complain about “too many features”?

There’s also an essential difference between “too many features available” and “too many unfinished features WIP” (shared, DIP1000, @live, importC, … to name a few)

I don't complain that D has too many features.
I complain that D has too many
unfinished features.

September 18, 2022

On Wednesday, 14 September 2022 at 05:58:53 UTC, Walter Bright wrote:

>

On 9/13/2022 7:56 PM, Steven Schveighoffer wrote:

>

But it doesn't disprove the fact that sometimes, hex digits aren't as clear.

Does sometimes justify a language feature, when there are other ways?

People often complain that D has too many features. What features would you say are not worth it?

extern(C++, ns)

It is never what you want (that would be extern(C++, "ns")).

It is never what you want because, unless the entire namespace is contained within a single module, modA.ns is not the same thing as modB.ns and to "fix" it you have to add a bunch of cross-referencing aliases. It leads to terrible non-sensical errors and error messages without the aliases.

Also it blocks string expressions for StdNamespace (being either "std" or "std::__cxx11" or whatever it is) "just working" (you need to do, extern(C++, (StdNamespace)) to get what you actually want).

September 18, 2022
On Saturday, 17 September 2022 at 21:39:59 UTC, Walter Bright wrote:
> On 9/17/2022 10:22 AM, Loara wrote:
>> The point is that a lot of people comes from C/C++ and they're used to use binary literals
>
> Not really. C11 doesn't have binary literals. C++ added them quite recently.

That's right -- binary literals are not part of the official C language, not now (as defined by C11) and not in the past. The language, as described in the second edition of K&R (1988), does not have them. Nor do they appear in the fifth edition of Harbison and Steele.

But compilers such as gcc and clang add them as an extension and the working draft of C2x does include them.

So while using C's history and current state as an example of why D ought to have binary literals is a non-existent argument, C++ recently added them, as you said, and C seems to be heading the same way.





September 18, 2022

On Saturday, 17 September 2022 at 22:11:35 UTC, Preetpal wrote:

>

On Saturday, 17 September 2022 at 21:57:41 UTC, Preetpal wrote:

>

[...]

Also, Emacs Lisp, Fortran, Go, Haskell, OCaml and Rust. It's hard to find a language without this feature (every single language that came to mind had it).

Haskell does not have binary integer literals. See the 2010 language report and

Prelude> 0x10
16
Prelude> 0o10
8
Prelude> 0b10

<interactive>:8:2: error: Variable not in scope: b10
September 18, 2022

On Sunday, 18 September 2022 at 01:55:35 UTC, Don Allen wrote:

>

On Saturday, 17 September 2022 at 22:11:35 UTC, Preetpal wrote:

>

On Saturday, 17 September 2022 at 21:57:41 UTC, Preetpal wrote:

>

[...]

Also, Emacs Lisp, Fortran, Go, Haskell, OCaml and Rust. It's hard to find a language without this feature (every single language that came to mind had it).

Haskell does not have binary integer literals. See the 2010 language report and

Prelude> 0x10
16
Prelude> 0o10
8
Prelude> 0b10

<interactive>:8:2: error: Variable not in scope: b10

"The language extension BinaryLiterals adds support for expressing integer literals". So you need to use a language extension to use it.

ps@DESKTOP:~$ ghci
GHCi, version 8.8.4: https://www.haskell.org/ghc/  :? for help
Prelude> :set -XBinaryLiterals
Prelude> 0b0010
2
Prelude>
September 18, 2022
On 14.09.22 21:34, Walter Bright wrote:
> On 9/12/2022 7:48 AM, jmh530 wrote:
>> I don't recall anyone mentioning the removal of complex/imaginary numbers, but the issues are the same.
> 
> I was surprised at the pretty much non-existent pushback on removing them, even though it did carry with it the loss of the convenient syntax for them.
> 

I will always miss "creal". It was the most humorous D keyword.
September 18, 2022

On Saturday, 17 September 2022 at 19:38:52 UTC, 0xEAB wrote:

>

I fail to see the value of such a flag. If there were no plan to remove or deprecate them, why issue a warning in the first place?!

There’s nothing wrong with binary literals (as in potential pitfalls), isnt’t there?

Because it seems that some people really needs binary literals and can't work without them although there are many higher level alternatives.

Binary literals aren't efficient (too many digit to represent relatively small numbers) and aren't essential to the language itself (hex literals are far more efficient). If you need to set flags an enum approach makes code much more readable:

enum MyFlag {A = 0, B, C}

T asFlag(T)(in T f) pure @safe nothrow @nogc{
  return (1 << f);
}

...

int field = MyFlag.A.asFlag & MyFlag.B.asFlag;
September 18, 2022

On Sunday, 18 September 2022 at 11:00:12 UTC, Loara wrote:

>

Because it seems that some people really needs binary literals and can't work without them although there are many higher level alternatives.

Yes, we need them because they have use cases where alternatives are not justifiable. For example, we have a simple communication protocol that defines just a handful of commands with additional information encoded in the bits (command length, flags, etc). It would be unreasonable to complicate the code with bit ops, parsers, etc., which would make it less readable. Having to replace the literals with bin!... would be tolerable, though.

September 18, 2022

On Sunday, 18 September 2022 at 04:26:45 UTC, Preetpal wrote:

>

On Sunday, 18 September 2022 at 01:55:35 UTC, Don Allen wrote:

>

On Saturday, 17 September 2022 at 22:11:35 UTC, Preetpal wrote:

>

[...]

Haskell does not have binary integer literals. See the 2010 language report and

Prelude> 0x10
16
Prelude> 0o10
8
Prelude> 0b10

<interactive>:8:2: error: Variable not in scope: b10

"The language extension BinaryLiterals adds support for expressing integer literals". So you need to use a language extension to use it.

ps@DESKTOP:~$ ghci
GHCi, version 8.8.4: https://www.haskell.org/ghc/  :? for help
Prelude> :set -XBinaryLiterals
Prelude> 0b0010
2
Prelude>

An extension offered by one compiler, off by default, is not the same as inclusion in the official language definition. The official Haskell language does not include binary literals.