[Xotcl] Thoughts on dealing with class parameters

Kristoffer Lawson setok at scred.com
Thu Aug 5 15:31:58 CEST 2010


Apologies for the flood, but I can't get my mind off this. Some more ideas for how this could be made to work:


== Use a brand new command:

set ob [new Car "Land Rover"]

set ob [new -with {-doors 2} Car "Caterham"]

or

set ob [new -with {
	doors 2
} Car "Caterham"]

Here there is no real risk of pre-initialisation getting confused with arguments to the constructor. It doesn't look quite as nice as my earlier suggestion:

set ob [Car -new "Caterham" {
	doors 2
}]

But it would mean not having to have both [new] and [-new]. The current [new] method could then be deprecated, without breaking old scripts.


== Do something a bit like Objective C:

set ob [[Car create] init "Land Rover"]

set ob [[[Car create] conf -doors 2] init "Caterham"]

or possibly:

set ob [Car create]
$ob doors 2
$ob init "Caterham"

This could probably be done in a near backwards compatible way. It's very explicit without any funny logic. In fact you can almost do it right now, except there is no method to create with an autoname, but to not do argument configuration and construction calling.

-- 
Kristoffer Lawson, Co-Founder, Scred // http://www.scred.com/



More information about the Xotcl mailing list