lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Monday 31 January 2005 02.21, Jamie Webb wrote:
> On Mon, Jan 31, 2005 at 11:42:58AM +1100, skaller wrote:
> > > I did 
> > > something similar for the simple types (integer, reals, 
> > > anything that doesn't carry an object reference) in the form of 
> > > large single level switch that decodes values combined from the 
> > > operator and the operand types. Fast and simple, and yet makes 
> > > trivial to implement things like "Pascal style 
divison" (integer / 
> > > integer ==> real, rather than integer).
> > > 
> > > The problems gather when you get to operations on objects...
> > 
> > Of course. It's impossible. This is the covariance
> > problem I referred to in another post.
> > 
> > YOu need n^2 routines for n types, which doesn't fit
> > into the n methods OO allows... this kills OO as a
> > programming methodology with a one line argument.
> It's certainly one of the numerous flaws in Java, but I don't think
> you can dismiss OO in general so easily. Surely in a dynamically
> typed language nothing more than multiple dispatch is required?

Yeah... One that covers all potentially relevant types, and one of 
those for each operator.

And if you want both 'this * x'  and 'x * this' between objects that 
don't have a two-way relation (ie when you add user types that want 
to interoperate with core types or types from other extensions), 
you'll need reverse operators as well - and obviously, VM support for 

The ugly thing about that is that the VM is forced to decide whether 
to use a forward or reverse method, based on whether or not the left 
hand object has a suitable method. That's at least one extra 
conditional in the main path, and some more when that one catches a 
reverse operation.

What if both operands have methods that would fit...? (Which is the 
case when you operate on two objects of the same type; if that method 
is implemented, both operands will be equally capable of performing 
the operation.)

So, doing this in a "proper" OO way looks more and more like some 
serious shoehorning...

//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
|  Free/Open Source audio engine for games and multimedia.  |
| MIDI, modular synthesis, real time effects, scripting,... |
`-----------------------------------> -'
   --- --- ---