Re: Python getters and setters

2013-08-17 Thread Fernando Saldanha
The debate got more interesting than I expected. Without taking sides, I would like to add that perhaps my "length" example was misleading: length is easy to calculate. The information could be hard to extract from the data, either because complex calculations are involved, or because it is not

Re: Python getters and setters

2013-08-17 Thread Chris Angelico
On Sun, Aug 18, 2013 at 12:40 AM, Steven D'Aprano wrote: > The Law of Demeter is really about being careful about what interface > your classes provide. Customers should provide a get_payment method; dogs > should provide a walk method. You shouldn't have to send individual step > messages to the

Re: Python getters and setters

2013-08-17 Thread Steven D'Aprano
On Sun, 18 Aug 2013 00:52:06 +0200, Irmen de Jong wrote: > On 17-8-2013 19:18, Steven D'Aprano wrote: [...] >> How is this: >> >> obj.data_length() >> >> easier for the user than this? >> >> len(obj.data) >> >> > It's not easier for the user perse, but it might be preferable from a > design p

Re: Python getters and setters

2013-08-17 Thread Irmen de Jong
On 17-8-2013 19:18, Steven D'Aprano wrote: > On Sat, 17 Aug 2013 09:53:07 -0700, Fernando Saldanha wrote: > >> Suppose my class contains an attribute called "data" that can >> potentially provide a lot of information that will be needed by class >> users. I have two options: >> >> 1) For each piec

Re: Python getters and setters

2013-08-17 Thread Tim Chase
On 2013-08-17 17:18, Steven D'Aprano wrote: > # Yes, this is good, consistent design > len(myrecord.field) > len(obj.data) > len(data.value) > len(collection[key]) I would also add that, if the primary goal of your class is to encapsulate the data, you can do class MyClass: def __init__(sel

Re: Python getters and setters

2013-08-17 Thread Steven D'Aprano
On Sat, 17 Aug 2013 09:53:07 -0700, Fernando Saldanha wrote: > Suppose my class contains an attribute called "data" that can > potentially provide a lot of information that will be needed by class > users. I have two options: > > 1) For each piece of information within data (e.g., length) I write

Re: Python getters and setters

2013-08-17 Thread MRAB
On 17/08/2013 17:53, Fernando Saldanha wrote: I am new to Python. I understand that it is "unpythonic" to write getters and setters, and that property() can be used if necessary. This deals with the case of attributes, but there are other kinds of information available within a class. Suppos

Python getters and setters

2013-08-17 Thread Fernando Saldanha
I am new to Python. I understand that it is "unpythonic" to write getters and setters, and that property() can be used if necessary. This deals with the case of attributes, but there are other kinds of information available within a class. Suppose my class contains an attribute called "data" t

Re: Accessors in Python (getters and setters)

2006-07-21 Thread Ed Jensen
Diez B. Roggisch <[EMAIL PROTECTED]> wrote: > Which puts us to the next question: the sealing itself doesn't do > anything to restrict the code, the SecurityManager does. Which AFAIK is > something hooked into the VM. Now, I'm not on sure grounds here on how > to altere its behaviour, but I'd sa

Re: Accessors in Python (getters and setters)

2006-07-21 Thread Diez B. Roggisch
Ed Jensen schrieb: > Diez B. Roggisch <[EMAIL PROTECTED]> wrote: >>> Java is not an acronym. That is: it's "Java", not "JAVA". >> Now THAT was an important information RIGHT on topic. > > It was not meant offensively. Ok. >>> Java does not allow access to private members via reflection. >> For

Re: Accessors in Python (getters and setters)

2006-07-20 Thread fuzzylollipop
Ed Jensen wrote: > Diez B. Roggisch <[EMAIL PROTECTED]> wrote: > > Ah, you mean like in JAVA > > Java is not an acronym. That is: it's "Java", not "JAVA". > > > where the compiler prevents you from accessing > > private variables, but the runtime allows access to these very variables > > via refl

Re: Accessors in Python (getters and setters)

2006-07-20 Thread Bruno Desthuilliers
Ant a écrit : > Came across this article this afternoon - thought it may be of interest > to some of those following this thread... > > http://www.devx.com/opensource/Article/31593/0/page/2 > Yeah. Presenting name mangling as the usual way to have 'private' attributes, then implementing (costly)

Re: [OT] Accessors in Python (getters and setters)

