On Tue, Jan 20, 2009 at 2:39 PM, Luis Zarrabeitia <ky...@uh.cu> wrote:
> This line would make a lot more sense if you were talking about Java's getters
> and setters, or about a language where accessing a property is different than
> accessing an attribute (which would make little sense). If properties already
> let you change from attribute to method without affecting the caller, why do 
> you
> need a property that does nothing?

My point exactly. Russ seems to agree with Python
but yet argue points for the sake of it. I'm not sure why :)

Having come from all kinda of programming backgrounds
and paradigms you learn to see the value in Python and the
kind of simplicity it has to offer. I will stand by my view
that there are many features of the traditional, strict
and academic features of the OO model that have little
practical value.

Python is a great mix of functional features, OO features
and has borrowed (what I believe) are the best of breed
features from all around.

One thing I find quite amazing is that we're having a discussion
over such low-level features of the OO model (and functional paradigm)
and how Python fits into it all ... And for what exactly ?

Russ - what is your point in all of this - You keep saying you don't have
time to waste with this - yet you keep making this thread grow
longer and longer and longer :)

As far as I'm concerned properties are just fancy functions to
retrieve and set attributes of an object. Consider the following
equivalent pieces of code:

#!/usr/bin/env python

from math import pi

class CircleA(object):

    def __init__(self, radius):
        self._radius = radius
        self._area = pi * radius ** 2

    def __getRadius(self):
        return self._radius

    def __setRadius(self, radius):
        self._radius = radius
        self._area = pi * radius ** 2

    def __getArea(self):
        return self._area

    def __repr__(self):
        return "<Circle r=%0.2f A=%0.2f>" % (self.radius, self.area)

    radius = property(__getRadius, __setRadius)
    area = property(__getArea)

class CircleB(object):

    def __init__(self, radius):
        self.radius = radius
        self.area = pi * radius ** 2

    def setRadius(self, radius):
        self.radius = radius
        self.area = pi * radius ** 2

    def __repr__(self):
        return "<Circle r=%0.2f A=%0.2f>" % (self.radius, self.area)

a = CircleA(1.5)
print a
a.radius = 2.0
print a

b = CircleB(1.5)
print b
b.radius = 2.0
print b

----------

http://codepad.org/tpyGNhrZ

I'll give you a hint which one I prefer :)

cheers
James
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to