November 01, 2021
On Monday, 1 November 2021 at 08:15:55 UTC, Araq wrote:
> What? Pattern matching doesn't scale/nest well because you think it's like try-catch? That's major news to all C#, F#, ML, Ocaml, Rust, Swift, Elixir programmers...

It scales, but how do you know if you remembered to test all types? If you forgot one, you'll get a runtime-crash. So you need something more powerful, something that can statically verify that you cover all relevant types (like a formalization of a set of types).

Then again, I am not really sure how often you need to test more than a handfull types in a well designed program, in which case if-then-else is sufficient…

November 01, 2021
On 11/1/21 3:45 AM, Bruce Carneal wrote:

> It seems Sean Baxter's
> "circle" C++ compiler is opening some eyes.

I haven't watched the video yet.

However, I had the privilege of having Sean Baxter as my only guest on one my D meetups. I had attended a C++ meetup where Sean introduced Circle. Basically, almost everything in Circle was already in D. Interestingly, he hadn't heard about D. So, he came to my meetup the next day. He may have found a couple of new things in D that Circle did not have.

> A quick scan produced an older critique of circle wrt another C++
> proposal:
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p2062r0.pdf.
> Those authors seem to embrace crippling, IMO, scope restrictions that
> circle does not.

Andrew Sutton happens to be one of the authors of an infamous paper:

  http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3613.pdf

That paper deprived C++ programmers of 'static if' for 8 years and counting. I am sure they will eventually come up with something better many years from now.

I see their behaviour as undervaluing engineering. I think D and Circle are great engineer tools but C++ is seeking some kind of perfection. For example, yes, 'static if' can be shown to have problems and shortcomings but it is an incredibly useful and succesful feature.

