February 22, 2013 Re: What happened to the alias this = identifier syntax in 2.062? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Joshua Niehus | On 02/23/2013 12:10 AM, Joshua Niehus wrote:
> On Friday, 22 February 2013 at 21:23:04 UTC, Timon Gehr wrote:
>> [snip].. or the alias this syntax should be deprecated in favour of a
>> specially named member function.
>
> pseudonym foo;
>
>
auto opPseudonym() { ... }
alias opPseudonym=foo;
| |||
February 22, 2013 Re: What happened to the alias this = identifier syntax in 2.062? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | On Friday, 22 February 2013 at 23:20:55 UTC, Timon Gehr wrote:
>
> auto opPseudonym() { ... }
>
> alias opPseudonym=foo;
Isn't that creating multiple functions for the same thing?
<shamelessly copies Ali's example>
struct Fraction
{
long numerator;
long denominator;
double value() const @property
{
return cast(double)numerator / denominator;
}
alias this = value;
}
as opposed to:
struct Fraction
{
long numerator;
long denominator;
double value() const @property
{
return cast(double)numerator / denominator;
}
@pseudonym value;
// in the year 2000...
@pseudonym value, value2, value3;
}
| |||
February 22, 2013 Re: What happened to the alias this = identifier syntax in 2.062? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Joshua Niehus | didn't fully formulate that thought:
above examples vs. the following
struct Fraction
{
long numerator;
long denominator;
double value() const @property
{
return cast(double)numerator / denominator;
}
auto opPseudonym() { /* points to value() ? */ }
alias opPsuedonym=value; // ??
}
| |||
February 23, 2013 Re: What happened to the alias this = identifier syntax in 2.062? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | On Friday, 22 February 2013 at 21:23:04 UTC, Timon Gehr wrote:
> I guess the main issue is that alias blah this; shouldn't have made it into the grammar in the first place. But this was obviously done in order to establish a broken analogy to the other uses of alias. Either alias this=blah; must be kept or the alias this syntax should be deprecated in favour of a specially named member function.
I believe the alias syntax was based on typedef, which was inherited from C, and has now been removed from D; so the justification was there in the past, but now absent which is why the change is happening now.
As far as replacing 'alias...this' with a member function, that's precisely how it *used* to be done with opDot(), but it suffered from overhead. I had thought, at the time 'alias...this' was first introduced, that the two were meant to live side by side, but then the realization came that one could actually achieve opDot's purpose with clever use of 'alias...this' so the latter fell out of favor. Alas.
| |||
February 23, 2013 Re: What happened to the alias this = identifier syntax in 2.062? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Chris Nicholson-Sauls | On Saturday, February 23, 2013 09:47:54 Chris Nicholson-Sauls wrote: > On Friday, 22 February 2013 at 21:23:04 UTC, Timon Gehr wrote: > > I guess the main issue is that alias blah this; shouldn't have made it into the grammar in the first place. But this was obviously done in order to establish a broken analogy to the other uses of alias. Either alias this=blah; must be kept or the alias this syntax should be deprecated in favour of a specially named member function. > > I believe the alias syntax was based on typedef, which was inherited from C, and has now been removed from D; so the justification was there in the past, but now absent which is why the change is happening now. alias bar = foo; was added simply because a number of folks didn't like alias foo bar; Both will continue to be supported. The only issue here is the fact that when alias bar = foo; was added, alias this = blah; was also added, but it was suddenly removed with the most recent release. Whether it's a good idea to disallow it or not, I don't know, but it broke people's code when it was removed, because some folks had started to use it - hence the complaints. alias bar = foo; is unaffected however. > As far as replacing 'alias...this' with a member function, that's precisely how it *used* to be done with opDot(), but it suffered from overhead. I had thought, at the time 'alias...this' was first introduced, that the two were meant to live side by side, but then the realization came that one could actually achieve opDot's purpose with clever use of 'alias...this' so the latter fell out of favor. Alas. alias this is supposed to completely replace opDot, and it's far more flexible than opDot, so there's really no reason to have opDot anymore. For whatever reason, opDot doesn't appear to have been actually deprecated yet, but it's supposed to be getting the axe at some point. - Jonathan M Davis | |||
February 23, 2013 Re: What happened to the alias this = identifier syntax in 2.062? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | On Saturday, 23 February 2013 at 09:24:20 UTC, Jonathan M Davis wrote:
> alias this is supposed to completely replace opDot, and it's far more flexible
> than opDot, so there's really no reason to have opDot anymore. For whatever
> reason, opDot doesn't appear to have been actually deprecated yet, but it's
> supposed to be getting the axe at some point.
>
It come with quite a lot of problems solved in an implementation defined way.
| |||
September 12, 2014 Re: What happened to the alias this = identifier syntax in 2.062? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to deadalnix | On Friday, 22 February 2013 at 16:47:58 UTC, deadalnix wrote: > On Friday, 22 February 2013 at 15:31:43 UTC, Martin wrote: >> On Friday, 22 February 2013 at 15:07:29 UTC, deadalnix wrote: >>> On Friday, 22 February 2013 at 14:58:02 UTC, Martin wrote: >>>> On Friday, 22 February 2013 at 14:55:19 UTC, bearophile wrote: >>>>> Martin: > It was wanted to distinguish the 2 with 2 different syntaxes. That's a very bad approach. | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply