<div class="gmail_quote">On Fri, Sep 30, 2011 at 4:16 PM, nicky van foreest <span dir="ltr">&lt;<a href="mailto:vanforeest@gmail.com">vanforeest@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Sorry to bug you, but I tried also the following:<br>
<br>
class Step(trellis.Component):<br>
    duration = trellis.attr(0)<br>
<br>
    def __init__(self, machine):<br>
        self.machine = machine<br>
        self.prevs = trellis.Set([])<br>
<br>
instead of<br>
<br>
class Step(trellis.Component):<br>
<div class="im">    prevs = trellis.make(trellis.Set)<br>
    duration = trellis.attr(0)<br>
<br>
</div>    def __init__(self, machine):<br>
        self.machine = machine<br>
<br>
This also works (that is, I get the same schedule in both cases). Is<br>
there a difference between the two implementations?</blockquote><div><br></div><div>The reason that your code currently *appears* to work is because you&#39;re not changing the value of &#39;prevs&#39; at runtime. <br><br>

If at some point you did, say, &quot;someStep.prevs = trellis.Set(somedata)&quot;, your program would break because none of the listeners of someStep.prevs would notice the change.  That&#39;s why you should always declare your attributes using trellis.* descriptors.<br>
<br>
The more &quot;correct&quot; (trellisthonic?) way to write your code above is:<br><br><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">
class Step(trellis.Component):<br>
    duration = trellis.attr(0)<br>
    prevs = trellis.make(trellis.Set)<br>
    machine = None<br>
    # No __init__ method necessary!<br></font><br>
That is, there&#39;s no reason to have an __init__ method at all, since trellis.Component() already takes keyword arguments and assigns them to attributes, as long as they are defined in the class.<br></div><div><br></div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">The second<br>
implementation sets prevs as a class variable, but this does not<br>
appear necessary (telling from implementation 1).<font color="#888888"><br></font></blockquote><div><br></div><div>Please note that &#39;prevs&#39; is *not* a &quot;class variable&quot;.  It&#39;s a descriptor.  That is, Step.prevs is a descriptor object, but someStep.prevs (where someStep is an instance of Step) will be a distinct trellis.Set() instance, unless overridden when created (e.g. via &quot;someStep=Step(prevs=...)&quot;).<br>
</div></div>