2006-07-20 Thread Bruno Desthuilliers
Dennis Lee Bieber a écrit : > On Thu, 20 Jul 2006 12:52:52 +0200, Bruno Desthuilliers > <[EMAIL PROTECTED]> declaimed the following in comp.lang.python: > > >>Granted. Actually, it *was* a typo - but it happened to also make sens, >>so I decided it was not a typo !-) >> > > Ah... One of th

Re: Accessors in Python (getters and setters)

2006-07-20 Thread Bruno Desthuilliers
Gerhard Fiedler a écrit : > On 2006-07-20 09:40:31, Bruno Desthuilliers wrote: > > >>>I'm not sure, but there's one thing that has a potential to be the real >>>issue: what's the common way to create a property that is read-write >>>for the implementation and "read-only" for the interface? >> >>

Re: Accessors in Python (getters and setters)

2006-07-20 Thread Bruno Desthuilliers
Diez B. Roggisch a écrit : >> You mean: >> >> class Pythonic(object): >> def __init__(self): >> self._is_active = True >> >> @apply >> def is_active(): >> def fget(self): return self._is_active >> def fset(self): raise SomeException('sorry, read-only') >> return

Re: Accessors in Python (getters and setters)

2006-07-20 Thread Ed Jensen
Diez B. Roggisch <[EMAIL PROTECTED]> wrote: >> Java is not an acronym. That is: it's "Java", not "JAVA". > > Now THAT was an important information RIGHT on topic. It was not meant offensively. >> Java does not allow access to private members via reflection. > > For somebody nitpicking on natur

Re: Accessors in Python (getters and setters)

2006-07-20 Thread mystilleef
Bruno Desthuilliers wrote: > mystilleef wrote: > > Bruno Desthuilliers wrote: > > >>point 2 : so anyone *can* "illegimately tampering with an object's > >>internal data" at will. > >> > > > >And this is robust how? > > > > You can do just the same in Java or C++. >

Re: Accessors in Python (getters and setters)

2006-07-20 Thread Gerhard Fiedler
On 2006-07-20 09:40:31, Bruno Desthuilliers wrote: >> I'm not sure, but there's one thing that has a potential to be the real >> issue: what's the common way to create a property that is read-write >> for the implementation and "read-only" for the interface? > > class Foo(object): > @apply >

Re: Accessors in Python (getters and setters)

2006-07-20 Thread Ant
Came across this article this afternoon - thought it may be of interest to some of those following this thread... http://www.devx.com/opensource/Article/31593/0/page/2 -- http://mail.python.org/mailman/listinfo/python-list

Re: Accessors in Python (getters and setters)

2006-07-20 Thread Bruno Desthuilliers
mystilleef wrote: > Bruno Desthuilliers wrote: >>point 2 : so anyone *can* "illegimately tampering with an object's >>internal data" at will. >> > >And this is robust how? > You can do just the same in Java or C++. >>> >>> >>>OMG! >> >>It's common knowledge. >

Re: Accessors in Python (getters and setters)

2006-07-20 Thread mystilleef
Bruno Desthuilliers wrote: > mystilleef wrote: > > Bruno Desthuilliers wrote: > > > (snip) > >You use accessors when you need to control access to a data attribute. > > Indeed. And when you don't need too ? (the second 'o' is not a typo) > > >>> > >>> > >>>You make the attribute

Re: Accessors in Python (getters and setters)

2006-07-20 Thread Diez B. Roggisch
> You mean: > > class Pythonic(object): > def __init__(self): > self._is_active = True > > @apply > def is_active(): > def fget(self): return self._is_active > def fset(self): raise SomeException('sorry, read-only') > return property(**locals()) Neat! That sli

Re: Accessors in Python (getters and setters)

2006-07-20 Thread Bruno Desthuilliers
mystilleef wrote: > Bruno Desthuilliers wrote: > (snip) >You use accessors when you need to control access to a data attribute. Indeed. And when you don't need too ? (the second 'o' is not a typo) >>> >>> >>>You make the attribute private/protected. >> >>doh :( >> >>Let's talk ab

Re: Accessors in Python (getters and setters)

2006-07-20 Thread mystilleef
Bruno Desthuilliers wrote: > mystilleef wrote: > > Bruno Desthuilliers wrote: > > > >>mystilleef wrote: > >> > >>>Bruno Desthuilliers wrote: > >>> > >>> > mystilleef wrote: > >> > >>(snip) > >> > >>>Of course using setters for the sake of just using them is pointless. > >> > >>Inde

Re: Accessors in Python (getters and setters)

2006-07-20 Thread Bruno Desthuilliers
Gerhard Fiedler wrote: (snip) > > I'm not sure, but there's one thing that has a potential to be the real > issue: what's the common way to create a property that is read-write for > the implementation and "read-only" for the interface? class Foo(object): @apply def _imp(): def fget(self

