Subclassing OrderedCollection in an external package

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

Subclassing OrderedCollection in an external package

Chris Muller-3
> P.S.: If XMLOrderedList is a subclass of OrderedCollection, then it's just
> plain wrong IMHO. Creating subclasses of collections in external packages is
> bad practice.

Hi Levente, I was just curious why that is bad practice.

Reply | Threaded
Open this post in threaded view
|

Re: Subclassing OrderedCollection in an external package

timrowledge

On 05-03-2013, at 2:01 PM, Chris Muller <[hidden email]> wrote:

>> P.S.: If XMLOrderedList is a subclass of OrderedCollection, then it's just
>> plain wrong IMHO. Creating subclasses of collections in external packages is
>> bad practice.
>
> Hi Levente, I was just curious why that is bad practice.

I am also curious why you think that. Making subclasses is pretty much the essence of programming.


tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
Oxymorons: Airline Food



Reply | Threaded
Open this post in threaded view
|

Re: Subclassing OrderedCollection in an external package

Frank Shearar-3
On 5 March 2013 22:06, tim Rowledge <[hidden email]> wrote:

>
> On 05-03-2013, at 2:01 PM, Chris Muller <[hidden email]> wrote:
>
>>> P.S.: If XMLOrderedList is a subclass of OrderedCollection, then it's just
>>> plain wrong IMHO. Creating subclasses of collections in external packages is
>>> bad practice.
>>
>> Hi Levente, I was just curious why that is bad practice.
>
> I am also curious why you think that. Making subclasses is pretty much the essence of programming.

Oh, the horror! Surely you mean _composition_, which subsumes diry,
icky inheritance. ("Dirty, icky" because to understand one class you
need to understand all its ancestors and all its descendants.)

frank

> tim
> --
> tim Rowledge; [hidden email]; http://www.rowledge.org/tim
> Oxymorons: Airline Food
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Subclassing OrderedCollection in an external package

Bert Freudenberg
In reply to this post by timrowledge
On 2013-03-05, at 23:06, tim Rowledge <[hidden email]> wrote:

> On 05-03-2013, at 2:01 PM, Chris Muller <[hidden email]> wrote:
>
>>> P.S.: If XMLOrderedList is a subclass of OrderedCollection, then it's just
>>> plain wrong IMHO. Creating subclasses of collections in external packages is
>>> bad practice.
>>
>> Hi Levente, I was just curious why that is bad practice.
>
> I am also curious why you think that. Making subclasses is pretty much the essence of programming.

I'm curious why you would feel the need to subclass OrderedCollection, have to agree with Levente.

It's bad practice to subclass for no good reason, because you're much more likely to depend on the implementation details of your superclass, and not just its external interface. One shortcoming of Smalltalk in particular is that all the implementation details are visible, so they tend to get made use of. Which is perfectly fine for a personal computing system in one image, but not for a collaboratively maintained one, where we have to worry about breaking subclasses that are not in the image.

So feel free to subclass away, but be prepared for dealing with the consequences later. Strong coupling is bad, and subclassing creates a pretty strong bound.

- Bert -


Reply | Threaded
Open this post in threaded view
|

Re: Subclassing OrderedCollection in an external package

timrowledge

On 05-03-2013, at 2:22 PM, Bert Freudenberg <[hidden email]> wrote:

> On 2013-03-05, at 23:06, tim Rowledge <[hidden email]> wrote:
>
>> On 05-03-2013, at 2:01 PM, Chris Muller <[hidden email]> wrote:
>>
>>>> P.S.: If XMLOrderedList is a subclass of OrderedCollection, then it's just
>>>> plain wrong IMHO. Creating subclasses of collections in external packages is
>>>> bad practice.
>>>
>>> Hi Levente, I was just curious why that is bad practice.
>>
>> I am also curious why you think that. Making subclasses is pretty much the essence of programming.
>
> I'm curious why you would feel the need to subclass OrderedCollection, have to agree with Levente.
>
> It's bad practice to subclass for no good reason,

It's bad practice to do *anything* for no good reason. Given a good reason, do it.


