class-oriented rather than object-oriented?

Discussion in 'Python' started by notnorwegian@yahoo.se, May 25, 2008.

  1. Guest

    i have some confusion over this.

    sure a class is basically a classification, like for example an animal
    or flower. and an object/instance of that class is then for example a
    cat.

    an object is an instance of a class. that i know, i also know how to
    program with classes etc.

    i am just confused about the term object-oriented.

    wouldnt class-oriented be more fitting? at least for java since what
    you do is divide everything into classes.

    in python i dont or at leats not as much.


    does object-oriented refer to that everything(strings, ints etc) are
    all objects? so there is a class string somewhere in the
    implementation rather than a primitive or somehing?

    are python functions objects?

    can a functional language be object-oriented or an objectoriented
    language be functional?
    one definition of OO is a language that passes messages between
    objects. but not necessarily that is has to pass message sbetween
    classes?
     
    , May 25, 2008
    #1
    1. Advertising

  2. On May 25, 4:34 am, wrote:
    > i have some confusion over this.
    >
    > sure a class is basically a classification, like for example an animal
    > or flower. and an object/instance of that class is then for example a
    > cat.
    >
    > an object is an instance of a class. that i know, i also know how to
    > program with classes etc.
    >
    > i am just confused about the term object-oriented.
    >
    > wouldnt class-oriented be more fitting? at least for java since what
    > you do is divide everything into classes.


    Unfortunately there is a lot of confusion in the terminology.
    Basically, everybody uses the term "object oriented" with
    a different meaning. So, it is not your fault and yes, a
    better name for Java would be class-oriented language.

    > in python i dont or at leats not as much.
    >
    > does object-oriented refer to that everything(strings, ints etc) are
    > all objects? so there is a class string somewhere in the
    > implementation rather than a primitive or somehing?


    Yes, this is the common meaning of the sentence
    "everything is an object", in the sense that type(x)
    gives you the class of x for any x.

    > are python functions objects?


    Yes.

    >>> def f(x): pass
    >>> type(f)

    <type 'function'>

    > can a functional language be object-oriented or an objectoriented
    > language be functional?


    Yes and not. A *pure* functional language has no mutation,
    whereas the basic tenet of object orientation is having
    something with a mutable state. In practice, most functional
    languages are not pure, and most object oriented language
    also allows functional construct.

    > one definition of OO is a language that passes messages between
    > objects. but not necessarily that is has to pass message sbetween
    > classes?


    "Passing a message" is another way of saying "calling a
    method". In a language such as Python (or Smalltalk, or
    Ruby) classes as objects (in the sense that they are
    instances of some class, the so-called metaclass)
    so you can "pass a message" to the class.
    Notice that the message passing methaphor only works
    with languages with single dispatch; the Common Lisp
    Object System (CLOS), which is based on multiple
    dispatch, goes in an entirely different category
    (no message passing there). A generic function system
    is not an object system in the traditional sense (I
    mean the sense of Smalltalk) so it should have a
    different name, but the mistake has been made twenty
    years ago and there is nothing we can do now.

    Michele Simionato
     
    Michele Simionato, May 25, 2008
    #2
    1. Advertising

  3. a écrit :
    > i have some confusion over this.
    >
    > sure a class is basically a classification, like for example an animal
    > or flower. and an object/instance of that class is then for example a
    > cat.
    >
    > an object is an instance of a class.


    Depends on the language.

    > that i know, i also know how to
    > program with classes etc.
    >
    > i am just confused about the term object-oriented.
    >
    > wouldnt class-oriented be more fitting? at least for java since what
    > you do is divide everything into classes.


    InMyArms(tm) !-)

    > in python i dont or at leats not as much.


    Fact is that Python is more concerned about objects and less about
    classes. While you do have the concept of a class in Python, it's in
    some points closer to javascript's prototypes. Amongst other things, the
    object/class relationship is not necessarily static - you can
    dynamically rebind an object to another class (whether it's a good idea
    is another question), dynamicallt add/remove/replace attributes
    (including methods) on a per-instance or per-class basis, etc.

    >
    > does object-oriented refer to that everything(strings, ints etc) are
    > all objects?


    The only commonly accepted definitions I know wrt/ OO are :

    1/ an OO program is composed of objects interacting thru messages
    2/ an object is defined by an identity, a state and a behaviour

    So to answer your question:

    Not necessarily, but having non-object "things" in an OO program somehow
    contradicts definition #1 IMHO.

    BTW, you'll notice that there's nowhere mention of "classes" here...

    > so there is a class string somewhere in the
    > implementation rather than a primitive or somehing?


    .... nor of "primitive types" !-)

    > are python functions objects?


    Yes. As well as classes, modules, and even the function's code. From
    this POV, Python is 100% object. wrt/ to the "message passing" part,
    it's probably a bit more debatable, specially when compared to Smalltalk
    where messages are the only control structure.

    > can a functional language be object-oriented or an objectoriented
    > language be functional?


    Well... Depends on the definitions of "object-oriented" and
    "functional". There are indeed some languages that try to support both
    approach, coming either from the OO side (Python, Ruby, Javascript...)
    or from the functional side (OCaml, Common Lisp, Scheme, ...).

    Now none of these languages are "pure" functional languages. The point
    is that OOP and FP are two different and more or less incompatible
    approach toward state management. OOP try to encapsulate state into
    objects, while FP try to simply get rid of any shared state.

    > one definition of OO is a language that passes messages between
    > objects. but not necessarily that is has to pass message sbetween
    > classes?


    If your classes are objects, then what's the difference ?-) And if they
    are not, how are you going to pass messages between them ?

    But the fact is that the concept of "class" is by no mean central, nor
    even necessary, to OO. You might want to have a look at languages like
    Self, Io and Javascript, which are prototype-based instead of class-based.
     
    Bruno Desthuilliers, May 26, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike Wahler
    Replies:
    3
    Views:
    431
    Gavin Deane
    Aug 1, 2003
  2. Replies:
    1
    Views:
    332
  3. Replies:
    6
    Views:
    413
    James Kanze
    Oct 16, 2007
  4. rolo
    Replies:
    3
    Views:
    197
    Robert Klemme
    Apr 9, 2004
  5. John Mair
    Replies:
    12
    Views:
    208
    Intransition
    Oct 23, 2010
Loading...

Share This Page