Re: Declarative properties

2007-10-13 Thread Bruno Desthuilliers
Dan Stromberg a écrit : (snip) > My implementation may or may not be lacking (feel free to improve it - in > fact, please do!), Since you ask for it: def makeprop(name): _name = '_' + name def fget(self): return getattr(self, _name, None) def fset(self, val): set

Re: Declarative properties

2007-10-13 Thread Bruno Desthuilliers
Dan Stromberg a écrit : > On Fri, 12 Oct 2007 09:42:28 +0200, Bruno Desthuilliers wrote: > > So what? Otherwise you carry *always* the baggage of a public property and a private attribute whether you need this or not. At least for me it would be unnecessary in most cases. >>> >>>Tha

Re: Declarative properties

2007-10-13 Thread Bruno Desthuilliers
Stargaming a écrit : > On Thu, 11 Oct 2007 18:58:44 +0200, Bruno Desthuilliers wrote: > [snip] > > Your implementation seems particularly broken. You do not return anything > from `name()`, Oops, my bad ! Indeed, I forgot the 'return property(**locals())' at the end. And a couple other things

Re: Declarative properties

2007-10-13 Thread Diez B. Roggisch
Dan Stromberg schrieb: > On Thu, 11 Oct 2007 18:42:16 +, Marc 'BlackJack' Rintsch wrote: > > >>> The "baggage" of possibly fixing (AKA "generalizing") how your attributes >>> are accessed is something you lug around while your deadline looms. >> Sorry I don't get it. If I want to customize t

Re: Declarative properties

2007-10-12 Thread Chris Mellon
On 10/12/07, Dan Stromberg <[EMAIL PROTECTED]> wrote: > On Fri, 12 Oct 2007 09:42:28 +0200, Bruno Desthuilliers wrote: > > >>> So what? Otherwise you carry *always* the baggage of a public > >>> property and a private attribute whether you need this or not. At > >>> least for me it would be unnec

Re: Declarative properties

2007-10-12 Thread Dan Stromberg
On Thu, 11 Oct 2007 18:42:16 +, Marc 'BlackJack' Rintsch wrote: >> The "baggage" of possibly fixing (AKA "generalizing") how your attributes >> are accessed is something you lug around while your deadline looms. > > Sorry I don't get it. If I want to customize the access to a "normal" > att

Re: Declarative properties

2007-10-12 Thread George Sakkis
On Oct 12, 2:55 pm, Dan Stromberg <[EMAIL PROTECTED]> wrote: > If you have a program that needs to perform well, you're much better off > coding your classes the best way you know how from a Software Engineering > perspective, and using pysco or shedskin or pypy or similar to > improve performance

Re: Declarative properties

2007-10-12 Thread Dan Stromberg
On Fri, 12 Oct 2007 09:42:28 +0200, Bruno Desthuilliers wrote: >>> So what? Otherwise you carry *always* the baggage of a public >>> property and a private attribute whether you need this or not. At >>> least for me it would be unnecessary in most cases. >> >> That "baggage" of carrying around

Re: Declarative properties