> because you're much more likely to depend on the implementation details of your superclass, and not just its external interface. One shortcoming of Smalltalk in particular is that all the implementation details are visible, so they tend to get made use of. Which is perfectly fine for a personal computing system in one image, but not for a collaboratively maintained one, where we have to worry about breaking subclasses that are not in the image.

If we had actual external interfaces, and if anyone ever paid attention, and if I even occasionally came across really well-written code…. but we don't and hardly anyone does and it never - well hardly ever(©Gilbert & Sullivan)  - happens. But I'd rather have a package with code that can be improved than no package at all.


tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
We can rescue a hostage or bankrupt a system. Now, what would you like us to do?



Reply | Threaded
Open this post in threaded view
|

Re: Subclassing OrderedCollection in an external package

Bert Freudenberg
On 2013-03-05, at 23:33, tim Rowledge <[hidden email]> wrote:

> On 05-03-2013, at 2:22 PM, Bert Freudenberg <[hidden email]> wrote:
>
>> On 2013-03-05, at 23:06, tim Rowledge <[hidden email]> wrote:
>>
>>> On 05-03-2013, at 2:01 PM, Chris Muller <[hidden email]> wrote:
>>>
>>>>> P.S.: If XMLOrderedList is a subclass of OrderedCollection, then it's just
>>>>> plain wrong IMHO. Creating subclasses of collections in external packages is
>>>>> bad practice.
>>>>
>>>> Hi Levente, I was just curious why that is bad practice.
>>>
>>> I am also curious why you think that. Making subclasses is pretty much the essence of programming.
>>
>> I'm curious why you would feel the need to subclass OrderedCollection, have to agree with Levente.
>>
>> It's bad practice to subclass for no good reason,
>
> It's bad practice to do *anything* for no good reason. Given a good reason, do it.
>
>
>> because you're much more likely to depend on the implementation details of your superclass, and not just its external interface. One shortcoming of Smalltalk in particular is that all the implementation details are visible, so they tend to get made use of. Which is perfectly fine for a personal computing system in one image, but not for a collaboratively maintained one, where we have to worry about breaking subclasses that are not in the image.
>
> If we had actual external interfaces, and if anyone ever paid attention, and if I even occasionally came across really well-written code…. but we don't and hardly anyone does and it never - well hardly ever(©Gilbert & Sullivan)  - happens. But I'd rather have a package with code that can be improved than no package at all.

Agreed. Still, for noobs who get too excited about their discovery of subclassing, it is worth mentioning that it's not always a good idea.

- Bert -



Reply | Threaded
Open this post in threaded view
|

Re: Subclassing OrderedCollection in an external package

Nicolas Cellier
In reply to this post by Bert Freudenberg
Strong bounds, and a lot of inter-dependency make the construction
fragile indeed.
I'll add that the worst thing with subclassing is whenever you want to
extend the behavior of superclass.
You'll then have to care of all the specific hacks of subclasses, some
ignoring some states, the others changing the meaning of them.

A good example I had recently was trying to implement a
Stream>>readStream subclassResponsibility which would either respond
self for a readStream or transparently transform the contents of a
WriteStream.
Simple enough you might think without reading code, but you should
really try just to understand how subclassing can turn evil.

Also it's a good exercize to reread WriteStream and explain why the
hell we need those three states, readLimit, writeLimit, position, why
we find so many 'readLimit := readLimit max: position.' snippets, and
how we can possibly change anything when more than 50 references each
raise the barrier that high.

Stream is a very good counter example of subclassing, I'd say the
shortest way to freeze code up to the point of un-maintainability.

As long as the good reasons for subclassing are put in balance with
the good reasons for not subclassing, I'm OK.

Nicolas

2013/3/5 Bert Freudenberg <[hidden email]>:

