Date: Mon, 08 Nov 2021 16:30:35 +0000
Gašper Ažman wrote:
> The committee actually did look at the (F this) syntax and it took a long
> time to convince them that it's a bad idea.
It's the lack of plain access to members without having
to write this-> or this. or self. that I regret losing.
I.e. I don't want to be able to write "this.foo" in
preference to "self.foo" in such a method, I want to be
able to just write "foo".
I have sometimes wondered whether it would he helpful to
provide syntax to bring arbitrary objects' members into
scope. Without this, free functions are inherently more
verbose than methods. I think that Pascal and/or Modula-2
had a "with" statement that allowed this. Example:
struct Circle {
float r;
float area() const { return pi*r*r; } // concise
};
float area(const Circle& circle)
{
return pi*circle.r*circle.r; // verbose
}
float area(const Circle& circle)
{
with circle {
return pi*r*r; // concise
}
}
You'll probably tell me this was considered and rejected years ago...
Regards, Phil.
> The committee actually did look at the (F this) syntax and it took a long
> time to convince them that it's a bad idea.
It's the lack of plain access to members without having
to write this-> or this. or self. that I regret losing.
I.e. I don't want to be able to write "this.foo" in
preference to "self.foo" in such a method, I want to be
able to just write "foo".
I have sometimes wondered whether it would he helpful to
provide syntax to bring arbitrary objects' members into
scope. Without this, free functions are inherently more
verbose than methods. I think that Pascal and/or Modula-2
had a "with" statement that allowed this. Example:
struct Circle {
float r;
float area() const { return pi*r*r; } // concise
};
float area(const Circle& circle)
{
return pi*circle.r*circle.r; // verbose
}
float area(const Circle& circle)
{
with circle {
return pi*r*r; // concise
}
}
You'll probably tell me this was considered and rejected years ago...
Regards, Phil.
Received on 2021-11-08 10:30:38