Re: Accessors in Python (getters and setters)

2006-07-20 Thread Bruno Desthuilliers
mystilleef wrote: (snip) > > __monitor_event is not supposed to be a write accessor. My point was > show how you can change the state of an object internally without > needing external access to it. Since some people are surprisingly > claiming it is not possible. I failed to see anyone making su

Re: Accessors in Python (getters and setters)

2006-07-20 Thread Diez B. Roggisch
> Lol. I actually did *un*learn the hard way. > > Mystilleef, I've started programing 17 years ago, and have done it > professionnaly for almost 10 years now. I do not pretend to be a good > programmer, but please believe that I do know my job. I've read the Book > too, I've tried applying it blin

Re: Accessors in Python (getters and setters)

2006-07-20 Thread Steve Holden
Gerhard Fiedler wrote: > On 2006-07-20 04:15:33, Steve Holden wrote: > > >>mystilleef wrote: >>[...] >> >>>I don't know it's your code not mine. >>> >>>class Robust(object): >>> >>> def __init__(self): >>> # Arbitrarily changing this state to False will crash app or >>> will >>>

Re: Accessors in Python (getters and setters)

2006-07-20 Thread Gerhard Fiedler
On 2006-07-20 04:15:33, Steve Holden wrote: > mystilleef wrote: > [...] >> >> I don't know it's your code not mine. >> >> class Robust(object): >> >> def __init__(self): >> # Arbitrarily changing this state to False will crash app or >> will >> # corrupt the whol

Re: Accessors in Python (getters and setters)

2006-07-20 Thread Bruno Desthuilliers
Dennis Lee Bieber wrote: > On Wed, 19 Jul 2006 18:54:55 +0200, Bruno Desthuilliers > <[EMAIL PROTECTED]> declaimed the following in comp.lang.python: > > >>Indeed. And when you don't need too ? (the second 'o' is not a typo) >> > > Pardon, but for the sense you intend, it should be: > >

Re: Accessors in Python (getters and setters)

2006-07-20 Thread Bruno Desthuilliers
mystilleef wrote: > Bruno Desthuilliers wrote: > >>mystilleef wrote: >> >>>Bruno Desthuilliers wrote: >>> >>> mystilleef wrote: >> >>(snip) >> >>>Of course using setters for the sake of just using them is pointless. >> >>Indeed. >> >> >> >> >>>The reason to use

Re: Accessors in Python (getters and setters)

2006-07-20 Thread mystilleef
Steve Holden wrote: > mystilleef wrote: > [...] > > > > I don't know it's your code not mine. > > > > class Robust(object): > > > > def __init__(self): > > # Arbitrarily changing this state to False will crash app or > > will > > # corrupt the whole event system. > >

Re: Accessors in Python (getters and setters)

2006-07-20 Thread Steve Holden
mystilleef wrote: [...] > > I don't know it's your code not mine. > > class Robust(object): > > def __init__(self): > # Arbitrarily changing this state to False will crash app or > will > # corrupt the whole event system. > self.__is_active = True

Re: Accessors in Python (getters and setters)

2006-07-20 Thread Steve Holden
Dennis Lee Bieber wrote: > On 19 Jul 2006 22:38:17 -0700, "mystilleef" <[EMAIL PROTECTED]> > declaimed the following in comp.lang.python: > > >>permitted should be between an object and its mediator. Messages are >>passed through the system via signals or events or established >>protocols. What a

Re: Accessors in Python (getters and setters)

2006-07-19 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, mystilleef wrote: > > Bruno Desthuilliers wrote: >> mystilleef wrote: >> > Bruno Desthuilliers wrote: >> > >> > Because you don't want third parties illegimately tampering with an >> > object's internal data and thus crashing your system? >> >> Let's try again... >> >> poi

Re: Accessors in Python (getters and setters)

2006-07-19 Thread mystilleef
Steve Holden wrote: > mystilleef wrote, making me somewhat tired of his/her repeated inability > to get what's being said [sigh]: > > Bruno Desthuilliers wrote: > >>mystilleef wrote: > >>>Bruno Desthuilliers wrote: > mystilleef wrote: > >Gerhard Fiedler wrote: > >>On 2006-07-15 06:55:1

Re: Accessors in Python (getters and setters)

2006-07-19 Thread mystilleef
Bruno Desthuilliers wrote: > mystilleef wrote: > > Bruno Desthuilliers wrote: > > > >>mystilleef wrote: > (snip) > > > >Of course using setters for the sake of just using them is pointless. > > Indeed. > > > > >The reason to use them is if pre-conditions or post