(Aside: There was another paper written years prior by known C++ personalities, proving "iterators are a better abstraction compared to ranges." (I can't find that paper anymore.) Ok, good proof! You go that way, and I will continue with my getting things done with ranges.)

Ali

November 01, 2021
On Monday, 1 November 2021 at 08:15:55 UTC, Araq wrote:
> On Monday, 1 November 2021 at 00:20:33 UTC, Andrei Alexandrescu wrote:
>> I think it's relevant to our recent discussion on versioning, and also for its considerations on language design.
>>
>> https://youtube.com/watch?v=raB_289NxBk
>>
>> P.S. Destruction comes at https://youtu.be/raB_289NxBk?t=4727 :o)
>
> What? Pattern matching doesn't scale/nest well because you think it's like try-catch? That's major news to all C#, F#, ML, Ocaml, Rust, Swift, Elixir programmers...

Andrei is perfectly correct on this IMO, and it's telling that both you and Herb dodged the complaint in the exact same way by invoking an argument from authority (or maybe analogy?) - "Well these other successful languages do it so it must be okay".

Herb goes one further and dismisses Andrei's rebuttal - that even if these other languages use pattern matching successfully, C++ does a lot of things differently and thus the (fallacious IMO) argument that other languages do this doesn't really hold up - with a pretty weak "we'll have to wait and see how it goes".

Not that I'm ascribing any intentional malice or desire to ignore Andrei's complaint to Herb's reponse, but I think he dismissed it a little too easily given that even in my own personal experience, writing nested match (and nested try-catch) statements is ugly, messy, and an enormous pain that really limits how often I reach for them.

That being said, I am a huge proponent of more "syntactically light" pattern matching features in a language as they can really make for some concise and powerful code.
November 01, 2021
On Monday, 1 November 2021 at 18:38:05 UTC, Meta wrote:
> Herb goes one further and dismisses Andrei's rebuttal - that even if these other languages use pattern matching successfully, C++ does a lot of things differently and thus the (fallacious IMO) argument that other languages do this doesn't really hold up - with a pretty weak "we'll have to wait and see how it goes".
>

I don't think Herb dodged.

It is right to look at what is successful in other languages. The fact something is successful in so many languages is a data point that cannot, and shouldn't, be ignored.

However, Andrei is right when he point that there is a category of use case, typically in generic code, that is not well served by current mechanisms. This is not a problem in most language because C++ (and D), differs significantly in their approach there.

You'll note that there are example in Herb's presentation that are also not well served by current D constructs, notably cascading match clauses. They ends up being done with very repetitive and error prone template constraints in D.
November 01, 2021
On 11/1/2021 6:39 AM, Andrei Alexandrescu wrote:
> Maybe because he's just the best technical speaker ever.

I agree with that. Herb is just amazing.
November 01, 2021
On 11/1/2021 9:18 AM, deadalnix wrote:
> This part IMO, point at what the #1 problem with the way things have been done in D. D's feature just don't compose well because they aren't orthogonal with each other (and many are inconsistent).

Can you be more specific?

Some examples of consistency in D:

1. basic types, structs, and arrays are interchangeable. But I couldn't add tuples to the list, because the function call ABI for structs is "special". Urgh.

2. The nature of how const, immmutable, and shared are applied to types is completely consistent, despite many requests to change that.

4. The way scope & return & ref apply to types is completely consistent. This enables me to advise that when people have problems understanding it, to rewrite their example code in terms of raw pointers, as it will behave the same.

A counter-example:

The original symbol lookup mechanism was completely consistent. It behaved exactly the same way for all scoped declarations.

However, I was the only one who felt that way. I was never even able to get anyone to even *concede* that it was consistent, but they didn't like it that way. What we have today is special case two-pass lookup, with special handling for imports.
November 01, 2021
On 2021-11-01 17:41, Walter Bright wrote:
> On 11/1/2021 9:18 AM, deadalnix wrote:
>> This part IMO, point at what the #1 problem with the way things have been done in D. D's feature just don't compose well because they aren't orthogonal with each other (and many are inconsistent).
> 
> Can you be more specific?
> 
> Some examples of consistency in D:

There are easily found counterpoints even to your examples.

> 1. basic types, structs, and arrays are interchangeable. But I couldn't add tuples to the list, because the function call ABI for structs is "special". Urgh.

1a. Hash tables have a number of language magic hacks (particularly concerning keys that have statically-sized array types) that are thoroughly inconsistent with the language rules.

> 2. The nature of how const, immmutable, and shared are applied to types is completely consistent, despite many requests to change that.

2a. Hash tables have any number of qualifier-related hacks that makes them impossible to implement as a library.

2b. Calls to built-in arrays remove the top-level qualifier in a way that is not accessible to user code. This makes qualified ranges impossible to implement:


void fun(T)(T data) {
	import std;
    writeln(T.stringof);
}

void main() {
    immutable int a = 42;
    immutable int[] b = [ 69 ];
    fun(a);  // fine, prints immutable(int)
    fun(b);  // prints immutable(int)[], not immutable(int[])
}

2c. There are a number of hacks in the compiler that give special treatment to shared numerics. Such is inaccessible to user code. Worse, they don't generate correct code.

void main() {
    shared int i = 42;
    i = i + 2;  // whatta?
}

> 4. The way scope & return & ref apply to types is completely consistent. This enables me to advise that when people have problems understanding it, to rewrite their example code in terms of raw pointers, as it will behave the same.

I very much wish this is true and useful.
November 01, 2021

On Monday, 1 November 2021 at 22:02:26 UTC, Andrei Alexandrescu wrote:

>

On 2021-11-01 17:41, Walter Bright wrote:

>
  1. The way scope & return & ref apply to types is completely consistent. This enables me to advise that when people have problems understanding it, to rewrite their example code in terms of raw pointers, as it will behave the same.

I very much wish this is true and useful.

It's true, as far as it goes. return and scope are consistent in the way they apply to types.

However, ref is not part of the type system--and when you add ref into the mix, that's when you start to see the special cases cropping up (see e.g. Dennis's thread on the inconsistency of return scope).

November 01, 2021
On Monday, 1 November 2021 at 16:26:47 UTC, Ola Fosheim Grøstad wrote:
> On Monday, 1 November 2021 at 08:15:55 UTC, Araq wrote:
>> What? Pattern matching doesn't scale/nest well because you think it's like try-catch? That's major news to all C#, F#, ML, Ocaml, Rust, Swift, Elixir programmers...
>
> It scales, but how do you know if you remembered to test all types? If you forgot one, you'll get a runtime-crash. So you need something more powerful, something that can statically verify that you cover all relevant types (like a formalization of a set of types).

Note to those not familiar with it, this is frequently called exhaustiveness checking.
November 01, 2021
On Monday, 1 November 2021 at 13:23:45 UTC, Arjan wrote:
> On Monday, 1 November 2021 at 00:20:33 UTC, Andrei Alexandrescu wrote:
>> I think it's relevant to our recent discussion on versioning, and also for its considerations on language design.
>>
>> https://youtube.com/watch?v=raB_289NxBk
>>
>> P.S. Destruction comes at https://youtu.be/raB_289NxBk?t=4727 :o)
>
> Why is it that always when I see Herb Sutter talk about C++, that long lost love for C++ suddenly re-emerges from the deep hurt past relationship...

The same goes for Bjarne S, but then I open a C++ file in my text editor and images of Scott Meyers take over my brain.