operations on types

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

operations on types

Steven D'Aprano-11
On Tue, 16 Jun 2015 19:24:03 -0500, Dr. John Q. Hacker wrote:

> [Dr. Bigcock wrote:]
>> The current syntax for adding functionality to a class using mix-in
>> style via inheritance list conflates two very different things.

I'm not sure why you are taking "Dr Bigcock" seriously. You know he isn't
actually a doctor?


>> A different way would be to create (sensible) operations on types:
>>
>> NewType = OldObject + mixin  #object composition
>>
>> Thoughts?
>
> That's an awesome idea.  It's like a final way to understand and operate
> with metaclasses.

Unfortunately, it has nothing to do with metaclasses.

I can see why:

    NewType = OldType + Mixin

appears more attractive at first glance than:

    class NewType(OldType, Mixin):
        pass


since it saves a lot of boilerplate. But in practice, the body of the
class is not often "pass". More often, you end up overriding or adding
new methods. In that case, the suggested syntax has no advantage.

I think that this might be a bit more attractive in statically-typed
languages. If you wrote:

    class NewType(OldType + Mixin): ...

the compiler could optimize away the intermediary class (OldType+Mixin)
and just use direct inheritance, but I don't think that would work in
Python. And a statically-typed language could avoid errors where you
forget to instantiate a class before doing regular addition:

    result = OldType + x  # oops, meant OldType()


--
Steven D'Aprano

Reply | Threaded
Open this post in threaded view
|

operations on types

Dr. John Q. Hacker
On Tue, Jun 16, 2015 at 9:04 PM, Steven D'Aprano <
steve+comp.lang.python at pearwood.info> wrote:

> On Tue, 16 Jun 2015 19:24:03 -0500, Dr. John Q. Hacker wrote:
>
> > [Dr. Bigcock wrote:]
> >> The current syntax for adding functionality to a class using mix-in
> >> style via inheritance list conflates two very different things.
>
> I'm not sure why you are taking "Dr Bigcock" seriously. You know he isn't
> actually a doctor?
>

Actually, I asked him.  He said he was has a PhD in Theology.

> > That's an awesome idea.  It's like a final way to understand and operate
> > > with metaclasses.
> >
> > Unfortunately, it has nothing to do with metaclasses.
>

 No, it *does*:  it's operations on classes themselves (i.e. types) and not
on *instantiations* of classes.  If that isn't metaclassing, then python's
been calling it wrong.

> I can see why:
> >
> >     NewType = OldType + Mixin
> >
> > appears more attractive at first glance than:
> >
> >     class NewType(OldType, Mixin):
> >         pass
> >
> > since it saves a lot of boilerplate. But in practice, the body of the
> > class is not often "pass". More often, you end up overriding or adding
> > new methods. In that case, the suggested syntax has no advantage.
>

Adding new methods is exactly what this syntax is supposed to do.

The tricky part is overriding existing methods.  If Python's dict (or
defaultdict) type, provided an optional collision parameter, this could be
user-defined.  Probably the __doc__ attribute could be concatenated (the
simple, naive solution) while the code would have to be merged in some
fashion.

zipher
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20150616/3f4e1b7b/attachment.html>

Reply | Threaded
Open this post in threaded view
|

operations on types

Ian Kelly-2
In reply to this post by Steven D'Aprano-11
On Tue, Jun 16, 2015 at 8:04 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> On Tue, 16 Jun 2015 19:24:03 -0500, Dr. John Q. Hacker wrote:
>
>> [Dr. Bigcock wrote:]
>>> The current syntax for adding functionality to a class using mix-in
>>> style via inheritance list conflates two very different things.
>
> I'm not sure why you are taking "Dr Bigcock" seriously. You know he isn't
> actually a doctor?

I'm reasonably certain that they're actually the same person, and he's
now engaging in sockpuppetry [1] by starting conversations with
himself. He's not trying very hard to hide it, signing posts with both
accounts as "zipher" and then lamp-shading that fact by commenting on
it. I can't even find any record that "Dr. Bigcock" ever actually
posted the text that "Dr. John Q. Hacker" is now responding to.

[1] https://en.wikipedia.org/wiki/Sockpuppet_(Internet)

Reply | Threaded
Open this post in threaded view
|

operations on types

Chris Angelico
On Wed, Jun 17, 2015 at 2:58 PM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
> I'm reasonably certain that they're actually the same person, and he's
> now engaging in sockpuppetry [1] by starting conversations with
> himself.

I used to think there was a limit to the depths of human boredom. Then
I met the internet, and learned better.

