Object>>#is:? (was: Re: PackageDependencyTest)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
71 messages Options
1234
Reply | Threaded
Open this post in threaded view
|

Re: Object>>#is:? (was: Re: PackageDependencyTest)

Tobias Pape

<rant>
> anObject askFor: #isMorph.

oh, then,

anObject prepareForQuestion: #askForIsMorph
</rant>

Really, I don't understand the askFor: metaphor.


So Long,
        -Tobias

Reply | Threaded
Open this post in threaded view
|

Re: Object>>#is:?

Colin Putney
In reply to this post by Juan Vuletich-4

On 2010-03-05, at 3:50 AM, Juan Vuletich wrote:

> Of course it is not. Anyway, it is much closer to being modular than Squeak. At least there is a lot less dependencies in the kernel upon the applications. The removal of lots of #isXXX methods in Object is just a small part of that.

First, that's not true. A method that returns a Boolean does not introduce a dependency on anything. The removal of these methods doesn't reduce dependency.

Second, the fact that a method is on Object doesn't make it part of the Kernel. If, for aesthetic reasons, you don't want #isGreen to be present when the Greenness package isn't loaded, *make it part of the package.* Extension methods are a good thing. They enable modularity.

Third, it's meaningless to talk about "kernel" and "applications" in Cuis. There are no packages. There are no boundaries. If one part of the system depends on another, is that the kernel depending on an application or the other way around? Until you actually draw the boundaries, you can't answer that question.

Colin
Reply | Threaded
Open this post in threaded view
|

Re: Object>>#is:?

Colin Putney
In reply to this post by Igor Stasenko

On 2010-03-04, at 10:16 PM, Igor Stasenko wrote:

> Agreed. But then expect an Object class to have thousands of isXXXX
> methods, since we having way many things which we can imagine and may
> want to model them. Then the Object class will become a flat space of
> system-wide methods. Is this what can be called good OO design which
> using polymorphic dispatch?

You exaggerate. In my image, Object has 51 methods that begin with 'is'. It's hardly a flat space of system-wide methods.

In general, I agree that Object has too many methods. But I think we should reduce that number by *increasing* the modularity of the system, rather than decreasing it.

Colin
Reply | Threaded
Open this post in threaded view
|

Re: Object>>#is:? (was: Re: PackageDependencyTest)

keith1y
In reply to this post by Tobias Pape

<rant>
anObject askFor: #isMorph.

oh, then,

anObject prepareForQuestion: #askForIsMorph
</rant>

Really, I don't understand the askFor: metaphor.


So Long,
-Tobias

The metaphor comes from "asking for" an interface. i.e. checking the presence of an interface that might be there, that is tagged by virtue of its implementation of an identifying boolean selector. If you can check that you have the interface you need to do something, why would you care what an object "is".

Keith



Reply | Threaded
Open this post in threaded view
|

Re: Object>>#is:? (was: Re: PackageDependencyTest)

Tobias Pape

Am 2010-03-05 um 17:09 schrieb keith:

>
> The metaphor comes from "asking for" an interface. i.e. checking the presence of an interface that might be there, that is tagged by virtue of its implementation of an identifying boolean selector.

ok, i got that.


> If you can check that you have the interface you need to do something, why would you care what an object "is".

because its my normal "real world" beahviour.

Tobias isWise => false
Sky isBlue => True

;)

I dont want to ask whether I may ask if something is.
It's an unnecessary indirection from my logical point of view.

So Long,
        -Tobias
Reply | Threaded
Open this post in threaded view
|

Re: Object>>#is:? (was: Re: PackageDependencyTest)

George Herolyants-3
In reply to this post by Michael van der Gulik-2
2010/3/5 Michael van der Gulik <[hidden email]>:
> It sounds like Java-style Interfaces should be implemented.
>
> (anObject implements: AnInterface) ifTrue: [ ... ]

What about traits in this role?

anObject implements: TDoable. ...or...
anObject supports: TDoable. ...or even...
anObject isA: TDoable


George

Reply | Threaded
Open this post in threaded view
|

Re: Object>>#is:? (was: Re: PackageDependencyTest)

Eliot Miranda-2
In reply to this post by Juan Vuletich-4


On Thu, Mar 4, 2010 at 3:05 PM, Juan Vuletich <[hidden email]> 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
archives.

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.

Cheers,
 - 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.

If is: is about protocol not inheritance (a position I would support) then is: is a very bad selector.  canUnderstand: and respondsTo: taken.  supports: has applications in civil engineering simulations.  What about comprehends:?  "Too long" you say; "is: is neat and short" you say.  But it is also hopelessly ambiguous.  What about groks: ? ;)