Re: Accessors in Python (getters and setters)

2006-07-19 Thread danielx
Bruno Desthuilliers wrote: > ZeD wrote: > > Bruno Desthuilliers wrote: > > > > > >>>I decided to change the name of an attribute. Problem is I've used the > >>>attribute in several places spanning thousands of lines of code. If I > >>>had encapsulated the attribute via an accessor, I wouldn't need

Re: Accessors in Python (getters and setters)

2006-07-19 Thread Diez B. Roggisch
Ed Jensen schrieb: > Diez B. Roggisch <[EMAIL PROTECTED]> wrote: >> Ah, you mean like in JAVA > > Java is not an acronym. That is: it's "Java", not "JAVA". Now THAT was an important information RIGHT on topic. >> where the compiler prevents you from accessing >> private variables, but the runti

Re: Accessors in Python (getters and setters)

2006-07-19 Thread Bruno Desthuilliers
Tobias Brox a écrit : > [Jason] > >>Nothing like being forced to write getters and setters in C++/Java >>before you feel like shooting your source code. Please don't bring >>this code-rage into Python. > > > "Code generation" springs into my mind. IMO, if the code needs to be > generated, the

Re: Accessors in Python (getters and setters)

2006-07-19 Thread Ant
Ed Jensen wrote: > > where the compiler prevents you from accessing > > private variables, but the runtime allows access to these very variables > > via reflection? > > Java does not allow access to private members via reflection. Yes it does. You can call setAccessible(true) on the Method objec

Re: Accessors in Python (getters and setters)

2006-07-19 Thread Gerhard Fiedler
On 2006-07-19 14:12:33, Tobias Brox wrote: > "Code generation" springs into my mind. IMO, if the code needs to be > generated, the language is not sufficiently advanced. Isn't that just a question of level? I'm sure there are editors that generate Python class stubs, GUI builders that generate P

Re: Accessors in Python (getters and setters)

2006-07-19 Thread Bruno Desthuilliers
mystilleef wrote: > Bruno Desthuilliers wrote: > >>mystilleef wrote: >> (snip) >For example, a third party randomly changing >is_active, (which Python lets you do freely and easily) Unless you make it a read-only property. >>> >>>So you see the purpose of accessors then? >>

Re: Accessors in Python (getters and setters)

2006-07-19 Thread Tobias Brox
[Jason] > Nothing like being forced to write getters and setters in C++/Java > before you feel like shooting your source code. Please don't bring > this code-rage into Python. "Code generation" springs into my mind. IMO, if the code needs to be generated, the language is not sufficiently advance

Re: Accessors in Python (getters and setters)

2006-07-19 Thread Tobias Brox
[ZeD] > you mean sed :) > sed 's/oldName/newName/g' oldFile > newFile I used to be a Perl programmer :-) perl -i.bak -pe 's/oldName/newName/g' * As said, this is risky as oldName can be used in other contexts. -- Tobias Brox, 69°42'N, 18°57'E -- http://mail.python.org/mailman/listinfo/pyth

Re: Accessors in Python (getters and setters)

2006-07-19 Thread Bruno Desthuilliers
mystilleef wrote: > Bruno Desthuilliers wrote: > >>mystilleef wrote: (snip) > >Of course using setters for the sake of just using them is pointless. Indeed. >The reason to use them is if pre-conditions or post-conditions need to >be met. Or to control access

Re: Accessors in Python (getters and setters)

2006-07-19 Thread Ed Jensen
Diez B. Roggisch <[EMAIL PROTECTED]> wrote: > Ah, you mean like in JAVA Java is not an acronym. That is: it's "Java", not "JAVA". > where the compiler prevents you from accessing > private variables, but the runtime allows access to these very variables > via reflection? Java does not allow ac

Re: Accessors in Python (getters and setters)

2006-07-19 Thread Diez B. Roggisch
>> What I'm saying here is that it's totally useless to duplicate default >> behaviour. >> > > And who's doing that? Somebody who uses setters that only set a property? Diez -- http://mail.python.org/mailman/listinfo/python-list

Re: Accessors in Python (getters and setters)

2006-07-19 Thread Diez B. Roggisch
>> Then why do you advise "(making) all attributes of a class >> private/protected" and systematically using properties ? >> > > Because you don't want third parties illegimately tampering with an > object's internal data and thus crashing your system? Ah, you mean like in JAVA where the compiler

Re: Accessors in Python (getters and setters)

