FAQ
The Python FAQ 1.4.5 gives 3 reasons for explicit self (condensed version):

1. Instance variables can be easily distinguished from local variables.

2. A method from a particular class can be called as
baseclass.methodname(self, <argument list>).

3. No need for declarations to disambiguate assignments to local/instance
variables.

All these reasons are valid and retained by the following suggestion: let
self be represented by the dot, e.g. replace

class someTest(unittest.TestCase):
def setUp(self):
self.ly = yList()
self.m1 = self.ly[0].message
self.m2 = self.ly[1].message
self.m3 = self.ly[2].message

def testList(self):
self.assertEqual(len(self.ly),3)
self.assertEqual(self.m1),"Ho")
self.assertEqual(self.m2),"HoHo")
self.assertEqual(self.m3),"HoHoHo")

by

class x(unittest.TestCase):
def .setUp():
.ly = yList()
.m1 = .ly[0].message
.m2 = .ly[1].message
.m3 = .ly[2].message

def .testList():
.assertEqual(len(.ly),3)
.assertEqual(.m1),"Ho")
.assertEqual(.m2),"HoHo")
.assertEqual(.m3),"HoHoHo")

Methods could still be referenced e.g. as x.testList(someInstance).
The current self syntax could still be valid (for backward compatibility.)
Advantages of the new syntax:

1. Enhanced readability, less verbosity

2. Unambiguous: no need to tell newbies that a virtuous pythoneer
has to stick to self instead of abbreviate it as s.

3. One argument less for "Python OO bolted on" propaganda.

The second reason is the most important for me. I consider syntax control
by a code of conduct as lame.

The "leading dot" syntax could have further advantages:

class x(object):
a = "" # static variable
.b = 0 # instance variable

This could replace parameterless __init__ methods. Methods without leading
dots could be considered static without a staticmethod decorator. For
backward compatibility this behaviour should be explicitly activated e.g. by
__autostatic__ = true.

What do you think?

--
Regards/Gruesse,

Peter Maas, Aachen
E-mail 'cGV0ZXIubWFhc0B1dGlsb2cuZGU=\n'.decode('base64')

