View · Search · Index
No registered users in community xowiki
in last 10 minutes

Re: [Xotcl] Thoughts on dealing with class parameters

From: Kristoffer Lawson <setok_at_scred.com>
Date: Thu, 5 Aug 2010 16:31:58 +0300

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/