Comparisons and sorting of a numeric class....

Ian Kelly ian.g.kelly at gmail.com
Mon Jan 26 20:50:07 EST 2015


On Mon, Jan 26, 2015 at 4:47 PM, Andrew Robinson
<andrew3 at r3dsolutions.com> wrote:
> Hmmm....  That's not much different than the tuple object I made as a
> container and which Ian complained about.  In fact, you did overload the
> comparison operators, just like I did...

Yeah, I know I said I was done with this thread, but since you call me
out by name I'll take a moment to respond.

> Let's see: Ian first complained that I wasn't subclassing in one example,

No. What I suggested was that for Python 2 you should explicitly name
a base class of object, i.e. the base class of *everything*. That's
not "you should use subclassing here", but rather "here's a tip for
writing good, Pythonic code".

> and then he next complained that he thought I was subclassing  *too quickly*
> (like he forgot that I didn't subclass before) because of something to do
> with 'bool' -- and then he mentioned I wasn't using composition....

I actually wrote about your tuple subclass "This seems fine," so don't
try to spin my words into something that they aren't. My criticism was
centered on your needless subclassing of tuple (nothing to do with
'bool'), resulting in a boolean class that supports nonsensical
operations like:

>>> len(MostlyFalse)
2

and even:

>>> isinstance(MostlyFalse, Sequence)
True

You may also notice that Rob's example which you compare to your own
doesn't do this.

> But now --I wonder why it didn't click with him that I avoided subclassing
> bool in my tuple example (at all)  -- because I was clearly making a general
> purpose container (composition pattern) to hold a bool and uncertainty
> value.

This is not an example of composition. By subclassing tuple, you are
effectively declaring that your boolean type IS a type of tuple.
Instead of aggressively and arrogantly defending poor code, why don't
you take my criticism as the learning opportunity that it was offered
as? Here would be a good place to start:

http://stackoverflow.com/questions/49002/prefer-composition-over-inheritance



More information about the Python-list mailing list