POV-Ray : Newsgroups : povray.off-topic : OO theory? Python. : Re: OO theory? Python. Server Time
29 Jul 2024 04:27:22 EDT (-0400)
  Re: OO theory? Python.  
From: Warp
Date: 16 Oct 2012 08:06:23
Message: <507d4dbf@news.povray.org>
Aydan <hes### [at] hendrik-sachsenet> wrote:
> Warp <war### [at] tagpovrayorg> wrote:
> > Aydan <hes### [at] hendrik-sachsenet> wrote:
> > > [begin code]
> > > class vector(object):
> > >   def __init__(self,x,y,z):
> > >     self.__x=x
> > >     self.__y=y
> > >     self.__z=z
> >
> > Is that really how you write OO code in Python? Is it just me, or does it
> > look like Python hasn't actually been specifically designed to be an OO
> > language?
> >
> What do you mean?

Well, for one, methods taking 'self' as a parameter seems highly unusual
because in the vast majority of OO programming languages all methods always
have an implicit pseudo-object (usually named 'self' or 'this'). Python
methods taking it explicitly just feels like a kludge that has been tacked
at a later time onto a non-OO language.

Using __ as a syntax to denote a special meaning of functions and variables
is also quite unusual, and likewise feels like a kludge. Programming
languages seldom give any special syntactic meaning to variables and
function names containing underscores. (Instead, they usually use actual
keywords to express, for example, member variable visibility.)

If these (and I'm sure other) syntactic decisions have been made since the
very beginning of Python, I must say that it's... unusual, to put it in
nice terms.

> Everything in Python is an object.

It's quite ambiguous to say that "X is an object".

In programming theory "object" is a synonym for "first-class citizen",
which in turn means that the entity can be stored in variables and data
structures, passed to and returned from subroutines, constructed at
run-time and has an identity (eg. a unique low-level memory address that
can be compared.)

For example a variable of type 'int' in C is an "object" by this definition
(in other words, it's a first-class citizen.) However, one would hardly
classify it as an "object" in the object-oriented sense of the word. For
example, it's not something that can be inherited from (which pretty much
makes it non-OO.)

"Object-oriented language" requires a bit more than just having "everything
is an object" (especially since it's unclear what's meant by "object" in
this context.)

-- 
                                                          - Warp


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.