D
Daniel Brockman
Trans said:An example of a call mechanism:
class A
def f
A\g # Peter's Syntax
I'm not incredibly turned on by that syntax; unfortunately,
I don't have any obviously better suggestion myself.
It would have been nice if we could use the =E2=80=98A::g=E2=80=99 syntax
for this. Correct me if I'm wrong, but I think this would
be possible if =E2=80=98Curses.addch(?x)=E2=80=99 could *not* be written =
as
=E2=80=98Curses::addch(?x)=E2=80=99 (so that =E2=80=98Foo::bar=E2=80=99 c=
ould be changed to
always mean =E2=80=9Cinvoke =E2=80=98bar=E2=80=99 as defined in =E2=80=98=
Foo=E2=80=99 on self=E2=80=9D).
(Note that even if this was done, =E2=80=98Foo::BAR=E2=80=99 could still
mean what it currently does, because there is no ambiguity
when no method calls are involved.)
While this change would probably break most Ruby code that
currently exists, fixing it could be done mechanically:
Just substitute "\1.\2" for /(\w):[a-z])/ everywhere.
You'd think another potential option would be =E2=80=98self.A::g=E2=80=99=
,
but of course that currently means =E2=80=98self.A.g=E2=80=99, and =E2=80=
=98self.A=E2=80=99
is the only way to call a method named =E2=80=98A=E2=80=99. (Though if t=
he
previously mentioned syntax is an option, then so is this.)
end
def g
"in g"
end
end
A possible downside to a call mechinism is that the method
is still part of the inheritance chain.
Another downside is that people would be tempted to add the
prefix =E2=80=98A\=E2=80=99 to every method call that would have been
non-virtual in C++. I can see two bad consequences of that:
* It would add loads of clutter, including the class name
sprinkled all over the place.
* It would be a step backwards towards static languages,
because it would mean tempting people to decide early
whether or not a method will need to be overridden.
On the upside the syntax can be used to call specific
acestor's methods (i.e. bypassing the direct parent,
which #super dosen't allow).
Yes, that would certainly be useful. I don't think the
syntax is suited for doing =E2=80=9Clocally private=E2=80=9D methods, but
this use case makes it all worthwhile.
I'm thinking primarily about cases such as the following.
class Foo < Bar
include Baz
def initialize(moomin, snufkin)
super(moomin)
Baz\initialize(snufkin)
end
end
The above could also be written as follows,
class Foo < Bar
include Baz
def initialize(moomin, snufkin)
Bar\initialize(moomin)
Baz\initialize(snufkin)
end
end
or with the syntax I proposed above:
class Foo < Bar
include Baz
def initialize(moomin, snufkin)
Bar::initialize(moomin)
Baz::initialize(snufkin)
end
end
If there were a way to make private methods truly private,
that'd be a better approach to =E2=80=9Clocally private=E2=80=9D methods.
But that seems rather difficult to get right.
--=20
Daniel Brockman <[email protected]>
So really, we all have to ask ourselves:
Am I waiting for RMS to do this? --TTN.