Here, further down, I just saw Walter indicate his opinion that alias this
is a mistake. Any thoughts?
Thread overview | |||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
August 03, 2021 Is `alias this` a mistake? | ||||
---|---|---|---|---|
| ||||
August 03, 2021 Re: Is `alias this` a mistake? | ||||
---|---|---|---|---|
| ||||
Posted in reply to NonNull | On Tue, Aug 03, 2021 at 03:52:07PM +0000, NonNull via Digitalmars-d wrote: > Here, further down, I just saw Walter indicate his opinion that `alias this` is a mistake. Any thoughts? > > https://news.ycombinator.com/item?id=28029184 This has been discussed many times before. Walter's stance is that it's a mistake because it's essentially another way of implementing subtyping, that has unclear interactions with well-established subtyping mechanisms (OO-style inheritance, in particular). This leads to a cascade of special cases that's hard to understand and adds a lot of complexity to the language for only meager benefits. A secondary reason is that it allows implicit conversions, and Walter has always had a low opinion of implicit conversions, especially the user-defined kind. I used to be a big fan of `alias this`, but after some actual experience with using it in my own code, I've come to agree with Walter more and more that it was a mistake. It's cool for quick hacks to make things work with code designed to receive a different type (and sometimes I still can't resist the temptation to use it), but in the long run it hurts code readability and maintainability. I've come to realize that whenever something in my code demands `alias this` as the answer, it's almost always a symptom of poor code design on my part. My code has often benefitted a lot from being rewritten to *not* need `alias this`. T -- He who sacrifices functionality for ease of use, loses both and deserves neither. -- Slashdotter |
August 03, 2021 Re: Is `alias this` a mistake? | ||||
---|---|---|---|---|
| ||||
Posted in reply to NonNull | On Tuesday, 3 August 2021 at 15:52:07 UTC, NonNull wrote: >Here, further down, I just saw Walter indicate his opinion that
...but it does kind of a crappy job at both. It's very easy to use |
August 03, 2021 Re: Is `alias this` a mistake? | ||||
---|---|---|---|---|
| ||||
Posted in reply to NonNull | On Tuesday, 3 August 2021 at 15:52:07 UTC, NonNull wrote: >Here, further down, I just saw Walter indicate his opinion that Usually inheritance can be replaced with composition and alias this has been the way to do that. Instad of alias this, Walter wants us to use mixin templates for composition. I have no problems with this but the documentation and marketing has totally failed regarding this few seem to know about mixin templates its usage and limitations. The D community needs to be market mixin templates better. |
August 03, 2021 Re: Is `alias this` a mistake? | ||||
---|---|---|---|---|
| ||||
Posted in reply to IGotD- | On Tuesday, 3 August 2021 at 16:34:35 UTC, IGotD- wrote: >On Tuesday, 3 August 2021 at 15:52:07 UTC, NonNull wrote: >Here, further down, I just saw Walter indicate his opinion that Usually inheritance can be replaced with composition and alias this has been the way to do that. Instad of alias this, Walter wants us to use mixin templates for composition. I have no problems with this but the documentation and marketing has totally failed regarding this few seem to know about mixin templates its usage and limitations. The D community needs to be market mixin templates better. This is the first time I'm hearing about this application of mixin templates. Think its possible for someone to write an article on the D blog? I'm interested in seeing this. |
August 03, 2021 Re: Is `alias this` a mistake? | ||||
---|---|---|---|---|
| ||||
Posted in reply to NonNull | On Tuesday, 3 August 2021 at 15:52:07 UTC, NonNull wrote: >Here, further down, I just saw Walter indicate his opinion that The only argument I've heard against alias this is that it can be misused. That's kind of a joke argument in a language that has pointers. |
August 03, 2021 Re: Is `alias this` a mistake? | ||||
---|---|---|---|---|
| ||||
Posted in reply to bachmeier | On Tuesday, 3 August 2021 at 17:18:48 UTC, bachmeier wrote: >On Tuesday, 3 August 2021 at 15:52:07 UTC, NonNull wrote: >Here, further down, I just saw Walter indicate his opinion that The only argument I've heard against alias this is that it can be misused. That's kind of a joke argument in a language that has pointers. Fyi, 'alias this' nicely fits for doing auto unboxing of a wrapper type into wrapped type, similar to how java does unboxing of primitives, not sure that it will be possible with mixin templates. |
August 04, 2021 Re: Is `alias this` a mistake? | ||||
---|---|---|---|---|
| ||||
Posted in reply to NonNull | On Tuesday, 3 August 2021 at 15:52:07 UTC, NonNull wrote: >Here, further down, I just saw Walter indicate his opinion that
Where My suggestion has been to deprecate (or at least discourage) More on that can be read at https://forum.dlang.org/post/vggskphkqxtriqnavmnf@forum.dlang.org |
August 04, 2021 Re: Is `alias this` a mistake? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paul Backus | On Tuesday, 3 August 2021 at 16:24:26 UTC, Paul Backus wrote: >On Tuesday, 3 August 2021 at 15:52:07 UTC, NonNull wrote: >Here, further down, I just saw Walter indicate his opinion that
...but it does kind of a crappy job at both. It's very easy to use I use alias this for implicit conversion between reference and value type. It's not really subtyping and not really type conversion and works fine without humongous amounts of metaprogramming. |
August 04, 2021 Re: Is `alias this` a mistake? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike | On Wednesday, 4 August 2021 at 00:29:21 UTC, Mike wrote: >My suggestion has been to deprecate (or at least discourage) It might be useful to allow More on that can be read at https://forum.dlang.org/post/vggskphkqxtriqnavmnf@forum.dlang.org Thanks. |