Search Discussions

  • Fredrik Lundh at Nov 11, 2006 at 10:16 pm

    Peter Maas wrote:

    What do you think?
    cannot all you clueless trolls who cannot think of a single useful thing
    to contribute to Python start your own newsgroup?

    </F>
  • Fredrik Lundh at Nov 11, 2006 at 10:23 pm

    cannot all you clueless trolls who cannot think of a single useful thing
    to contribute to Python start your own newsgroup?
    and before anyone complains; please note that they're working through

    http://www.effbot.org/pyfaq/design-index.htm

    one article at a time. who's going to be the first one to argue that
    Python needs a goto statement ?

    </F>
  • Doug at Nov 11, 2006 at 11:40 pm

    Fredrik Lundh wrote:
    Fredrik Lundh wrote:
    cannot all you clueless trolls who cannot think of a single useful thing
    to contribute to Python start your own newsgroup?
    and before anyone complains; please note that they're working through

    http://www.effbot.org/pyfaq/design-index.htm
    That site is a bunch of FUD -
    The explicit self is there simply because OOP was tacked onto python as
    an afterthought.
    Why not just be honest about it. It's too late to change Python's
    syntax. It just means a little extra typing. If it really bothers
    someone, use "s" instead of "self" or else use Ruby.
  • Fredrik Lundh at Nov 12, 2006 at 12:00 am

    Doug (Holton?) wrote:

    and before anyone complains; please note that they're working through

    http://www.effbot.org/pyfaq/design-index.htm
    That site is a bunch of FUD -
    the official FAQ is a bunch of FUD? are you sure you know what FUD means?

    </F>
  • Skip at Nov 12, 2006 at 12:09 am
    Doug> The explicit self is there simply because OOP was tacked onto
    Doug> python as an afterthought.

    Got a reference to support that claim?

    Skip
  • Steven D'Aprano at Nov 12, 2006 at 12:44 am

    On Sat, 11 Nov 2006 18:09:59 -0600, skip wrote:
    Doug> The explicit self is there simply because OOP was tacked onto
    Doug> python as an afterthought.

    Got a reference to support that claim?
    Of course not, since it is a classic example of trolling.

    By comparison, the way I read the Original Poster, he was sincere if
    misguided -- but Doug's bullshit response is a typical attempt to throw
    petrol on an already hot situation.


    --
    Steven.
  • Doug at Nov 12, 2006 at 7:14 am

    Fredrik Lundh wrote:
    Doug wrote:
    Fredrik Lundh wrote:
    Fredrik Lundh wrote:
    cannot all you clueless trolls who cannot think of a single useful thing
    to contribute to Python start your own newsgroup?
    and before anyone complains; please note that they're working through
    http://www.effbot.org/pyfaq/design-index.htm
    That site is a bunch of FUD -
    The explicit self is there simply because OOP was tacked onto python as
    an afterthought.
    Why not just be honest about it. It's too late to change Python's
    syntax. It just means a little extra typing. If it really bothers
    someone, use "s" instead of "self" or else use Ruby.
    the official FAQ is a bunch of FUD? are you sure you know what FUD means?

    </F>
    You idiot. Putting the word "official" in front of something doesn't
    mean it can't be FUD. Especially when it is written by people such as
    yourself. Have you not paid attention to anything happening in
    politics around the world during your lifetime?
    And yes, actually, the dash after FUD was where I was going to link to
    a definition of FUD to show I really meant to use that term. It
    doesn't appear that you believe anything that isn't on your own effbot
    site, however.
  • Alan G Isaac at Nov 12, 2006 at 11:49 am

    On Sun, 12 Nov 2006 02:14:32 -0500, Doug wrote:
    I was going to link to
    a definition of FUD to show I really meant to use that term.
    Oooh.
    If you had just mentioned your dyslogia,
    it would have saved us all some time.
    Thanks!
    Alan
  • Carsten Haese at Nov 12, 2006 at 5:12 pm

    On Sat, 2006-11-11 at 23:14 -0800, Doug wrote:
    Fredrik Lundh wrote:
    Doug wrote:
    Fredrik Lundh wrote:
    Fredrik Lundh wrote:
    cannot all you clueless trolls who cannot think of a single useful thing
    to contribute to Python start your own newsgroup?
    and before anyone complains; please note that they're working through
    http://www.effbot.org/pyfaq/design-index.htm
    That site is a bunch of FUD -
    The explicit self is there simply because OOP was tacked onto python as
    an afterthought.
    Why not just be honest about it. It's too late to change Python's
    syntax. It just means a little extra typing. If it really bothers
    someone, use "s" instead of "self" or else use Ruby.
    the official FAQ is a bunch of FUD? are you sure you know what FUD means?

    </F>
    You idiot. Putting the word "official" in front of something doesn't
    mean it can't be FUD.
    Fredrik doesn't have to prove that the official FAQ isn't FUD. You,
    Doug, have to prove that it is, because you accused it of being FUD.

    By your logic, I can prove that you are a piece of cheddar cheese. I
    will simply assert that you are a piece of cheddar cheese. You might
    respond by making a surprisingly lucid (for a piece of cheddar) argument
    that you are a sentient being. To this I will respond "You idiot,
    proving that you are a sentient being doesn't mean you can't be a piece
    of cheddar." QED.

    Since you are too lazy to post the wikipedia link, please allow me:
    http://en.wikipedia.org/wiki/Fear%2C_uncertainty_and_doubt

    According to that definition, FUD is "a sales or marketing strategy of
    disseminating negative (and vague) information on a competitor's
    product."

    Even if the FAQ could, by a stretch of the imagination, be considered a
    sales or marketing strategy, you'd be hard-pressed to find evidence of
    it disseminating negative information on a competitor's product. Hence,
    it's not FUD.

    -Carsten
  • Fredrik Lundh at Nov 12, 2006 at 5:36 pm

    Carsten Haese wrote:

    According to that definition, FUD is "a sales or marketing strategy of
    disseminating negative (and vague) information on a competitor's
    product."
    Doug "cheddar cheese" Holton (who has a long history of posting
    seriously confused and/or abusive stuff under a number of aliases) is
    a developer of a "competing" language named Boo.

    I suppose that in his view, language advocacy is a zero-sum game, so
    positive comments about Python can be considered as FUD against his own
    project. He's even invented his own del.icio.us tag for this purpose:

    http://del.icio.us/tag/pythonfud

    </F>
  • Fredrik Lundh at Nov 13, 2006 at 12:06 am

    I suppose that in his view, language advocacy is a zero-sum game, so
    positive comments about Python can be considered as FUD against his own
    project. He's even invented his own del.icio.us tag for this purpose:

    http://del.icio.us/tag/pythonfud
    now at:

    http://del.icio.us/tag/python-fud

    </F>
  • Simon Brunning at Nov 13, 2006 at 4:57 pm

    On 11/13/06, Fredrik Lundh wrote:
    I suppose that in his view, language advocacy is a zero-sum game, so
    positive comments about Python can be considered as FUD against his own
    project. He's even invented his own del.icio.us tag for this purpose:

    http://del.icio.us/tag/pythonfud
    now at:

    http://del.icio.us/tag/python-fud

    </F>
    Hey, Fredrik, you have your own tag!
    <http://del.icio.us/tag/fredrik-lundh-troll> I wish *I* had my own
    tag. ;-)

    I notice that, as you predicted, Python's lack of a goto is in there too.

    --
    Cheers,
    Simon B
    simon at brunningonline.net
    http://www.brunningonline.net/simon/blog/
  • Christophe at Nov 13, 2006 at 5:02 pm

    Simon Brunning a ?crit :
    On 11/13/06, Fredrik Lundh wrote:

    I suppose that in his view, language advocacy is a zero-sum game, so
    positive comments about Python can be considered as FUD against his own
    project. He's even invented his own del.icio.us tag for this purpose:

    http://del.icio.us/tag/pythonfud
    now at:

    http://del.icio.us/tag/python-fud

    </F>
    Hey, Fredrik, you have your own tag!
    <http://del.icio.us/tag/fredrik-lundh-troll> I wish *I* had my own
    tag. ;-)

    I notice that, as you predicted, Python's lack of a goto is in there too.
    Hey, this is fun :D I also found that one :
    http://del.icio.us/dholton/python-fud-by-fredrik-lundh

    But is seems they all point to the same article than yours so you get
    the points for it ;)
  • Fynali at Nov 13, 2006 at 3:13 pm

    You idiot. Putting the word "official" in front of something doesn't
    mean it can't be FUD. Especially when it is written by people such as
    yourself. Have you not paid attention to anything happening in
    politics around the world during your lifetime?
    Ridiculous boo-llshit!
  • Steve Holden at Nov 13, 2006 at 9:29 am
    Doug wrote:
    [...]
    The explicit self is there simply because OOP was tacked onto python as
    an afterthought.
    No, it was added in such a way that Python would be useful as a
    procedural as well as an OO language.

    I don't know what's got into me.

    can't-normally-say-boo-to-a-goose-ly y'rs - steve
    --
    Steve Holden +44 150 684 7255 +1 800 494 3119
    Holden Web LLC/Ltd http://www.holdenweb.com
    Skype: holdenweb http://holdenweb.blogspot.com
    Recent Ramblings http://del.icio.us/steve.holden
  • Fredrik Lundh at Nov 12, 2006 at 12:55 am

    Dennis Lee Bieber wrote:

    one article at a time. who's going to be the first one to argue that
    Python needs a goto statement ?
    Especially since there is a comefrom <G>
    ah, good point. I've updated the FAQ.

    </F>
  • Duncan Booth at Nov 12, 2006 at 9:55 am

    Dennis Lee Bieber wrote:

    On Sun, 12 Nov 2006 01:55:35 +0100, Fredrik Lundh
    <fredrik at pythonware.com> declaimed the following in comp.lang.python:

    ah, good point. I've updated the FAQ.
    Ah, but do we dare update the Wikipedia link to include Python as a
    language capable of COMEFROM? <G>
    Somebody definitely should. The current wikipedia article contains an
    example in a hypothetical dialect of BASIC ('because an actual example in
    INTERCAL would be too difficult to read'). Somebody should enhance the
    article with the equivalent example in Python which is both easy to read
    and can actually be run:

    from goto import goto, comefrom, label

    comefrom .repeat
    name = raw_input('what is your name? ')
    if name:
    print "Hello",name
    label .repeat

    print "Goodbye!"
  • Hendrik van Rooyen at Nov 12, 2006 at 11:15 am

    "Dennis Lee Bieber" wrote:


    Especially since there is a comefrom <G>

    *breaks into song* : "Oh Susannah, now don't you cry for me..."
  • Steven D'Aprano at Nov 12, 2006 at 2:42 am
    On Sat, 11 Nov 2006 22:39:37 +0100, Peter Maas wrote:

    [snip]
    let self be represented by the dot, e.g. replace

    class someTest(unittest.TestCase):
    def setUp(self):
    self.ly = yList()
    self.m1 = self.ly[0].message
    self.m2 = self.ly[1].message
    self.m3 = self.ly[2].message
    by

    class x(unittest.TestCase):
    def .setUp():
    .ly = yList()
    .m1 = .ly[0].message
    .m2 = .ly[1].message
    .m3 = .ly[2].message
    On the assumption that Peter was sincere, and not trolling, I thought I'd
    make a point-by-point response, but then X crashed and took my post with
    it. So here's the brief version.

    Implicit self will never be used for Python, because it is redundant so
    long as there is a need for explicit self, and there is a need for
    explicit self because there are a number of basic, dare I say
    *fundamental* programming techniques that require an explicit self.

    For example, delegation.

    class MyClass(Parent):
    def method(self, arg):
    Parent.method(self, arg)
    # what are you going to write? Parent.method(,arg) maybe?

    Here's another fundamental technique that implicit self breaks.

    class MyList(list):
    def __iadd__(self, other):
    # in-place addition
    other = transform(other) # do something to the argument
    super(MyList, self).__iadd__(other) # call the superclass
    # could be written .__class__.__iadd__(other)
    # BUT be aware the semantics are NOT the same!
    return self # and return the suitably modified instance

    You can't explicitly return the instance unless you have an explicit name
    for it. (And if you are thinking of creating more magic syntax that
    implicitly returns self, just don't bother.)

    Even more fundamentally, any time you need to pass the instance to a
    function, you need an explicit self. (Delegation is a special case of this.)

    def __str__(self):
    # I like semicolons and dislike square brackets.
    return ';'.join(self)



    --
    Steven.
  • Peter Maas at Nov 13, 2006 at 10:03 pm

    Steven D'Aprano schrieb:
    Implicit self will never be used for Python, because it is redundant so
    long as there is a need for explicit self, and there is a need for
    explicit self because there are a number of basic, dare I say
    *fundamental* programming techniques that require an explicit self.

    For example, delegation.

    class MyClass(Parent):
    def method(self, arg):
    Parent.method(self, arg)
    # what are you going to write? Parent.method(,arg) maybe?
    The idea is: let self (or self.) be represented by the dot alone,
    therefore:

    Parent.method(., arg) # :)
    Here's another fundamental technique that implicit self breaks.

    class MyList(list):
    def __iadd__(self, other):
    # in-place addition
    other = transform(other) # do something to the argument
    super(MyList, self).__iadd__(other) # call the superclass
    # could be written .__class__.__iadd__(other)
    # BUT be aware the semantics are NOT the same!
    return self # and return the suitably modified instance return .
    You can't explicitly return the instance unless you have an explicit name
    for it. (And if you are thinking of creating more magic syntax that
    implicitly returns self, just don't bother.)
    No magic. Just a dot. But perhaps a dot is too tiny. We could take JUST_ME
    or ME_AND_BOBBY_MCGEE instead, of course as a reserved keyword followed by a
    dot ;)

    Thanks for your hints, Steven.

    --
    Regards/Gruesse,

    Peter Maas, Aachen
    E-mail 'cGV0ZXIubWFhc0B1dGlsb2cuZGU=\n'.decode('base64')
  • Baalbek at Nov 18, 2006 at 1:20 am

    Peter Maas wrote:

    No magic. Just a dot. But perhaps a dot is too tiny. We could take JUST_ME
    or ME_AND_BOBBY_MCGEE instead, of course as a reserved keyword followed
    by a
    dot ;)
    Why a dot, and not a @, like in Ruby and Perl?

    I think a dot is a particular bad idea, not the least due to poorer
    readability of code (and thou shall not underestimate the readability of
    code!).

    Baalbek
  • Michele Simionato at Nov 13, 2006 at 8:51 am

    Peter Maas wrote:
    The Python FAQ 1.4.5 gives 3 reasons for explicit self (condensed version):

    1. Instance variables can be easily distinguished from local variables.

    2. A method from a particular class can be called as
    baseclass.methodname(self, <argument list>).

    3. No need for declarations to disambiguate assignments to local/instance
    variables.

    All these reasons are valid and retained by the following suggestion: let
    self be represented by the dot <snip>
    This suggestion has been discussed in the past (I remember having the
    same idea
    myself when I first learned Python). But at the end I believe the
    explicit 'self' is
    a better solution, because there are cases where it is useful to have
    it (see Steven
    d'Aprano's post) and also I like the fact that I can spell it 'cls' in
    classmethods and in
    metaclasses. After a while one gets used to it and if you think a bit
    it makes quite a
    lot sense. Also, having the self explicit, makes Python object system
    better (i.e.
    it goes more in the direction of CLOS and less in the direction of
    Java).

    Michele Simionato
  • Peter Maas at Nov 13, 2006 at 6:08 pm

    Michele Simionato wrote:
    Peter Maas wrote:
    All these reasons are valid and retained by the following suggestion: let
    self be represented by the dot <snip>
    This suggestion has been discussed in the past (I remember having the
    same idea myself when I first learned Python). But at the end I believe
    the explicit 'self' is a better solution, because there are cases where
    it is useful to have it
    Thanks, Michele. My intention wasn't to abandon explicit self but to replace
    it by a shorter and unique entity. I searched a little for similar suggestions
    in the past but didn't find them so I decided to post. I admit that my
    suggestion was half-baked.

    But at least I learned something: a heated debate isn't bound to become an
    endless thread if the OP abstains from answering idiot replies ;)

    --
    Regards/Gruesse,

    Peter Maas, Aachen
    E-mail 'cGV0ZXIubWFhc0B1dGlsb2cuZGU=\n'.decode('base64')
  • Fredrik Lundh at Nov 13, 2006 at 9:57 pm

    Peter Maas wrote:

    But at least I learned something: a heated debate isn't bound to become an
    endless thread if the OP abstains from answering idiot replies ;)
    trolling is trolling even if you use smilies. I'm sure you can find a
    way to actually *contribute* to Python if you really want to...

    </F>

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedNov 11, '06 at 9:39p
activeNov 18, '06 at 1:20a
posts25
users16
websitepython.org

People

Translate

site design / logo © 2022 Grokbase