ChrisA

Reply | Threaded
Open this post in threaded view
|

operations on types

Steven D'Aprano-11
In reply to this post by Steven D'Aprano-11
On Wednesday 17 June 2015 12:42, Dr. John Q. Hacker wrote:

> On Tue, Jun 16, 2015 at 9:04 PM, Steven D'Aprano <
> steve+comp.lang.python at pearwood.info> wrote:
>
>> On Tue, 16 Jun 2015 19:24:03 -0500, Dr. John Q. Hacker wrote:
>>
>> > [Dr. Bigcock wrote:]
>> >> The current syntax for adding functionality to a class using mix-in
>> >> style via inheritance list conflates two very different things.
>>
>> I'm not sure why you are taking "Dr Bigcock" seriously. You know he isn't
>> actually a doctor?
>>
>
> Actually, I asked him.  He said he was has a PhD in Theology.

You believe somebody calling himself "Dr Bigcock" (among other pseudonyms)?
Just how much credibility does somebody calling themselves Bigcock get? Even
in the "Carry On" movies they didn't use any names as unsubtle as that.

https://www.youtube.com/watch?v=wcBOX1JBcjQ

Besides, I have a Doctorate of Divinity, and I'm not a doctor either.


>> > That's an awesome idea.  It's like a final way to understand and
>> > operate
>> > > with metaclasses.
>> >
>> > Unfortunately, it has nothing to do with metaclasses.
>>
>
>  No, it *does*:  it's operations on classes themselves (i.e. types) and
>  not
> on *instantiations* of classes.  If that isn't metaclassing, then python's
> been calling it wrong.

Python's definition of "metaclass" (the class of a class) is the same as
that used by (at least) Objective C and Smalltalk. If you're going to argue
that *Smalltalk* is wrong, well, good luck with that, Smalltalk invented the
concept.

http://www.cocoawithlove.com/2010/01/what-is-meta-class-in-objective-c.html

http://pharo.gforge.inria.fr/PBE1/PBE1ch14.html

If you think there's another definition of "metaclass" in widespread use,
please give some citations or links.

What I will accept is that implementing class composition using the +
operator *could* be implemented via the metaclass, at least in languages
with metaclasses. But that's not the only way to do it. Java, for example,
has no metaclasses (classes are not themselves objects in Java), but the
Java language could easily define "Type + Type" as a way of composing types.
It just wouldn't work via the metaclass.

That's what I mean by "it has nothing to do with metaclasses" -- you can
implement this without using metaclasses.


>> I can see why:
>> >
>> >     NewType = OldType + Mixin
>> >
>> > appears more attractive at first glance than:
>> >
>> >     class NewType(OldType, Mixin):
>> >         pass
>> >
>> > since it saves a lot of boilerplate. But in practice, the body of the
>> > class is not often "pass". More often, you end up overriding or adding
>> > new methods. In that case, the suggested syntax has no advantage.
>>
>
> Adding new methods is exactly what this syntax is supposed to do.

No, it creates a new class which inherits *existing* methods belonging to
the two composed classes, OldType and Mixin. It doesn't create any methods
that don't already exist.


> The tricky part is overriding existing methods.

Precisely. If you want NewType.method to override either parent
(OldType.method and/or Mixin.method) you need more than just a type
composition operator. In Python you would use a class statement:

class NewType(OldType + Mixin):
    def method(self):
        ...


You would also do the same to add a new method not provided by either
OldType or the Mixin.


--
Steve


Reply | Threaded
Open this post in threaded view
|

operations on types

Steven D'Aprano-8
In reply to this post by Steven D'Aprano-11
On Wed, 17 Jun 2015 02:58 pm, Ian Kelly wrote:

> On Tue, Jun 16, 2015 at 8:04 PM, Steven D'Aprano
> <steve+comp.lang.python at pearwood.info> wrote:
>> On Tue, 16 Jun 2015 19:24:03 -0500, Dr. John Q. Hacker wrote:
>>
>>> [Dr. Bigcock wrote:]
>>>> The current syntax for adding functionality to a class using mix-in
>>>> style via inheritance list conflates two very different things.
>>
>> I'm not sure why you are taking "Dr Bigcock" seriously. You know he isn't
>> actually a doctor?
>
> I'm reasonably certain that they're actually the same person, and he's
> now engaging in sockpuppetry [1] by starting conversations with
> himself. He's not trying very hard to hide it, signing posts with both
> accounts as "zipher" and then lamp-shading that fact by commenting on
> it. I can't even find any record that "Dr. Bigcock" ever actually
> posted the text that "Dr. John Q. Hacker" is now responding to.