Seriously, can we find something better than is?  Or perhaps it can be in the argument, where one would use "has: #MorphProtocol" instead of the ambiguous "is: #Morph"? (obvious problems implementing Andreas' base case efficiently).

At the very least the implementation of is: needs to include a decent comment explaining the convention.
 
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.

Cheers,
Juan Vuletich




Reply | Threaded
Open this post in threaded view
|

Re: Object>>#is:?

Eliot Miranda-2
In reply to this post by Igor Stasenko


On Thu, Mar 4, 2010 at 10:16 PM, Igor Stasenko <[hidden email]> wrote:
On 5 March 2010 06:37, Colin Putney <[hidden email]> wrote:
>
> On 2010-03-04, at 1:18 PM, Stéphane Rollandin wrote:
>
>> I got it; see my answer to Juan. I guess I'm just programming in bad style: I do indeed consider that Object is part of my packages (or, more accurately, that Object is not a forbidden place for my package to go in).
>
> Hear hear. I've been wondering why people are so enthusiastic about #is: - good to see I'm not the only one.
>
> I think #isA: is fine, as an easy way to do #isKindOf: without a direct class reference. Being able to avoid class references makes it easier to avoid dependencies, which makes it easier to have a modular system.
>
> Juan's implementation of #is: puzzles me though. It replaces polymorphic dispatch with boolean logic. Good OO design generally goes in the opposite direction.
>

Agreed. But then expect an Object class to have thousands of isXXXX
methods, since we having way many things which we can imagine and may
want to model them. Then the Object class will become a flat space of
system-wide methods. Is this what can be called good OO design which
using polymorphic dispatch?


I think this is alarmism.  There may be 10's, even 100's but 1000's?  Take for example the is methods in the parse node hierarchy.  Object need only implement isParseNode, then ParseNode is where the various specifics such as isReturnNode.  So the number of is methods in Object can grow to the number of domains, not to the sized of those domains.  We already have a few (often indispensible) specifics such as isNil.  But as domains grow we can be more selective.


> Furthermore, Juan's version of #is: makes it more difficult to modularize the system. If I write a package that needs to add the concept of "greenness" to the system, I can add #isGreen extension methods wherever I want, without breaking any existing code. Somebody else can add #isPurple methods without breaking my code. But if we both need to override #is:, we have a gratuitous incompatibility.
>

But you are still free to do that, so what the problem?
But in 90% of cases, i think you can use #is: method , without the
need of adding extensions anywhere, because the only reason why you
adding it is to be overridden in subclass, which belongs to your
package.


> Note that #is: may work well in Cuis, but that's because Cuis is *not* a modular system.
>
> Finally, I also want to point out that "simpler" and "fewer methods" are not the same thing. Methods that answer booleans are dead simple to understand, no matter how many of them there are. A single #is: method increases incomplexity as the number of tests it encompasses increases.
>
I disagree. Adding a new protocols and corresponding way to test a
conformance to it - this is what increases system complexity in a
first place. The #is: method by itself puts zero weight into it, if
you not using it.

> So, consider this moral support for Stéphane, since he seems to be beset on all sides. Also,
>
> +0 for #isA:
> -1 for #is:
>
> Colin
>



--
Best regards,
Igor Stasenko AKA sig.




Reply | Threaded
Open this post in threaded view
|

Re: Object>>#is:?

Eliot Miranda-2
In reply to this post by Colin Putney


On Thu, Mar 4, 2010 at 8:37 PM, Colin Putney <[hidden email]> wrote:

On 2010-03-04, at 1:18 PM, Stéphane Rollandin wrote:

> I got it; see my answer to Juan. I guess I'm just programming in bad style: I do indeed consider that Object is part of my packages (or, more accurately, that Object is not a forbidden place for my package to go in).

Hear hear. I've been wondering why people are so enthusiastic about #is: - good to see I'm not the only one.

I think #isA: is fine, as an easy way to do #isKindOf: without a direct class reference. Being able to avoid class references makes it easier to avoid dependencies, which makes it easier to have a modular system.

Juan's implementation of #is: puzzles me though. It replaces polymorphic dispatch with boolean logic. Good OO design generally goes in the opposite direction.

Furthermore, Juan's version of #is: makes it more difficult to modularize the system. If I write a package that needs to add the concept of "greenness" to the system, I can add #isGreen extension methods wherever I want, without breaking any existing code. Somebody else can add #isPurple methods without breaking my code. But if we both need to override #is:, we have a gratuitous incompatibility.

Note that #is: may work well in Cuis, but that's because Cuis is *not* a modular system.

Finally, I also want to point out that "simpler" and "fewer methods" are not the same thing. Methods that answer booleans are dead simple to understand, no matter how many of them there are. A single #is: method increases incomplexity as the number of tests it encompasses increases.

So, consider this moral support for Stéphane, since he seems to be beset on all sides. Also,

+0 for #isA:
-1 for #is:

Colin

Hear, hear!



Reply | Threaded
Open this post in threaded view
|

Re: Object>>#is:?

Igor Stasenko
In reply to this post by Eliot Miranda-2
On 7 March 2010 07:35, Eliot Miranda <[hidden email]> wrote:

>
>
> On Thu, Mar 4, 2010 at 10:16 PM, Igor Stasenko <[hidden email]> wrote:
>>
>> On 5 March 2010 06:37, Colin Putney <[hidden email]> wrote:
>> >
>> > On 2010-03-04, at 1:18 PM, Stéphane Rollandin wrote:
>> >
>> >> I got it; see my answer to Juan. I guess I'm just programming in bad
>> >> style: I do indeed consider that Object is part of my packages (or, more
>> >> accurately, that Object is not a forbidden place for my package to go in).
>> >
>> > Hear hear. I've been wondering why people are so enthusiastic about #is:
>> > - good to see I'm not the only one.
>> >
>> > I think #isA: is fine, as an easy way to do #isKindOf: without a direct
>> > class reference. Being able to avoid class references makes it easier to
>> > avoid dependencies, which makes it easier to have a modular system.
>> >
>> > Juan's implementation of #is: puzzles me though. It replaces polymorphic
>> > dispatch with boolean logic. Good OO design generally goes in the opposite
>> > direction.
>> >
>>
>> Agreed. But then expect an Object class to have thousands of isXXXX
>> methods, since we having way many things which we can imagine and may
>> want to model them. Then the Object class will become a flat space of
>> system-wide methods. Is this what can be called good OO design which
>> using polymorphic dispatch?
>
>
> I think this is alarmism.  There may be 10's, even 100's but 1000's?  Take
> for example the is methods in the parse node hierarchy.  Object need only
> implement isParseNode, then ParseNode is where the various specifics such as
> isReturnNode.  So the number of is methods in Object can grow to the number
> of domains, not to the sized of those domains.  We already have a few (often
> indispensible) specifics such as isNil.  But as domains grow we can be more
> selective.

I am trying to find a way to not repeat myself, when coding.
If i need implement, say 10 isXXX methods during the year, then count
here others, who also has to implement their own.
Sure thing, not all will find their place in Object. But still this
pattern can be found all over the places.

That's fun, when Colin says that #is: 'replaces polymorphic dispatch
with boolean logic'.
But hey, this is not true. It doesn't replacing polymorphic dispatch,
it is the coder who replacing it, when writing:

object isFoo ifTrue: [ self doSomething ] ifFalse: [ self doOtherThing ]
or:
(object is: #Foo) ifTrue: [ self doSomething ] ifFalse: [ self doOtherThing ]

instead:

object doSomethingWith: self

>>
>> > Furthermore, Juan's version of #is: makes it more difficult to
>> > modularize the system. If I write a package that needs to add the concept of
>> > "greenness" to the system, I can add #isGreen extension methods wherever I
>> > want, without breaking any existing code. Somebody else can add #isPurple
>> > methods without breaking my code. But if we both need to override #is:, we
>> > have a gratuitous incompatibility.
>> >
>>
>> But you are still free to do that, so what the problem?
>> But in 90% of cases, i think you can use #is: method , without the
>> need of adding extensions anywhere, because the only reason why you
>> adding it is to be overridden in subclass, which belongs to your
>> package.
>>
>>
>> > Note that #is: may work well in Cuis, but that's because Cuis is *not* a
>> > modular system.
>> >
>> > Finally, I also want to point out that "simpler" and "fewer methods" are
>> > not the same thing. Methods that answer booleans are dead simple to
>> > understand, no matter how many of them there are. A single #is: method
>> > increases incomplexity as the number of tests it encompasses increases.
>> >
>> I disagree. Adding a new protocols and corresponding way to test a
>> conformance to it - this is what increases system complexity in a
>> first place. The #is: method by itself puts zero weight into it, if
>> you not using it.
>>
>> > So, consider this moral support for Stéphane, since he seems to be beset
>> > on all sides. Also,
>> >
>> > +0 for #isA:
>> > -1 for #is:
>> >
>> > Colin
>> >
>>
>>
>>
>> --
>> Best regards,
>> Igor Stasenko AKA sig.
>>
>
>
>
>
>



--
Best regards,
Igor Stasenko AKA sig.

Reply | Threaded
Open this post in threaded view
|

Re: Object>>#is:? (was: Re: PackageDependencyTest)

Tony Garnock-Jones-2
In reply to this post by Eliot Miranda-2
Eliot Miranda wrote:
> If is: is about protocol not inheritance (a position I would support)
> then is: is a very bad selector.  canUnderstand: and respondsTo: taken.
>  supports: has applications in civil engineering simulations.  What
> about comprehends:?  "Too long" you say; "is: is neat and short" you
> say.  But it is also hopelessly ambiguous.  What about groks: ? ;)

#provides: ? #implements: ? #hasProtocol: ?

Tony


1234