2006-07-19 Thread Steve Holden
mystilleef wrote, making me somewhat tired of his/her repeated inability to get what's being said [sigh]: > Bruno Desthuilliers wrote: >>mystilleef wrote: >>>Bruno Desthuilliers wrote: mystilleef wrote: >Gerhard Fiedler wrote: >>On 2006-07-15 06:55:14, mystilleef wrote: >>>In very

Re: Accessors in Python (getters and setters)

2006-07-18 Thread mystilleef
Bruno Desthuilliers wrote: > mystilleef wrote: > > Bruno Desthuilliers wrote: > > > >>mystilleef wrote: > >>Please don't top-post > >> > >>>On State and Behavior: > >>> > >>>To understand objects in terms of state and behavior you need to > >>>absolve yourself from implementation details of langua

Re: Accessors in Python (getters and setters)

2006-07-18 Thread mystilleef
Bruno Desthuilliers wrote: > mystilleef wrote: > > Bruno Desthuilliers wrote: > > > >>mystilleef wrote: > >> > >>>Gerhard Fiedler wrote: > >>> > >>> > On 2006-07-15 06:55:14, mystilleef wrote: > > > > >In very well designed systems, the state of an object should only be > >>

Re: Accessors in Python (getters and setters)

2006-07-18 Thread Bruno Desthuilliers
mystilleef wrote: > Bruno Desthuilliers wrote: > >>mystilleef wrote: >>Please don't top-post >> >>>On State and Behavior: >>> >>>To understand objects in terms of state and behavior you need to >>>absolve yourself from implementation details of languages >>>and think at an abstract level. >> >> >>

Re: Accessors in Python (getters and setters)

2006-07-18 Thread Bruno Desthuilliers
mystilleef wrote: > Bruno Desthuilliers wrote: > >>mystilleef wrote: >> >>>Gerhard Fiedler wrote: >>> >>> On 2006-07-15 06:55:14, mystilleef wrote: >In very well designed systems, the state of an object should only be >changed by the object. IMO that's not quite

Re: Accessors in Python (getters and setters)

2006-07-18 Thread mystilleef
Bruno Desthuilliers wrote: > mystilleef wrote: > > Gerhard Fiedler wrote: > > > >>On 2006-07-15 06:55:14, mystilleef wrote: > >> > >> > >>>In very well designed systems, the state of an object should only be > >>>changed by the object. > >> > >>IMO that's not quite true. Ultimately, the state alwa

Re: Accessors in Python (getters and setters)

2006-07-18 Thread mystilleef
Bruno Desthuilliers wrote: > mystilleef wrote: > Please don't top-post > > On State and Behavior: > > > > To understand objects in terms of state and behavior you need to > > absolve yourself from implementation details of languages > > and think at an abstract level. > > > > > Take a button objec

Re: Accessors in Python (getters and setters)

2006-07-17 Thread Bruno Desthuilliers
Bruno Desthuilliers wrote: > mystilleef wrote: (snip) >>Here are the lessons I've learned (the hard way). >> >>1) Make all attributes of a class private or protected. > > > Unless they are obviously part of the implementation s/implementation/interface/, of course. > (ie: when you would > def

Re: Accessors in Python (getters and setters)

2006-07-17 Thread Bruno Desthuilliers
mystilleef wrote: > Gerhard Fiedler wrote: > >>On 2006-07-15 06:55:14, mystilleef wrote: >> >> >>>In very well designed systems, the state of an object should only be >>>changed by the object. >> >>IMO that's not quite true. Ultimately, the state always gets changed by >>something else (user inter

Re: Accessors in Python (getters and setters)

2006-07-17 Thread Bruno Desthuilliers
mystilleef wrote: Please don't top-post > On State and Behavior: > > To understand objects in terms of state and behavior you need to > absolve yourself from implementation details of languages > and think at an abstract level. > Take a button object, for example. It has state and behavior. Pos

Re: Accessors in Python (getters and setters)

2006-07-16 Thread Gerhard Fiedler
On 2006-07-15 19:46:16, Ben C wrote: > There isn't any practical difference, as you say, if all the setter does > is set. But it might easily do a few other subtle things, in particular > wait for a good moment to actually effect the change. I agree. But even then, for me there's no practical dif

Re: Accessors in Python (getters and setters)

2006-07-15 Thread Ben C
On 2006-07-15, Gerhard Fiedler <[EMAIL PROTECTED]> wrote: > On 2006-07-15 06:55:14, mystilleef wrote: > >> In very well designed systems, the state of an object should only be >> changed by the object. > > IMO that's not quite true. Ultimately, the state always gets changed by > something else (us

