[squeak-dev] Re: Object>>#is:? (was: Re: PackageDependencyTest)
siguctua at gmail.com
Thu Mar 4 23:21:37 UTC 2010
On 5 March 2010 01:05, Juan Vuletich <juan at jvuletich.org> wrote:
> Andreas Raab wrote:
>> On 3/4/2010 12:33 PM, Juan Vuletich wrote:
>>> I believe #isKindOf: is really bad. Reasons for this are given in
>>> http://userweb.cs.utexas.edu/~wcook/Drafts/2009/essay.pdf . This was
>>> also discussed here, you can google for the name of the pdf in the
>>> In the Cuis implementation of Object>>#is: there is no call to
>>> #isKindOf:. The idea is to ask for a protocol, not for inheritance.
>> But inheritance implies protocol. There is nothing wrong with asking for
>> protocol conformance based on inheritance; it is the same as implementing
>> isNumber in class Number for the purpose of having subclasses inherit that.
>> The implementation that I've proposed is making that point. Thus (42 is:
>> #Number) returns true, since 42 conforms to the Number protocol. If you had
>> some other class that conforms to the number protocol without subclassing
>> it, it is free to implement, e.g.,
>> ComplexNumericRepresentative>>is: aSymbol
>> "I conform to the number protocol"
>> ^aSymbol == #Number or:[super is: aSymbol]
>> As a consequence, the #is: test is not an inheritance test at all.
>> - Andreas
> What you say is right. The reasons for me not doing it that way are perhaps
> subtle and aesthetic. I prefer making it as clear as possible that this is
> not about inheritance but protocol. I also think that my approach is easier
> to explain and understand. Besides I don't like it looking like there are
> "special" or "privileged" classes or hierarchies. Perhaps more important, I
> prefer not having "implicit" protocol conformance without anybody declaring
> (for example) that #BorderedMorph is now considered a protocol. In addition,
> I believe that this should be used only when really needed. In general, a
> better design might make all these queries unneeded. So, forcing people to
> declare their protocols might discourage abuse.
> Anyway, I think both solutions are acceptable and it comes down to taste.
So, let's vote for
self class environment
ifPresent:[:aClass| ^self isKindOf: aClass].
both methods should have an appropriate comment, explaining how and
when to use it. I just skipped it here.
My vote is for a).
Initially i proposed a little different implementation:
^ self = anObject
(note that i'm using 'anObject' argument name , not just symbol)
but now, i agree with Juan that more not always better.
A method , which answers just false (as in (a) case) looking a bit obscure, but
if we take into account that it comes with definitive giude about how
and when it should be used, then its not.
> Juan Vuletich
Igor Stasenko AKA sig.
More information about the Squeak-dev