POV-Ray : Newsgroups : povray.off-topic : OO theory? Python. : Re: OO theory? Python. Server Time
29 Jul 2024 04:24:24 EDT (-0400)
  Re: OO theory? Python.  
From: Darren New
Date: 21 Oct 2012 20:28:34
Message: <50849332@news.povray.org>
On 10/20/2012 23:39, Warp wrote:
> Darren New<dne### [at] sanrrcom>  wrote:
>> On 10/16/2012 5:06, Warp wrote:
>>> Well, for one, methods taking 'self' as a parameter seems highly unusual
>
>> A function that takes "self" as the first argument is a method. Otherwise
>> it's a function.
>
> Well, duh. How does that change what I said?

I'm just explaining why people pass "self" as the first parameter. It's 
basically a declaration.

>>> Using __ as a syntax to denote a special meaning of functions and variables
>>> is also quite unusual,
>
>> The constructor is named __init__
>
>> The operator+ method is named __add__
>
>> And so on. It just avoids special syntax and substitutes special names.
>
> It substitutes special syntax by using special syntax... Sounds
> contradictory to me.

Having underlings as part of the name isn't any more "special" than it is in 
C or C++.  However, I cannot name my own function "operator'" in C++ because 
the "operator" keyword actually is special syntax. I can name my function 
__quote__ in Python because that function name has no special meaning to the 
interpreter.

When the interpreter sees "a + b" it first looks to see who implements 
__add__, and then invokes that. If neither side implements __add__ then it 
goes to the default implementation of adding integers or floats or whatever.

However, my main point was to explain to you what was happening. Whether you 
think it's reasonable after it is explained is up to you.

-- 
Darren New, San Diego CA, USA (PST)
   "They're the 1-800-#-GORILA of the telecom business."


Post a reply to this message

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