> On 2013-03-05, at 23:06, tim Rowledge <[hidden email]> wrote:
>
>> On 05-03-2013, at 2:01 PM, Chris Muller <[hidden email]> wrote:
>>
>>>> P.S.: If XMLOrderedList is a subclass of OrderedCollection, then it's just
>>>> plain wrong IMHO. Creating subclasses of collections in external packages is
>>>> bad practice.
>>>
>>> Hi Levente, I was just curious why that is bad practice.
>>
>> I am also curious why you think that. Making subclasses is pretty much the essence of programming.
>
> I'm curious why you would feel the need to subclass OrderedCollection, have to agree with Levente.
>
> It's bad practice to subclass for no good reason, because you're much more likely to depend on the implementation details of your superclass, and not just its external interface. One shortcoming of Smalltalk in particular is that all the implementation details are visible, so they tend to get made use of. Which is perfectly fine for a personal computing system in one image, but not for a collaboratively maintained one, where we have to worry about breaking subclasses that are not in the image.
>
> So feel free to subclass away, but be prepared for dealing with the consequences later. Strong coupling is bad, and subclassing creates a pretty strong bound.
>
> - Bert -
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Subclassing OrderedCollection in an external package

Chris Muller-3
In reply to this post by Bert Freudenberg
>> I am also curious why you think that. Making subclasses is pretty much the essence of programming.
>
> I'm curious why you would feel the need to subclass OrderedCollection, have to agree with Levente.
>
> It's bad practice to subclass for no good reason, because you're much more likely to depend on the implementation details of your superclass, and not just its external interface. One shortcoming of Smalltalk in particular is that all the implementation details are visible, so they tend to get made use of. Which is perfectly fine for a personal computing system in one image, but not for a collaboratively maintained one, where we have to worry about breaking subclasses that are not in the image.
>
> So feel free to subclass away, but be prepared for dealing with the consequences later. Strong coupling is bad, and subclassing creates a pretty strong bound.

Ah, ok, now I got it.  This is what we're taught when we're new and
learning Smalltalk, and what we definitely want to tell newbies so
they don't go off and do something like that when they don't need to.

But we wouldn't say that about the current subclasses of
OrderedCollection such as WeakOrderedCollection or...  It's definitely
*rare* for that to be the right thing but not totally absolute.

Reply | Threaded
Open this post in threaded view
|

Re: Subclassing OrderedCollection in an external package

David T. Lewis
In reply to this post by timrowledge
On Tue, Mar 05, 2013 at 02:33:50PM -0800, tim Rowledge wrote:
>
> On 05-03-2013, at 2:22 PM, Bert Freudenberg <[hidden email]> wrote:
> >
> > It's bad practice to subclass for no good reason,
>
> It's bad practice to do *anything* for no good reason. Given a good reason, do it.

I wish someone had told me that when I was younger.

;-)

Dave


Reply | Threaded
Open this post in threaded view
|

Re: Subclassing OrderedCollection in an external package

Casey Ransberger-2
Oh come on, people, I subclass Object all the time! ;)

On Wed, Mar 6, 2013 at 5:33 PM, David T. Lewis <[hidden email]> wrote:
On Tue, Mar 05, 2013 at 02:33:50PM -0800, tim Rowledge wrote:
>
> On 05-03-2013, at 2:22 PM, Bert Freudenberg <[hidden email]> wrote:
> >
> > It's bad practice to subclass for no good reason,
>
> It's bad practice to do *anything* for no good reason. Given a good reason, do it.

I wish someone had told me that when I was younger.

;-)

Dave





--
Casey Ransberger

Reply | Threaded
Open this post in threaded view
|

Re: Subclassing OrderedCollection in an external package

Hannes Hirzel
Yes, and the question is about subclassing OrderedCollection. Quite
often done by beginners. Later on you find out that you can easily
wrap them in a class which is a subclass of Object.

Maybe it could help the discussion to see the actual example....

--Hannes

On 3/7/13, Casey Ransberger <[hidden email]> wrote:

> Oh come on, people, I subclass Object all the time! ;)
>
> On Wed, Mar 6, 2013 at 5:33 PM, David T. Lewis <[hidden email]> wrote:
>
>> On Tue, Mar 05, 2013 at 02:33:50PM -0800, tim Rowledge wrote:
>> >
>> > On 05-03-2013, at 2:22 PM, Bert Freudenberg <[hidden email]>
>> wrote:
>> > >
>> > > It's bad practice to subclass for no good reason,
>> >
>> > It's bad practice to do *anything* for no good reason. Given a good
>> reason, do it.
>>
>> I wish someone had told me that when I was younger.
>>
>> ;-)
>>
>> Dave
>>
>>
>>
>
>
> --
> Casey Ransberger
>