Re: Accessors in Python (getters and setters)

2006-07-15 Thread Gerhard Fiedler
On 2006-07-15 12:04:20, mystilleef wrote: > State - behavior is not something I made up, so it isn't subjective. It > is a common term used in OO literature. In fact, the only reason I used > it is because I thought is was common knowledge. Of course. But your association of state with attribute

Re: Accessors in Python (getters and setters)

2006-07-15 Thread mystilleef
Gerhard Fiedler wrote: > On 2006-07-15 06:55:14, mystilleef wrote: > > > In very well designed systems, the state of an object should only be > > changed by the object. > > IMO that's not quite true. Ultimately, the state always gets changed by > something else (user interaction, physical events);

Re: Accessors in Python (getters and setters)

2006-07-15 Thread Gerhard Fiedler
On 2006-07-15 06:55:14, mystilleef wrote: > In very well designed systems, the state of an object should only be > changed by the object. IMO that's not quite true. Ultimately, the state always gets changed by something else (user interaction, physical events); very few objects are completely se

Re: Accessors in Python (getters and setters)

2006-07-15 Thread mystilleef
On State and Behavior: To understand objects in terms of state and behavior you need to absolve yourself from implementation details of languages and think at an abstract level. Take a button object, for example. It has state and behavior. Possible states may include, is_active, is_focused, is_ma

Re: Accessors in Python (getters and setters)

2006-07-14 Thread riquito
mystilleef ha scritto: > Methods are used to perform actions. Data attributes usually aren't. We > are on different planes. You aren't thinking pythonic. You should not make any difference between accessing an attribute and accessing a function. They both just need to receive the right data to p

Re: Accessors in Python (getters and setters)

2006-07-14 Thread Steve Holden
mystilleef wrote: > Marc 'BlackJack' Rintsch wrote: > >>In <[EMAIL PROTECTED]>, mystilleef >>wrote: >> >> >>>Maric Michaud wrote: >>> But that's not python philosophy. >>> >>>Python doesn't have any philosophy with regards to naming identifiers. >> >>But the python community has one. Pythonis

Re: Accessors in Python (getters and setters)

2006-07-13 Thread Carl Banks
mystilleef wrote: > Fredrik Lundh wrote: > > "mystilleef" wrote: > > > > > Pretending to be intelligent does, however. > > > > so the real reason you've written a few hundred posts saying basically "I > > pick > > bad names, which proves... uh... whatever" is to impress people by > > pretending

Re: Accessors in Python (getters and setters)

2006-07-13 Thread Bruno Desthuilliers
mystilleef wrote: (snip) > > Okay, I feel I need to make myself clear. I certainly I'm not blaming > Python for my mistakes. And I don't think language X is better than > Python or vice-versa. Okay scrap the vice-versa. It was silly of me to > name the variable tmp regardless of whatever excuses I

Re: Accessors in Python (getters and setters)

2006-07-13 Thread Alex Martelli
Gerhard Fiedler <[EMAIL PROTECTED]> wrote: > On 2006-07-13 01:50:18, Alex Martelli wrote: > > >> I'm not sure about which languages you are talking (pretty much all that > >> allow public methods also allow public attributes), [...] > > > > Smalltalk is a very well known object-oriented language

Re: Accessors in Python (getters and setters)

2006-07-13 Thread Bruno Desthuilliers
mystilleef wrote: > Ant wrote: > >>We seem to be flogging a dead horse now. Is the following a fair >>summary: >> >>Q. What is the Pythonic way of implementing getters and setters? >> >>A. Use attributes. >> >>Quote: "I put a lot more effort into choosing method and function >>names" >> >>Wisdom:

Re: Accessors in Python (getters and setters)

2006-07-13 Thread Bruno Desthuilliers
mystilleef wrote: > Bruno Desthuilliers wrote: > 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 pro

Re: Accessors in Python (getters and setters)

2006-07-13 Thread Roel Schroeven
mystilleef schreef: > Ant wrote: >> We seem to be flogging a dead horse now. Is the following a fair >> summary: >> >> Q. What is the Pythonic way of implementing getters and setters? >> >> A. Use attributes. >> >> Quote: "I put a lot more effort into choosing method and function >> names" >> >> Wi

Re: Accessors in Python (getters and setters)

2006-07-13 Thread mystilleef
Bruno Desthuilliers wrote: > mystilleef wrote: > > Bruno Desthuilliers wrote: > > > >>mystilleef wrote: > >> > (snip) > > >I have used that name in > >dozens of places spanning over 27000 LOC. > > Too bad for you. > >>> > >>> > >>>Thank you, that was helpful. > >> > >>What am

