Origin of the term "first-class object"

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hung Jung Lu

    Origin of the term "first-class object"

    Hi,

    Does anybody know where this term comes from?

    "First-class object" means "something passable as an argument in a
    function call", but I fail to see the connection with "object class"
    or with "first-class airplane ticket". I just find the name a bit
    strange. Also, if there are first-class objects, what would the
    second-class objects or economy/tourist class objects be? :)

    Just wondering,

    Hung Jung
  • Erik Max Francis

    #2
    Re: Origin of the term "first-class object"

    Hung Jung Lu wrote:
    [color=blue]
    > Does anybody know where this term comes from?
    >
    > "First-class object" means "something passable as an argument in a
    > function call", but I fail to see the connection with "object class"
    > or with "first-class airplane ticket".[/color]

    It doesn't have any connection with the former (since the term long
    predates object orientation, so far as I know). It does have a
    connection to the latter, in that something going first class has all
    the privileges and properties owed to it as a complete and total thing.
    So a "first-class object" is a complete entity unto itself, and can be
    passed to functions and returned from them, as you suggest.

    Think of "first-class object" as "important thing" and maybe it'll make
    slightly more sense.

    --
    Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
    __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
    / \
    \__/ The only way to get rid of a temptation is to yield to it.
    -- Oscar Wilde

    Comment

    • Ben Finney

      #3
      Re: Origin of the term "first-class object"

      On 17 Nov 2003 13:35:36 -0800, Hung Jung Lu wrote:[color=blue]
      > "First-class object" means "something passable as an argument in a
      > function call", but I fail to see the connection with "object class"
      > or with "first-class airplane ticket".[/color]

      The term is analogous to "first-class citizen". It implies that no
      other kind of object has privilege to do more than this object, i.e. it
      has the most elevated object status -- first-class.
      [color=blue]
      > Also, if there are first-class objects, what would the second-class
      > objects or economy/tourist class objects be? :)[/color]

      Objects with fewer capabilities. E.g. in many OO-capable languages,
      built-in types are not first-class objects; you (variously) can't
      inherit from them, pass them as arguments, access their methods, etc.

      Using this term implies, by social analogy, that the existence of
      objects which are lower than first-class is undesirable and should be
      rectified by elevating the status of all objects toward the ideal state:
      where all are first-class.

      This is why Pythonistas are proud that everything in Python is a
      first-class object.

      --
      \ "If you get invited to your first orgy, don't just show up |
      `\ nude. That's a common mistake. You have to let nudity |
      _o__) 'happen.'" -- Jack Handey |
      Ben Finney <http://bignose.squidly .org/>

      Comment

      • John Roth

        #4
        Re: Origin of the term &quot;first-class object&quot;


        "Hung Jung Lu" <hungjunglu@yah oo.com> wrote in message
        news:8ef9bea6.0 311171335.356a7 af6@posting.goo gle.com...[color=blue]
        > Hi,
        >
        > Does anybody know where this term comes from?
        >
        > "First-class object" means "something passable as an argument in a
        > function call", but I fail to see the connection with "object class"
        > or with "first-class airplane ticket". I just find the name a bit
        > strange. Also, if there are first-class objects, what would the
        > second-class objects or economy/tourist class objects be? :)
        >
        > Just wondering,[/color]

        I'm not sure who started to use it, but to me it means that
        there are no restrictions on the object's use. It's the same as
        any other object. I'm also not sure what being able to pass
        it in a function call has to do with it; I'm used to being
        able to use them in a lot of other ways.

        For example, in Python both classes and functions are
        objects (there are no second class citizens in Python...)
        This means that I can rebind a class object into another
        module at run time, and access it under its new name.
        I can thow functions around with wild abandon, and even
        add attributes to them for some meta-data scheme, for
        example.

        In Java, neither classes nor methods are first class
        objects, even though you can get a "class" object
        if you ask politely, it's simply a special construct
        for the reflection mechanism.

        In C++, neither is an object, first class or not.

        John Roth

        [color=blue]
        >
        > Hung Jung[/color]


        Comment

        • Mike C. Fletcher

          #5
          Re: Origin of the term &quot;first-class object&quot;

          Hung Jung Lu wrote:
          [color=blue]
          >Hi,
          >
          >Does anybody know where this term comes from?
          >
          >"First-class object" means "something passable as an argument in a
          >function call", but I fail to see the connection with "object class"
          >or with "first-class airplane ticket". I just find the name a bit
          >strange. Also, if there are first-class objects, what would the
          >second-class objects or economy/tourist class objects be? :)
          >
          >[/color]
          "Second class citizens" are those denied the rights afforded to "first
          class citizens". In this context, first class objects are those which
          can participate in the (object) environment in the same manner as any
          other "normal" object. In many languages, classes are not able to be
          processed in the same manner as regular objects (e.g. being passed into
          functions, introspected for their type, holding properties).

          HTH,
          Mike

          _______________ _______________ _________
          Mike C. Fletcher
          Designer, VR Plumber, Coder





          Comment

          • Rainer Deyke

            #6
            Re: Origin of the term &quot;first-class object&quot;

            John Roth wrote:[color=blue]
            > For example, in Python both classes and functions are
            > objects (there are no second class citizens in Python...)[/color]

            I would consider variables to be second-class citizens. You can change
            their value, delete them, and get at the object to which they refer, but you
            can't do much else with them.
            [color=blue]
            > In Java, neither classes nor methods are first class
            > objects, even though you can get a "class" object
            > if you ask politely, it's simply a special construct
            > for the reflection mechanism.
            >
            > In C++, neither is an object, first class or not.[/color]

            While you can't create new functions and unbound methods in C++ at runtime,
            you can take their address and pass that around as a first class object.
            Bound methods are another matter.


            --
            Rainer Deyke - rainerd@eldwood .com - http://eldwood.com


            Comment

            • Erik Max Francis

              #7
              Re: Origin of the term &quot;first-class object&quot;

              Rainer Deyke wrote:
              [color=blue]
              > While you can't create new functions and unbound methods in C++ at
              > runtime,
              > you can take their address and pass that around as a first class
              > object.[/color]

              True, though that usually devolves into a semantic issue about whether
              functions are first-class if you can only manipulate pointers to them.
              I usually say C has first-class functions if you squint. C++ doesn't
              have first-class bound member function pointers, as you point out, and
              another obvious example in C++ is the lack of first-class classes -- a
              feature in Python that is extremely powerful, since it almost makes the
              "factory" pattern automatic in Python (the class object itself is just a
              callable type that creates instances).

              --
              Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
              __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
              / \
              \__/ And there inside our private war / I died the night before
              -- Sade

              Comment

              • Ben Finney

                #8
                Re: Origin of the term &quot;first-class object&quot;

                On Mon, 17 Nov 2003 23:18:52 GMT, Rainer Deyke wrote:[color=blue]
                > John Roth wrote:[color=green]
                >> there are no second class citizens in Python...[/color]
                >
                > I would consider variables to be second-class citizens. You can
                > change their value, delete them, and get at the object to which they
                > refer, but you can't do much else with them.[/color]

                AIUI, there are no "variables" in Python; or rather, the normal usage of
                that term is not precise enough in Python, since the task is split.
                There are names bound to objects.

                Objects are all first-class.

                Names are essentually a language device used to refer to an object. You
                don't "change their value"; you change the object to which they are
                bound.

                Names aren't objects, and I don't see what you'd gain if you started
                treating a name as an object; you'd merely need some additional way of
                referring to *those* objects somehow. (Meta-names, anyone?)

                Since names aren't objects, the question of whether they're first-class
                objects doesn't arise.

                --
                \ "We must respect the other fellow's religion, but only in the |
                `\ sense and to the extent that we respect his theory that his |
                _o__) wife is beautiful and his children smart." -- Henry L. Mencken |
                Ben Finney <http://bignose.squidly .org/>

                Comment

                • John Roth

                  #9
                  Re: Origin of the term &quot;first-class object&quot;


                  "Rainer Deyke" <rainerd@eldwoo d.com> wrote in message
                  news:wHcub.2276 49$Tr4.672235@a ttbi_s03...[color=blue]
                  > John Roth wrote:[color=green]
                  > > For example, in Python both classes and functions are
                  > > objects (there are no second class citizens in Python...)[/color]
                  >
                  > I would consider variables to be second-class citizens. You can change
                  > their value, delete them, and get at the object to which they refer, but[/color]
                  you[color=blue]
                  > can't do much else with them.[/color]

                  I think I'd disagree with that. In fact, except for the optimization
                  within function bodies, I can't think of anything I can't do
                  with a name that I might want to.

                  John Roth


                  Comment

                  • Rainer Deyke

                    #10
                    Re: Origin of the term &quot;first-class object&quot;

                    John Roth wrote:[color=blue]
                    > I think I'd disagree with that. In fact, except for the optimization
                    > within function bodies, I can't think of anything I can't do
                    > with a name that I might want to.[/color]


                    I can think of several things. One would be passing a name as an argument
                    to a function. Given the immutability of certain Python objects, it is
                    often necessary to write statements in the form of
                    "x = f(x)". This is a violation of the Once And Only Once principles, since
                    it mentions the same variable twice.

                    I'm not saying that the way Python deals with objects and variables is
                    wrong. Language design is a series of trade-offs, and the simplicity and
                    clarity of Python may very well make up for its limitations. However, that
                    doesn't mean that the limitations are not real.



                    --
                    Rainer Deyke - rainerd@eldwood .com - http://eldwood.com


                    Comment

                    • Terry Reedy

                      #11
                      Re: Origin of the term &quot;first-class object&quot;


                      "Rainer Deyke" <rainerd@eldwoo d.com> wrote in message
                      news:wHcub.2276 49$Tr4.672235@a ttbi_s03...[color=blue]
                      > I would consider variables to be second-class citizens.[/color]

                      In a sense, 'they' are not even citizens.

                      In Python, names are syntactic entities, not runtime objects (although
                      they sometimes get embodied in or represented as strings). They are
                      part of the code directing computation but are not the subject of
                      computation themselves (although strings representing them can be).
                      (But the CPython interpreter usually represents local function names
                      as C integers instead.) In themselves, names have neither id, type,
                      nor value, just a current binding to an object that does.

                      "Variable' is an informal term with multiple meanings even in
                      mathematics. In named-memory-block languages like C, a 'variable' is
                      a name associated with a fixed-address, mutable-content (value) block,
                      which before 'const', was (to my memory) every number (including
                      chars), array, and structure/union.

                      Python, being about objects rather than memory, has no direct
                      equivalent. Nor is there a formal definition of 'variable' for
                      Python. Python names are used much like C variables, but I think
                      people sometimes use 'variable' in a way that more refers to objects
                      than to names. For instance, in Python 'the value of i' is 'the value
                      of the ojbect currently associated with i' whereas in C it is 'the
                      value currently in memory block i'.
                      [color=blue]
                      > You can change their value,[/color]

                      You can change the value of objects, but only the binding of names.
                      [color=blue]
                      > delete them,[/color]

                      You can delete objects but only the binding of names. 'Del a' means
                      unbind 'a' from its currently associated object and if that was the
                      last remaining binding of that object, make the *object* eligible for
                      de-existence.

                      Thus far, you are using 'variable' more to describe objects than
                      names.
                      [color=blue]
                      > and get at the object to which they refer,[/color]

                      But here you clearly mean 'variable' = 'name' unless you also mean
                      'variable' = collection slot or object attribute ('dotted name').
                      [color=blue]
                      > but you can't do much else with them.[/color]

                      It is hard to do much with an ill-defined abstraction ;-).

                      Terry J. Reedy



                      Comment

                      • Ben Finney

                        #12
                        Re: Origin of the term &quot;first-class object&quot;

                        On Tue, 18 Nov 2003 03:01:35 GMT, Rainer Deyke wrote:[color=blue]
                        > John Roth wrote:[color=green]
                        >> I can't think of anything I can't do with a name that I might want
                        >> to.[/color]
                        >
                        > One would be passing a name as an argument
                        > to a function.[/color]

                        To accomplish what? What would you be doing with the name that you
                        can't do just as easily by passing the object (by reference, as always
                        happens in Python)?
                        [color=blue]
                        > Given the immutability of certain Python objects, it is
                        > often necessary to write statements in the form of
                        > "x = f(x)".[/color]

                        I don't understand the logic here. What is it that necessitates
                        "x = f(x)", and why is that undesirable?
                        [color=blue]
                        > This is a violation of the Once And Only Once principles, since it
                        > mentions the same variable twice.[/color]

                        I've never heard of that principle. Surely one of the main advantages
                        of naming an object is to use that name in multiple places to refer to
                        the object?

                        I can't think how you'd write any non-trivial program to work with
                        objects that *doesn't* "mention the same [object] twice", nor what you'd
                        gain by doing so.

                        Perhaps you're referring to a principle sometimes called the Single
                        Point Of Truth (SPOT), which requires that, ideally, there be one and
                        only one canonical place where each datum resides. This is quite
                        separate to the names given to objects within the program -- having a
                        SPOT for each datum is *enabled* by using the same name multiple times
                        within the program.
                        [color=blue]
                        > Language design is a series of trade-offs, and the simplicity and
                        > clarity of Python may very well make up for its limitations. However,
                        > that doesn't mean that the limitations are not real.[/color]

                        I'll have to ask you to explain those limitations, I can't understand
                        them as you've expressed them here.

                        --
                        \ "Kissing a smoker is like licking an ashtray." -- Anonymous |
                        `\ |
                        _o__) |
                        Ben Finney <http://bignose.squidly .org/>

                        Comment

                        • Rainer Deyke

                          #13
                          Re: Origin of the term &quot;first-class object&quot;

                          Ben Finney wrote:[color=blue]
                          > On Tue, 18 Nov 2003 03:01:35 GMT, Rainer Deyke wrote:[color=green]
                          >> One would be passing a name as an argument
                          >> to a function.[/color]
                          >
                          > To accomplish what? What would you be doing with the name that you
                          > can't do just as easily by passing the object (by reference, as always
                          > happens in Python)?[/color]

                          Binding the name to a different object.
                          [color=blue][color=green]
                          >> Given the immutability of certain Python objects, it is
                          >> often necessary to write statements in the form of
                          >> "x = f(x)".[/color]
                          >
                          > I don't understand the logic here. What is it that necessitates
                          > "x = f(x)",[/color]

                          For example, any "mutating" operation on x, where x is an immutable object.

                          Trivial and useless example:

                          def increment(x):
                          return x + 1

                          i = increment(i)
                          [color=blue]
                          > and why is that undesirable?[/color]

                          Suppose the 'x' in 'x = f(x)' is not a simple variable, but an element in a
                          list

                          l[x * 2 + f(y)] = f(l[x * 2 + f(y)])

                          This statement contains an obvious redundancy that will make code
                          maintenance difficult. Python allows me to factor out some of the
                          redundancy:

                          index = x * 2 + f(y)
                          l[index] = f(l[index])

                          However, Python gives me no way to factor out the remaining redundancy.


                          --
                          Rainer Deyke - rainerd@eldwood .com - http://eldwood.com


                          Comment

                          • John J. Lee

                            #14
                            Re: Origin of the term &quot;first-class object&quot;

                            Erik Max Francis <max@alcyone.co m> writes:
                            [color=blue]
                            > Hung Jung Lu wrote:
                            >[color=green]
                            > > Does anybody know where this term comes from?
                            > >
                            > > "First-class object" means "something passable as an argument in a
                            > > function call", but I fail to see the connection with "object class"
                            > > or with "first-class airplane ticket".[/color]
                            >
                            > It doesn't have any connection with the former (since the term long
                            > predates object orientation, so far as I know). It does have a
                            > connection to the latter, in that something going first class has all
                            > the privileges and properties owed to it as a complete and total thing.[/color]
                            [...]

                            Ben is closer to the mark in terms of etymology, I think -- though
                            maybe "first-class citizen" in turn derives from "first-class ticket"?


                            John

                            Comment

                            • John Roth

                              #15
                              Re: Origin of the term &quot;first-class object&quot;


                              "Ben Finney" <bignose-hates-spam@and-benfinney-does-too.id.au> wrote in
                              message news:slrnbrjijj .105.bignose-hates-spam@rose.local domain.fake...[color=blue]
                              >[color=green]
                              > > This is a violation of the Once And Only Once principles, since it
                              > > mentions the same variable twice.[/color]
                              >
                              > I've never heard of that principle.[/color]

                              Different authors give it different names. Dave Thomas and
                              Mike Hunt (the Pragmatic Programmers) call it "DRY":
                              "Don't repeat yourself." Once and only once comes, I believe,
                              from XP. There are other names.

                              The essential concept is that there should only be one
                              location for something in a system. Complaining about
                              x = f(x) is, IMO, being excessively anal about it.

                              John Roth


                              Comment

                              Working...