September 30, 2020
On Wed, Sep 30, 2020 at 07:54:39AM +0000, Paolo Invernizzi via Digitalmars-d wrote:
> On Wednesday, 30 September 2020 at 01:36:59 UTC, Mike wrote:
> > On Monday, 28 September 2020 at 19:55:10 UTC, Andrei Alexandrescu wrote:
> > 
> > 1.  Deprecate `alias this` for classes, and implement multiple `alias this` for structs.  That will give users the composition feature they need, and in addition, because structs cannot inherit, it removes the complexity Walter spoke of.
> 
> This!
> 
> We've never used alias this for classes, I'm wondering if there's something like that in Phobos, or in other projects ...
[...]

I haven't used alias on classes either, but I did frequently use alias this on structs that wrap classes. Which may lead to some of the same complexity: struct S implicitly converts to class C which may in turn implicitly convert to base class B or interface I.  But probably not as horrible as using alias this inside a class.


T

-- 
Three out of two people have difficulties with fractions. -- Dirk Eddelbuettel
September 30, 2020
On Wednesday, 30 September 2020 at 12:34:03 UTC, H. S. Teoh wrote:
> On Wed, Sep 30, 2020 at 07:54:39AM +0000, Paolo Invernizzi via Digitalmars-d wrote:
>> On Wednesday, 30 September 2020 at 01:36:59 UTC, Mike wrote:
>> > On Monday, 28 September 2020 at 19:55:10 UTC, Andrei Alexandrescu wrote:
>> > 
>> > 1.  Deprecate `alias this` for classes, and implement multiple `alias this` for structs.  That will give users the composition feature they need, and in addition, because structs cannot inherit, it removes the complexity Walter spoke of.
>> 
>> This!
>> 
>> We've never used alias this for classes, I'm wondering if there's something like that in Phobos, or in other projects ...
> [...]
>
> I haven't used alias on classes either, but I did frequently use alias this on structs that wrap classes. Which may lead to some of the same complexity: struct S implicitly converts to class C which may in turn implicitly convert to base class B or interface I.  But probably not as horrible as using alias this inside a class.
>
>
> T

Indeed, I imagine that's a much simpler case to handle in the compiler.

It would be interesting to have a PR that disable alias this for classes just to have a look on how many external dub projects are impacted by that ...


September 30, 2020
On Wednesday, 30 September 2020 at 12:40:03 UTC, Paolo Invernizzi wrote:
> On Wednesday, 30 September 2020 at 12:34:03 UTC, H. S. Teoh wrote:
>> On Wed, Sep 30, 2020 at 07:54:39AM +0000, Paolo Invernizzi via Digitalmars-d wrote:
>>> On Wednesday, 30 September 2020 at 01:36:59 UTC, Mike wrote:
>>> > On Monday, 28 September 2020 at 19:55:10 UTC, Andrei Alexandrescu wrote:
>>> > 
>>> > 1.  Deprecate `alias this` for classes, and implement multiple `alias this` for structs.  That will give users the composition feature they need, and in addition, because structs cannot inherit, it removes the complexity Walter spoke of.
>>> 
>>> This!
>>> 
>>> We've never used alias this for classes, I'm wondering if there's something like that in Phobos, or in other projects ...

> It would be interesting to have a PR that disable alias this for classes just to have a look on how many external dub projects are impacted by that ...


Right, we just had a discussion last month on the problems I found here:

https://forum.dlang.org/post/pjxwebeyiypgtgxqmcdp@forum.dlang.org

class SharedArray(T) {
  public T[] array;
  alias array this;  // subtyping
}


The point is, these D language features are not well-thought and designed, and when people start to use it and mix with other language features, all kinds of weird corner-case behavior show up and surprise the user.

September 30, 2020
On Wednesday, 30 September 2020 at 12:40:03 UTC, Paolo Invernizzi wrote:

> Indeed, I imagine that's a much simpler case to handle in the compiler.
>
> It would be interesting to have a PR that disable alias this for classes just to have a look on how many external dub projects are impacted by that ...

https://github.com/dlang/dmd/pull/11817
October 01, 2020
On Wednesday, 30 September 2020 at 07:54:39 UTC, Paolo Invernizzi wrote:
> On Wednesday, 30 September 2020 at 01:36:59 UTC, Mike wrote:
>> 1.  Deprecate `alias this` for classes, and implement multiple `alias this` for structs.  That will give users the composition feature they need, and in addition, because structs cannot inherit, it removes the complexity Walter spoke of.
>
> This!
>
> We've never used alias this for classes, I'm wondering if there's something like that in Phobos, or in other projects ...

To be more precise, you don't actually have to deprecated alias this for classes.  You could keep singular alias this for classes and then add multiple alias this for structs.  That may satisfy the "add, don't change" crowd, while still giving users the struct composition features that D currently lacks.
August 05, 2021
On Thursday, 1 October 2020 at 00:40:05 UTC, Mike wrote:
> To be more precise, you don't actually have to deprecated alias this for classes.  You could keep singular alias this for classes and then add multiple alias this for structs.  That may satisfy the "add, don't change" crowd, while still giving users the struct composition features that D currently lacks.

Yes, an extension for structs only seems like a good way to avoid adding edge cases.
Here's a suggestion.
https://forum.dlang.org/thread/uniyvmvjopeyyxmphfso@forum.dlang.org


4 5 6 7 8 9 10 11 12 13 14
Next ›   Last »