explicit self revisited

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michele Simionato

    #16
    Re: explicit self revisited

    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.metho dname(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

    Comment

    • Steve Holden

      #17
      Re: explicit self revisited

      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

      Comment

      • Hendrik van Rooyen

        #18
        Re: explicit self revisited

        "Dennis Lee Bieber" <wlfraed@ix.net com.comwrote:

        Especially since there is a comefrom <G>

        *breaks into song* : "Oh Susannah, now don't you cry for me..."

        Comment

        • fynali

          #19
          Re: Fredrik Lundh [was &quot;Re: explicit self revisited&quot;]

          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!

          Comment

          • Simon Brunning

            #20
            Re: explicit self revisited

            On 11/13/06, Fredrik Lundh <fredrik@python ware.comwrote:
            >
            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:
            >

            >
            </F>
            Hey, Fredrik, you have your own tag!
            <http://del.icio.us/tag/fredrik-lundh-trollI 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@brunningo nline.net

            Comment

            • Christophe

              #21
              Re: explicit self revisited

              Simon Brunning a écrit :
              On 11/13/06, Fredrik Lundh <fredrik@python ware.comwrote:
              >>
              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-trollI 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 :


              But is seems they all point to the same article than yours so you get
              the points for it ;)

              Comment

              • Peter Maas

                #22
                Re: explicit self revisited

                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 'cGV0ZXIubWFhc0 B1dGlsb2cuZGU=\ n'.decode('base 64')

                Comment

                • Fredrik Lundh

                  #23
                  Re: explicit self revisited

                  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>

                  Comment

                  • Peter Maas

                    #24
                    Re: explicit self revisited

                    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(s elf, 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__.__ia dd__(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_MC GEE instead, of course as a reserved keyword followed by a
                    dot ;)

                    Thanks for your hints, Steven.

                    --
                    Regards/Gruesse,

                    Peter Maas, Aachen
                    E-mail 'cGV0ZXIubWFhc0 B1dGlsb2cuZGU=\ n'.decode('base 64')

                    Comment

                    • baalbek

                      #25
                      Re: explicit self revisited

                      Peter Maas wrote:
                      No magic. Just a dot. But perhaps a dot is too tiny. We could take JUST_ME
                      or ME_AND_BOBBY_MC GEE 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

                      Comment

                      Working...