Re: Accessors in Python (getters and setters)
- From: "mystilleef" <mystilleef@xxxxxxxxx>
- Date: 13 Jul 2006 04:32:34 -0700
Bruno Desthuilliers wrote:
mystilleef wrote:I did already. If I had used Java, Eiffel, Smalltalk or C++, I would
Bruno Desthuilliers wrote:
mystilleef wrote:
(snip)
Python doesn't have any philosophy with regards to naming identifiers.
Yes it does.
No it doesn't.
But they are in Python and that is the python's philosophy. All attribute or
method not beginning with an '_' *is* API.
Right, and what if I want to change a private API to a public one.
Then you provide a public API on top of the private one.
class MyClass(object):
def __init__(self, ...):
self._attr = XXX
# seems like we really have enough use
# cases to justify exposing _imp_attr
@apply
def attr():
def fget(self):
return self._attr
def fset(self):
self._attr = attr
return property(**locals())
def _method(self, ...):
# code here
# seems like we really have enough use
# cases to justify exposing _imp_method
method = _impmethod
Note that none of this actually breaks encapsulation.
Ha! Just as bad as getters and setter.
What point are you trying to make here ? Of course a computed attribute
is just syntactic sugar for getters and setters - what else could it be?
The difference is that you don't need to write explicit getters/setters
beforehand, nor to use a "behaviour" semantic.
How
does that solve my naming issues.
How could this solve *your* naming issue ? This is totally unrelated.
You choose a bad name for a *public* symbol.
My point exactly! It doesn't solve my problem!
What do you hope ? Something that cures cancer ? Please enlighten us and
explain how explicit getters/setters would have solved the problem of
badly named getters/setters ?
have easily changed tmp to temporary_buffer without having search and
replace or grep 27000 lines of code. The point of accessors in those
languages is encapsulation. Which means I can change any detail of
implementation, yes including names of attributes, without breaking
code.
.
- Follow-Ups:
- Re: Accessors in Python (getters and setters)
- From: Bruno Desthuilliers
- Re: Accessors in Python (getters and setters)
- From: Antoon Pardon
- Re: Accessors in Python (getters and setters)
- References:
- Accessors in Python (getters and setters)
- From: mystilleef
- Re: Accessors in Python (getters and setters)
- From: Bruno Desthuilliers
- Re: Accessors in Python (getters and setters)
- From: mystilleef
- Re: Accessors in Python (getters and setters)
- From: Bruno Desthuilliers
- Re: Accessors in Python (getters and setters)
- From: mystilleef
- Re: Accessors in Python (getters and setters)
- From: Bruno Desthuilliers
- Accessors in Python (getters and setters)
- Prev by Date: Re: Data access from multiple code modules
- Next by Date: Re: help in xml and python
- Previous by thread: Re: Accessors in Python (getters and setters)
- Next by thread: Re: Accessors in Python (getters and setters)
- Index(es):
Relevant Pages
|