What is not objects in Python?

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

    #16
    Re: What is not objects in Python?

    George Sakkis wrote:
    As Terry Reedy wrote, partly history and partly practicality. There's
    no philosophical reason why we write "len(x)" (generic builtin),
    "x.append(1 )" (method) or "del x[i]" (statement). The latter in
    particular is IMHO a design wart; there's no reason for not writing it
    as "x.delete(i )".
    `del x` has almost nothing to do with `x`, and almost everything to do with
    a namespace containing `x`. The object doesn't know what namespace it's
    in.

    Mel.

    Comment

    • Marc 'BlackJack' Rintsch

      #17
      Re: What is not objects in Python?

      On Mon, 29 Sep 2008 11:14:36 -0400, Mel wrote:
      George Sakkis wrote:
      >As Terry Reedy wrote, partly history and partly practicality. There's
      >no philosophical reason why we write "len(x)" (generic builtin),
      >"x.append(1) " (method) or "del x[i]" (statement). The latter in
      >particular is IMHO a design wart; there's no reason for not writing it
      >as "x.delete(i )".
      >
      `del x` has almost nothing to do with `x`, and almost everything to do
      with a namespace containing `x`. The object doesn't know what namespace
      it's in.
      But George's example was ``del x[i]`` which *has* something to do with
      `x` as it mutates the object (or at least calls `x.__delitem__( )`).

      Ciao,
      Marc 'BlackJack' Rintsch

      Comment

      • bearophileHUGS@lycos.com

        #18
        Re: What is not objects in Python?

        George Sakkis:
        No difference in principle, just len() happens to be implemented more
        often than upper().
        That's an important point. In a language that tries to be both
        practical, readable, and elegant, the things that are done more may
        deserve some sugar, to avoid code like this in many cases:

        sorted(seq, key=lambda x:x.__len__())

        Bye,
        bearophile

        Comment

        • George Sakkis

          #19
          Re: What is not objects in Python?

          On Sep 29, 11:37 am, bearophileH...@ lycos.com wrote:
          George Sakkis:
          >
          No difference in principle, just len() happens to be implemented more
          often than upper().
          >
          That's an important point. In a language that tries to be both
          practical, readable, and elegant, the things that are done more may
          deserve some sugar, to avoid code like this in many cases:
          >
          sorted(seq, key=lambda x:x.__len__())
          If this was the most compelling use case of having len as builtin, I
          would be even less convinced. How often do you sort by len? FWIW, the
          most common sorting keys I see in real world are attrgetter(some _attr)
          or itemgetter(some _index) and both are imported functions, not
          builtins.

          George

          Comment

          • Terry Reedy

            #20
            Re: What is not objects in Python?

            George Sakkis wrote:
            Sure, "len" looks better than lambda x:x.__len__(), but the same would
            be true if there was an "upper" builtin for the following example:
            >
            >>>s = ['a', 'd', 'B', 'C']
            >>>s2 = [u'a', u'd', u'B', u'C']
            >>>upper = lambda x: x.upper()
            >>>sorted(s, key=upper)
            ['a', 'B', 'C', 'd']
            >>>sorted(s2, key=upper)
            [u'a', u'B', u'C', u'd']
            >
            No difference in principle, just len() happens to be implemented more
            often than upper().
            I disagree. One versus many classes is a principle. If a method is
            used on objects of just one class, the class attribute can be used and
            passed directly.

            sorted(s, key = str.upper)
            sorted(s2, key = unicode.upper)

            The problem is having two text classes, which Guido considers to be a
            mess and which Python did not have originally and which 3.0 also does
            not have, even though bytes keeps the string methods. Mixing int, long,
            and float numbers is or should be more common than mixing str and
            unicode strings, and certainly more common than mixing str strings and
            bytes in 3.0 (which is actively discouraged).

            To me, discerning the implicit principles of Python's design makes it
            easier to learn and remember, even if they are not as exact as one might
            like. The choices are not random, and so one can do better than rote
            memory.

            Terry Jan Reedy

            Comment

            • Steven D'Aprano

              #21
              Re: What is not objects in Python?

              On Mon, 29 Sep 2008 05:41:02 -0700, George Sakkis wrote:
              For example I would be much less
              opposed to len() being defined as, say, |x| if "|...|" was a valid
              operator.
              Arghh! No!!! |x| should be abs(x), not len(x). Just ask mathematicians
              and physicists.

              *wink*

              Actually there's a serious point there. There aren't that many
              unambiguous operators that are available on a standard keyboard that
              (nearly) everyone can agree on.


              --
              Steven

              Comment

              • Terry Reedy

                #22
                Re: What is not objects in Python?

                Steven D'Aprano wrote:
                On Mon, 29 Sep 2008 05:41:02 -0700, George Sakkis wrote:
                >
                >For example I would be much less
                >opposed to len() being defined as, say, |x| if "|...|" was a valid
                >operator.
                >
                Arghh! No!!! |x| should be abs(x), not len(x). Just ask mathematicians
                and physicists.
                It should be both, just as + is addition for numbers and concatenation
                for sequences. Or we could have just one built-in -- size() instead of
                abs() and len(). For non-sequence collections, size() would be better
                than len() anyway.

                tjr

                Comment

                • namekuseijin

                  #23
                  Re: What is not objects in Python?

                  On 28 set, 15:29, process <circularf...@g mail.comwrote:
                  I have heard some criticism about Python, that it is not fully object-
                  oriented.
                  So what?
                  Why isn't len implemented as a str.len and list.len method instead of
                  a len(list) function?
                  Because postfix notation sucks. The natural way of spelling is
                  adjective+noun and verb+predicate. That's one of the reasons I like
                  Lisp better than Python.

                  Comment

                  • Roy Smith

                    #24
                    Re: What is not objects in Python?

                    In article <mailman.1716.1 222747204.3487. python-list@python.org >,
                    Terry Reedy <tjreedy@udel.e duwrote:
                    It should be both, just as + is addition for numbers and concatenation
                    for sequences.
                    Actually, the math folks would argue that using + for concatenation is
                    wrong, since by normal math rules, + denotes a commutative operation.

                    Of course, the math folks think that i^2 = -1, so what do they know? All
                    right-thinking people know that j^2 = -1.

                    Comment

                    • Steven D'Aprano

                      #25
                      Re: What is not objects in Python?

                      On Mon, 29 Sep 2008 21:03:07 -0700, namekuseijin wrote:
                      >Why isn't len implemented as a str.len and list.len method instead of a
                      >len(list) function?
                      >
                      Because postfix notation sucks. The natural way of spelling is
                      adjective+noun and verb+predicate.
                      "Natural"?

                      You mean phrases like "heir apparent" and "worst choice imaginable" are
                      unnatural? To say nothing of languages like Spanish, Albanian, Italian,
                      Cornish, Vietnamese, Hebrew...



                      --
                      Steven

                      Comment

                      • Gabriel Genellina

                        #26
                        Re: What is not objects in Python?

                        En Tue, 30 Sep 2008 01:03:07 -0300, namekuseijin <namekuseijin@g mail.com>
                        escribió:
                        On 28 set, 15:29, process <circularf...@g mail.comwrote:
                        >Why isn't len implemented as a str.len and list.len method instead of
                        >a len(list) function?
                        >
                        Because postfix notation sucks. The natural way of spelling is
                        adjective+noun and verb+predicate. That's one of the reasons I like
                        Lisp better than Python.
                        Well, "natural" for English-speaking people... Noun+adjective is usually
                        more "natural" In Spanish than the English word ordering.

                        Back to the original question, len(x) allows for a fast response without
                        paying the overhead of a name lookup and then a method call.
                        len(some_list) doesn't invoke some_list.__len __(), it just returns the
                        value stored somewhere in the list object; same for other built-in
                        objects. __len__ is searched as a last resort only.
                        The optimization could not be done if it were spelled x.len()

                        --
                        Gabriel Genellina

                        Comment

                        • Steve Holden

                          #27
                          Re: What is not objects in Python?

                          Terry Reedy wrote:
                          Steven D'Aprano wrote:
                          >On Mon, 29 Sep 2008 05:41:02 -0700, George Sakkis wrote:
                          >>
                          >>For example I would be much less
                          >>opposed to len() being defined as, say, |x| if "|...|" was a valid
                          >>operator.
                          >>
                          >Arghh! No!!! |x| should be abs(x), not len(x). Just ask mathematicians
                          >and physicists.
                          >
                          It should be both, just as + is addition for numbers and concatenation
                          for sequences. Or we could have just one built-in -- size() instead of
                          abs() and len(). For non-sequence collections, size() would be better
                          than len() anyway.
                          >
                          And how are these "non-sequence collections" to be distinguished? And
                          how does size() differ from len() in that case?

                          regards
                          Steve
                          --
                          Steve Holden +1 571 484 6266 +1 800 494 3119
                          Holden Web LLC http://www.holdenweb.com/

                          Comment

                          • Lie Ryan

                            #28
                            Re: What is not objects in Python?

                            On Mon, 2008-09-29 at 21:03 -0700, namekuseijin wrote:
                            On 28 set, 15:29, process <circularf...@g mail.comwrote:
                            I have heard some criticism about Python, that it is not fully object-
                            oriented.
                            >
                            So what?
                            >
                            Why isn't len implemented as a str.len and list.len method instead of
                            a len(list) function?
                            >
                            Because postfix notation sucks. The natural way of spelling is
                            adjective+noun and verb+predicate. That's one of the reasons I like
                            Lisp better than Python.
                            --

                            >
                            Actually str.len and len(str) is just like saying "the string's length"
                            and "the length of the string". There is no difference between the two
                            except for personal preference. (I am no linguist-- not even a native
                            speaker of English --but I think there is a subtle difference on
                            emphasis, "the string's length" emphasizes on the length being string's
                            property, while "the length of the string" emphasizes on the length
                            itself, am I correct?)


                            Comment

                            • Steve Holden

                              #29
                              Re: What is not objects in Python?

                              Steven D'Aprano wrote:
                              On Mon, 29 Sep 2008 21:03:07 -0700, namekuseijin wrote:
                              >
                              >>Why isn't len implemented as a str.len and list.len method instead of a
                              >>len(list) function?
                              >Because postfix notation sucks. The natural way of spelling is
                              >adjective+no un and verb+predicate.
                              >
                              "Natural"?
                              >
                              You mean phrases like "heir apparent" and "worst choice imaginable" are
                              unnatural?
                              They are certainly far from normal usage, as my dog yellow would be
                              certain to agree.
                              To say nothing of languages like Spanish, Albanian, Italian,
                              Cornish, Vietnamese, Hebrew...
                              It's long been a convention in the Western programming world to pretend
                              no other language than English and no other codes than ASCII exist.

                              The fact that Python is beginning to come to terms with Unicode is a
                              tribute to certain developers' persistence.

                              regards
                              Steve
                              --
                              Steve Holden +1 571 484 6266 +1 800 494 3119
                              Holden Web LLC http://www.holdenweb.com/

                              Comment

                              • Steve Holden

                                #30
                                Re: What is not objects in Python?

                                Steven D'Aprano wrote:
                                On Mon, 29 Sep 2008 21:03:07 -0700, namekuseijin wrote:
                                >
                                >>Why isn't len implemented as a str.len and list.len method instead of a
                                >>len(list) function?
                                >Because postfix notation sucks. The natural way of spelling is
                                >adjective+no un and verb+predicate.
                                >
                                "Natural"?
                                >
                                You mean phrases like "heir apparent" and "worst choice imaginable" are
                                unnatural?
                                They are certainly far from normal usage, as my dog yellow would be
                                certain to agree.
                                To say nothing of languages like Spanish, Albanian, Italian,
                                Cornish, Vietnamese, Hebrew...
                                It's long been a convention in the Western programming world to pretend
                                no other language than English and no other codes than ASCII exist.

                                The fact that Python is beginning to come to terms with Unicode is a
                                tribute to certain developers' persistence.

                                regards
                                Steve
                                --
                                Steve Holden +1 571 484 6266 +1 800 494 3119
                                Holden Web LLC http://www.holdenweb.com/

                                Comment

                                Working...