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

[Sc-devel] various classes ==




There are a bunch of methods that are written like this:

Quark
== { arg that;
^that respondsTo: #[name, summary, version, author, dependencies, tags, path] 
and: {(this.name  == that.name)
and: {this.summary == that.summary}
and: {this.version  == that.version}
and: {this.author  == that.author}
and: {this.dependencies  == that.dependencies}
and: {this.tags  == that.tags}
and: {this.path  == that.path}
}
}


OSCpathResponder

== { arg that;

^that respondsTo: \path and: { path == that.path }

}


especially with this last one, ANYTHING that has a path might end up being equal.


I recently added Object-compareObject


which would allow the safer version:


== { arg that;

   ^this.compareObject(that,[\path])

}


this also allows you to compare private variables.


compareObject { arg that,instVarNames;

if(this === that,{ ^true });

// possibly ok if one of us isKindOf the other

if(this.class !== that.class,{ ^false });

if(instVarNames.notNil,{

instVarNames.do({ |varname|

if(this.instVarAt(varname) != that.instVarAt(varname),{

^false

})

});

},{

this.instVarSize.do({ arg i;

if(this.instVarAt(i) != that.instVarAt(i),{ ^false });

});

});

^true

}



the only issue/difference would be when comparing objects that aren't of the same class but for the purposes of whatever you are testing it for might be equal.


one example would be Bus vs. SharedBus


but for these rare cases I would just write a custom ==
and it mostly depends on your application.

so does anybody mind if I change these various == implementations ?

-cx