2007-10-12 Thread Stargaming
On Thu, 11 Oct 2007 18:58:44 +0200, Bruno Desthuilliers wrote: [snip] Your implementation seems particularly broken. You do not return anything from `name()`, hereby removing name as an attribute (or: replacing it with its return value -- None). You should return ``property(**locals()) `` (or ``

Re: Declarative properties

2007-10-12 Thread Bruno Desthuilliers
Artur Siekielski a écrit : > George Sakkis wrote: >> By now you must have been convinced that default getters/setters is >> not a very useful idea in Python but this does not mean you can't do >> it; > > It's a perfect summary of my thoughts after reading this thread. I > will use public attribute

Re: Declarative properties

2007-10-12 Thread Bruno Desthuilliers
Dan Stromberg a écrit : > On Thu, 11 Oct 2007 13:46:12 +, Marc 'BlackJack' Rintsch wrote: > >> On Thu, 11 Oct 2007 13:04:53 +, Artur Siekielski wrote: >> >>> On Oct 11, 2:27 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: But why? Default getters and setters are unnecessary a

Re: Declarative properties

2007-10-12 Thread Artur Siekielski
George Sakkis wrote: > By now you must have been convinced that default getters/setters is > not a very useful idea in Python but this does not mean you can't do > it; It's a perfect summary of my thoughts after reading this thread. I will use public attributes (with access customizable with prope

Re: Declarative properties

2007-10-11 Thread George Sakkis
On Oct 11, 7:04 pm, George Sakkis <[EMAIL PROTECTED]> wrote: > You could take it even further by removing the need to repeat the > attribute's name twice. Currently this can done only through > metaclasses but in the future a class decorator would be even > better: Replying to myself here, but ac

Re: Declarative properties

2007-10-11 Thread George Sakkis
On Oct 11, 7:48 am, Artur Siekielski <[EMAIL PROTECTED]> wrote: > I know about 'property' function in Python, but it's normal usage > isn't declarative, because I have to code imperatively getters and > setters: > > class Person(object): >def __init__(self, name): > self._name = name >

Re: Declarative properties

2007-10-11 Thread Paul Hankin
On Oct 11, 7:42 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > Sorry I don't get it. If I want to customize the access to a "normal" > attribute I simply turn it into a property. I *think* I understand Artur's problem: he wants to be able to add (for example) clean-up and validation co

Re: Declarative properties

2007-10-11 Thread Paul Hankin
On Oct 11, 12:48 pm, Artur Siekielski <[EMAIL PROTECTED]> wrote: > Hi. > > I would like to have declarative properties in Python, ie. something > like slots definitions in defclass in Common Lisp. It seems that even > Java will have it, using a library (https://bean-pr

Re: Declarative properties

2007-10-11 Thread Marc 'BlackJack' Rintsch
On Thu, 11 Oct 2007 09:58:48 -0700, Dan Stromberg wrote: > On Thu, 11 Oct 2007 13:46:12 +, Marc 'BlackJack' Rintsch wrote: > >> On Thu, 11 Oct 2007 13:04:53 +, Artur Siekielski wrote: >> >>> 1. If I use instance field 'name' which is accessed directly by other >>> classes, >>> and later

Re: Declarative properties

2007-10-11 Thread Dan Stromberg
On Thu, 11 Oct 2007 13:46:12 +, Marc 'BlackJack' Rintsch wrote: > On Thu, 11 Oct 2007 13:04:53 +, Artur Siekielski wrote: > >> On Oct 11, 2:27 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: >>> But why? Default getters and setters are unnecessary and if you need >>> something ot

Re: Declarative properties

2007-10-11 Thread Bruno Desthuilliers
Artur Siekielski a écrit : > On Oct 11, 4:21 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: >> In practice, it turns out to be a lot less work to deal with that >> occasionally than to always deal with lugging around internal >> attributes and external properties when they're really not needed.

Re: Declarative properties

2007-10-11 Thread Bruno Desthuilliers
Artur Siekielski a écrit : > On Oct 11, 2:27 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: >> But why? Default getters and setters are unnecessary and if you need >> something other than the default you need to write it anyway more >> explicitly. > > I see some problems with your approa

Re: Declarative properties

2007-10-11 Thread Bruno Desthuilliers
Artur Siekielski a écrit : > Hi. > > I would like to have declarative properties in Python, ie. something > like slots definitions in defclass in Common Lisp. It seems that even > Java will have it, using a library ( https://bean-properties.dev.java.net/ > ). > > I know a

Re: Declarative properties

2007-10-11 Thread Marc 'BlackJack' Rintsch
On Thu, 11 Oct 2007 15:39:29 +, Artur Siekielski wrote: > On Oct 11, 4:21 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: >> > 2. Properties define (a part of) public interface of a class. When >> > using fields for public access, you must tell this explicitly in >> > documentation, or use

Re: Declarative properties

2007-10-11 Thread Artur Siekielski
On Oct 11, 4:21 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > In practice, it turns out to be a lot less work to deal with that > occasionally than to always deal with lugging around internal > attributes and external properties when they're really not needed. By > writing everything as pro

Re: Declarative properties

2007-10-11 Thread [EMAIL PROTECTED]
Artur Siekielski wrote: > On Oct 11, 2:27 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > > But why? Default getters and setters are unnecessary and if you need > > something other than the default you need to write it anyway more > > explicitly. > > I see some problems with your approac

Re: Declarative properties

2007-10-11 Thread Marc 'BlackJack' Rintsch
On Thu, 11 Oct 2007 13:04:53 +, Artur Siekielski wrote: > On Oct 11, 2:27 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: >> But why? Default getters and setters are unnecessary and if you need >> something other than the default you need to write it anyway more >> explicitly. > > I

Re: Declarative properties

2007-10-11 Thread Artur Siekielski
On Oct 11, 2:27 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > But why? Default getters and setters are unnecessary and if you need > something other than the default you need to write it anyway more > explicitly. I see some problems with your approach: 1. If I use instance field 'nam

Re: Declarative properties

2007-10-11 Thread Marc 'BlackJack' Rintsch
On Thu, 11 Oct 2007 11:48:18 +, Artur Siekielski wrote: > class Person(object): >def __init__(self, name): > self._name = name >def _get_name(self): > return self._name >def _set_name(self, new_name): > self._name = new_name >name = property(_get_name, _set_na

Declarative properties

2007-10-11 Thread Artur Siekielski
Hi. I would like to have declarative properties in Python, ie. something like slots definitions in defclass in Common Lisp. It seems that even Java will have it, using a library ( https://bean-properties.dev.java.net/ ). I know about 'property' function in Python, but it's nor