Re: Accessors in Python (getters and setters)

2006-07-13 Thread Gerhard Fiedler
On 2006-07-13 01:50:18, Alex Martelli wrote: >> I'm not sure about which languages you are talking (pretty much all that >> allow public methods also allow public attributes), [...] > > Smalltalk is a very well known object-oriented language that behaves > otherwise, just as one example. I didn'

Re: Accessors in Python (getters and setters)

2006-07-13 Thread Gerhard Fiedler
On 2006-07-13 06:03:40, Bruno Desthuilliers wrote: >> [...] the underscore way to mark private entities. Maybe this doesn't >> work as I think it does > > If you think that single leading underscores have a special meaning for > the compiler/interpreter, then you got it wrong. It's a convention.

Re: Accessors in Python (getters and setters)

2006-07-13 Thread Simon Brunning
On 7/13/06, Simon Brunning <[EMAIL PROTECTED]> wrote: > Something like this any use to you? Or this, about a squillion times cleaner: class MyClass(object): def _get_bad_name(self): warn('"bad_name" deprecated. Please refer to "good_name"', stacklevel=2) return self.good_name

Re: Accessors in Python (getters and setters)

2006-07-13 Thread Bruno Desthuilliers
mystilleef wrote: > Bruno Desthuilliers wrote: > >>mystilleef wrote: >> (snip) >I have used that name in >dozens of places spanning over 27000 LOC. Too bad for you. >>> >>> >>>Thank you, that was helpful. >> >>What am I supposed to say ? You choose a bad name for a public sym

Re: Accessors in Python (getters and setters)

2006-07-13 Thread Antoon Pardon
On 2006-07-13, mystilleef <[EMAIL PROTECTED]> wrote: > >> 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 ? >> > I did already. If I had used Java, Eiffel, Smalltalk or C

Re: Accessors in Python (getters and setters)

2006-07-13 Thread Simon Brunning
On 10 Jul 2006 05:51:02 -0700, mystilleef <[EMAIL PROTECTED]> wrote: > I decided to change the name of an attribute. Problem is I've used the > attribute in several places spanning thousands of lines of code. If I > had encapsulated the attribute via an accessor, I wouldn't need to do > an unreliab

Re: Accessors in Python (getters and setters)

2006-07-13 Thread mystilleef
Ant wrote: > We seem to be flogging a dead horse now. Is the following a fair > summary: > > Q. What is the Pythonic way of implementing getters and setters? > > A. Use attributes. > > Quote: "I put a lot more effort into choosing method and function > names" > > Wisdom: Python is a different para

Re: Accessors in Python (getters and setters)

2006-07-13 Thread Ant
We seem to be flogging a dead horse now. Is the following a fair summary: Q. What is the Pythonic way of implementing getters and setters? A. Use attributes. Quote: "I put a lot more effort into choosing method and function names" Wisdom: Python is a different paradigm from (e.g.) Java w.r.t. a

Re: Accessors in Python (getters and setters)

2006-07-13 Thread mystilleef
Bruno Desthuilliers wrote: > mystilleef wrote: > > 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

Re: Accessors in Python (getters and setters)

2006-07-13 Thread mystilleef
Bruno Desthuilliers wrote: > mystilleef wrote: > > Bruno Desthuilliers wrote: > > > >>mystilleef wrote: > >> > >>>Lousy Attribute Name: > >>> self.tmp > >>> > >>>Accessors: > >>> set_temporary_buffer > >>> get_temporary_buffer > >>> > >>>The attribute name I chose, "tmp" sucks. > >> > >>Well

Re: Accessors in Python (getters and setters)

2006-07-13 Thread Bruno Desthuilliers
mystilleef wrote: > 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

Re: Accessors in Python (getters and setters)

2006-07-13 Thread mystilleef
Fredrik Lundh wrote: > "mystilleef" wrote: > > > Pretending to be intelligent does, however. > > so the real reason you've written a few hundred posts saying basically "I pick > bad names, which proves... uh... whatever" is to impress people by pretending > to be something you're not ? > > Choos

Re: Accessors in Python (getters and setters)

2006-07-13 Thread Bruno Desthuilliers
mystilleef wrote: > Bruno Desthuilliers wrote: > >>mystilleef wrote: >> >>>Marc 'BlackJack' Rintsch wrote: >>> >>> In <[EMAIL PROTECTED]>, mystilleef wrote: >Maric Michaud wrote: >> >>(snip) >> >> >>But they are in Python and that is the python's philosophy. All attr

