POV-Ray : Newsgroups : povray.off-topic : OO theory? Python. : Re: OO theory? Python. Server Time
29 Jul 2024 04:30:39 EDT (-0400)
  Re: OO theory? Python.  
From: Aydan
Date: 16 Oct 2012 10:20:01
Message: <web.507d6c5b7215dcd3771cd8e0@news.povray.org>
Warp <war### [at] tagpovrayorg> wrote:
> 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

I don't know why the pythonians did what they did, but keep in mind that python
is not a compiled language but a dynamic script language. Everything happens at
runtime.
print "\n".join(dir(int)) gives you all member functions of int.
Now you tell me if it's an OO object or not ;o)
As to why self is passed for instance functions? No idea, I see it as something
like main{} for C, it's just done like that and it doesn't disturb me.
I suppose it's a distinction between class functions and instance functions.


Post a reply to this message

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