CLOS style: default-initargs vs. multiple initforms
by Marco Baringer » Mon, 25 Oct 2004 18:42:30 GMT
Assuming i have a class foo:
(defclass foo ()
((a :initform nil :initform :a)))
I'd like to sub class foo and change the default value of the slot A
to T, afaict there are two ways to do this:
(defclass sub-foo (foo)
()
(:default-initargs :a t))
or
(defclass sub-foo (foo)
((a :initform t)))
Other than 1) the extra direct-slot-definition in the second case and
2) the fact that the first only works when foo's A slot has an
initarg, is there any difference between these two? which style do
people prefer? I'm leaning towards the first as it makes very clear
that the slot we're refering to is foo's A and not some new and
different A.
--
-Marco
Ring the bells that still can ring.
Forget your perfect offering.
There is a crack in everything.
That's how the light gets in.
-Leonard Cohen
Re: CLOS style: default-initargs vs. multiple initforms
by Pascal Costanza » Mon, 25 Oct 2004 21:39:50 GMT
The second alternative may break when someone changes slot a's
allocation in foo to :class.
Pascal
--
Tyler: "How's that working out for you?"
Jack: "Great."
Tyler: "Keep it up, then."
Re: CLOS style: default-initargs vs. multiple initforms
by Kenneth Tilton » Tue, 26 Oct 2004 03:20:31 GMT
On 2004-10-24 05:42:30 -0400, "Marco Baringer" < XXXX@XXXXX.COM > said:
I was all over the map on this issue until a hard-to-find bug made me
notice what I think is a decisive factor: any default-initarg, no
matter how high up the class inheritance list will trump any initform,
no matter how specific to a subclass.
So there really is no choice in the matter other than consistently to
author default values for an inherited slot via default-initargs. The
initform can be used in the class declaring the slot originally for
convenience. This comes a cropper only if during refactoring one
somewhow ends up with a new superclass also "originating" the same slot
and then some newly-inherited intermediate class specifying a
default-initarg, but I would expect the refactoring to chop the slot
from what was the original class to originate the slot. If you know
what I mean. :)
kenny