I must admit that the possibility of a sockpuppet crossed my mind too, even
to the point of checking the headers of their posts to see if they came
from the same IP address. (Inconclusive.)

But there was an earlier post from Mark Jansen, a.k.a. Mark
Rosenblitt-Janssen, Dr Bigcock, and Zipher, starting this thread a few days
earlier. I won't link to it, but the relevant headers are:


Subject: operations on types
From: <dreamingforward at gmail.com>
Date: Tue, 16 Jun 2015 09:30:01 -0700 (PDT)
Groups: comp.lang.python


posted from Google Groups. "Dr Hacker", if he really is a doctor or a
hacker, replied via the python-list mailing list, but broke threading when
doing so. (Alas, this is not an unusual thing to happen.)

At the moment, I'm still willing to give Dr Hacker the benefit of the doubt
re the sockpuppet suspicion.



--
Steven


Reply | Threaded
Open this post in threaded view
|

operations on types

Ned Batchelder
On Wednesday, June 17, 2015 at 7:52:05 AM UTC-4, Steven D'Aprano wrote:

> On Wed, 17 Jun 2015 02:58 pm, Ian Kelly wrote:
>
> > On Tue, Jun 16, 2015 at 8:04 PM, Steven D'Aprano
> > <steve+comp.lang.python at pearwood.info> wrote:
> >> I'm not sure why you are taking "Dr Bigcock" seriously. You know he isn't
> >> actually a doctor?
> >
> > I'm reasonably certain that they're actually the same person, and he's
> > now engaging in sockpuppetry [1] by starting conversations with
> > himself. He's not trying very hard to hide it, signing posts with both
> > accounts as "zipher" and then lamp-shading that fact by commenting on
> > it. I can't even find any record that "Dr. Bigcock" ever actually
> > posted the text that "Dr. John Q. Hacker" is now responding to.
>
>
> I must admit that the possibility of a sockpuppet crossed my mind too, even
> to the point of checking the headers of their posts to see if they came
> from the same IP address. (Inconclusive.)
>
> At the moment, I'm still willing to give Dr Hacker the benefit of the doubt
> re the sockpuppet suspicion.

If you search for "zondervanz", you will find the GitHub account theProhpet
with that email address: https://github.com/theProphet

There you will find a repo with commits like this one where theProphet adds
attributions to Mark Janssen:

https://github.com/theProphet/GlassBeadGame/commit/a1f5082feb76fb0d51b069dc81de2228ff36a221

The INSTALL file lists the owner as Mark:

https://github.com/theProphet/GlassBeadGame/blob/master/INSTALL

The Sourceforge page from that INSTALL is pangaia.sf.net, which
lists the Twitter account https://twitter.com/Xer0Dynamite, which
includes this tweet, asking to be called Dr Bigcock:

https://twitter.com/Xer0Dynamite/status/594217063725592577

We've been through this before.  Mark is energetic, and tantalizing,
but not worth engaging.

--Ned.

Reply | Threaded
Open this post in threaded view
|

operations on types

Steven D'Aprano-8
On Thu, 18 Jun 2015 12:26 am, Ned Batchelder wrote:

> On Wednesday, June 17, 2015 at 7:52:05 AM UTC-4, Steven D'Aprano wrote:

>> At the moment, I'm still willing to give Dr Hacker the benefit of the
>> doubt re the sockpuppet suspicion.
>
> If you search for "zondervanz", you will find the GitHub account
> theProhpet with that email address: https://github.com/theProphet
[...]

Ah, well that certainly clears up any lingering doubt. Thanks for your
detective work.


--
Steven


Reply | Threaded
Open this post in threaded view
|

operations on types

Michael Torrie
On 06/17/2015 09:42 AM, Steven D'Aprano wrote:

> On Thu, 18 Jun 2015 12:26 am, Ned Batchelder wrote:
>
>> On Wednesday, June 17, 2015 at 7:52:05 AM UTC-4, Steven D'Aprano wrote:
>
>>> At the moment, I'm still willing to give Dr Hacker the benefit of the
>>> doubt re the sockpuppet suspicion.
>>
>> If you search for "zondervanz", you will find the GitHub account
>> theProhpet with that email address: https://github.com/theProphet
> [...]
>
> Ah, well that certainly clears up any lingering doubt. Thanks for your
> detective work.

Indeed thank you. I've added this new email address to my filter (though
gmail's filters are rather awkward).