[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: unified methods
- From: "Joshua Jensen" <jjensen@...>
- Date: Wed, 28 Nov 2001 19:57:58 -0700
> Just for completion, the Sol version ;-) (and some comments)
>
> methodTable2 = methodTable:class { -- inherit methods from
> methodTable
> function func3(self)
> printf("Hello", self.b)
> end
> }
This is a great approach. Just cross your fingers that nobody ever
removes the function class() from the method table! :)
> myTable = methodTable { a=5 } -- create instance
> myTable:func()
> -- anyway, a method that doesn't take a self (static class function?)
> -- shouldn't be called via an instance. this should be used:
> -- methodTable.func2()
Or possibly just:
methods(myTable).func2()
> IMHO, having 4 different field access operators is confusing!
> I could understand that one want's another operator to
> preserve backward compatibility. So make it '->' (will give
> the minimum confusion) and mark the ':' as "for compatibility
> use only" (remember, it was ment as a method operator to give
> OO look'n'feel in the first place). I think that you won't
> need it very often anyway. And about your fourth one see the
> comments in the code above.
I am in agreement with this and the confusion. I see, then, the need
for 3 operators.
myTable.func() -- No implicit self.
myTable:funcWithSelf() -- Implicit self passed. Backwards
compatible, but still useful.
myTable->methodTableFuncWithSelf() -- Implicit self passed through to
a method table function.
Which is the same as:
methods(myTable).methodTableFuncWithSelf(methods(myTable))
and
methods(myTable):methodTableFuncWithSelf()
And from Peter's response:
>I have to agree on the confusion arising from all the operators!
>Used so far in this thread: . : .. :: -> .> :> Ouch! what about
>;) :-> and .-> ?? *g*
Hey, the more smileys you can build into your code, the better! :)
>but why use another operator at all?
>it should be easy to provide backward compatibility with
>appropriate methods, or am i missing something? so you can stick
>to . and :
Another operator is necessary to keep code looking simple and existing
code behaving the same. In the case of:
myTable->methodTableFuncWithSelf() -- Implicit self passed through to
a method table function.
Which is the same as:
methods(myTable).methodTableFuncWithSelf(methods(myTable))
and
methods(myTable):methodTableFuncWithSelf()
The use of the -> operator hides the [ methods(myTable): ]. Plus, there
is no question that the method came from the method table at that point.
It would be possible to make the : operator first check myTable and then
methods(myTable), but at the very least, you have the cost of the
myTable hash lookup, which could be a waste of time. To make the :
operator just look at methods(myTable) would be bad, because it would
break existing code, in addition to not allowing an implicit self to be
passed through to a myTable function (although it's debatable how
important that is).
-Josh