Re: Accessors in Python (getters and setters)

2006-07-13 Thread Bruno Desthuilliers
mystilleef wrote: > Bruno Desthuilliers wrote: > >>mystilleef wrote: >> >>>Lousy Attribute Name: >>> self.tmp >>> >>>Accessors: >>> set_temporary_buffer >>> get_temporary_buffer >>> >>>The attribute name I chose, "tmp" sucks. >> >>Well, it's surely not as descriptive as 'temporary_buff

Re: Accessors in Python (getters and setters)

2006-07-13 Thread Fredrik Lundh
"mystilleef" wrote: > Pretending to be intelligent does, however. so the real reason you've written a few hundred posts saying basically "I pick bad names, which proves... uh... whatever" is to impress people by pretending to be something you're not ? -- http://mail.python.org/mailman/list

Re: Accessors in Python (getters and setters)

2006-07-13 Thread mystilleef
Fredrik Lundh wrote: > "mystilleef" wrote: > > >> if your code is as muddled as your rhetorics, your only solution might be > >> to give up programming. > > > > There's no correlation between rhetorics and programming. That's like > > me saying if you are trying to be sarcastic your only solution

Re: Accessors in Python (getters and setters)

2006-07-13 Thread Fredrik Lundh
"mystilleef" wrote: >> if your code is as muddled as your rhetorics, your only solution might be >> to give up programming. > > There's no correlation between rhetorics and programming. That's like > me saying if you are trying to be sarcastic your only solution might be > to give up programming.

Re: Accessors in Python (getters and setters)

2006-07-13 Thread mystilleef
Bruno Desthuilliers wrote: > mystilleef wrote: > > Marc 'BlackJack' Rintsch wrote: > > > >>In <[EMAIL PROTECTED]>, mystilleef > >>wrote: > >> > >> > >>>Maric Michaud wrote: > (snip) > > But they are in Python and that is the python's philosophy. All attribute > or > method not beginni

Re: Accessors in Python (getters and setters)

2006-07-13 Thread Bruno Desthuilliers
mystilleef wrote: > Marc 'BlackJack' Rintsch wrote: > >>In <[EMAIL PROTECTED]>, mystilleef >>wrote: >> >> >>>Maric Michaud wrote: (snip) 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

Re: Accessors in Python (getters and setters)

2006-07-13 Thread mystilleef
Fredrik Lundh wrote: > "mystilleef" wrote: > > > Right, and what if I want to change a private API to a public one. How > > does that solve my naming issues. > > if your code is as muddled as your rhetorics, your only solution might be > to give up programming. > > There's no correlation between

Re: Accessors in Python (getters and setters)

2006-07-13 Thread Bruno Desthuilliers
Marc 'BlackJack' Rintsch wrote: > In <[EMAIL PROTECTED]>, mystilleef > wrote: > > >>Maric Michaud wrote: >> (snip) >>>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 t

Re: Accessors in Python (getters and setters)

2006-07-13 Thread mystilleef
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. >

Re: Accessors in Python (getters and setters)

2006-07-13 Thread Bruno Desthuilliers
Gerhard Fiedler wrote: > On 2006-07-12 06:17:27, mystilleef wrote: > > >>But developers tend to pay more attention to given methods/functions >>less crappy names, at least when compared to data attributes. This >>stems from the fact that in many languages data attributes aren't >>usually part of

Re: Accessors in Python (getters and setters)

2006-07-13 Thread Fredrik Lundh
"mystilleef" wrote: > Right, and what if I want to change a private API to a public one. How > does that solve my naming issues. if your code is as muddled as your rhetorics, your only solution might be to give up programming. -- http://mail.python.org/mailman/listinfo/python-list

Re: Accessors in Python (getters and setters)

2006-07-13 Thread mystilleef
Marc 'BlackJack' Rintsch wrote: > In <[EMAIL PROTECTED]>, mystilleef > wrote: > > > Maric Michaud wrote: > >> But that's not python philosophy. > > Python doesn't have any philosophy with regards to naming identifiers. > > But the python community has one. Pythonistas prefer readable source code

Re: Accessors in Python (getters and setters)

2006-07-13 Thread mystilleef
Bruno Desthuilliers wrote: > mystilleef wrote: > > Lousy Attribute Name: > > self.tmp > > > > Accessors: > > set_temporary_buffer > > get_temporary_buffer > > > > The attribute name I chose, "tmp" sucks. > > Well, it's surely not as descriptive as 'temporary_buffer' > > > I have used t

  1   2   >