On Mon, May 2, 2016 at 6:26 PM, Michael Orlitzky <mich...@orlitzky.com> wrote: > On 05/02/2016 06:07 AM, Erik Bray wrote: >> On Mon, May 2, 2016 at 10:35 AM, Jeroen Demeyer <jdeme...@cage.ugent.be> >> wrote: >>> My vote: >>> >>>> [X] Phase out properties which perform any non-trivial computation >>> >>> >>> In certain cases, properties might be useful (but it could very well be that >>> there are 0 such cases in Sage). >> >> I generally feel that properties *should* be used in general for >> invariants of some object, regardless of how it's computed in the >> first place. I see the point about not using them for "non-trivial" >> computations but I also find the lack of a clear definition of >> "non-trivial" troubling. >> > > Properties, in any programming language, are syntactic sugar over > getter/setter methods on private member variables. In a language like > C#, they're useful and you have a sensible rule for when to use them: > use properties to get/set private member variables, and methods for > everything else. So basically, properties do no computation at all. > > In python, all member variables are public, so the concept of a property > is a bit redundant. It's hard to come up with a "when to use properties" > rule in python, because the only rule that makes sense doesn't apply. > Anywhere you could use a property, you can use a "public" member > variable instead (if you can't, then you wanted a method to begin with). > > The one useful feature of @property is that it lets you document your > member variables. If I have a class with a "public" nrows member > variable, then I can't document it so that when a user runs foo.nrows?, > it tells him what that variable is supposed to do. By creating a > property (which is only syntactic sugar over a getter method), I gain > the ability to add a docstring on what would otherwise be a variable.
I can say from significant experience that that is *not* the only useful feature of property. Let's also not forget the even deeper magic that is the descriptor protocol in general. -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.