On Sat, Jun 18, 2011 at 10:01 AM, Masklinn <maskl...@masklinn.net> wrote:

> On 2011-06-18, at 15:05 , Ethan Jucovy wrote:
> > I tend to avoid @property -- it adds conceptual overhead for code
> > readers (hiding the fact that a function call is taking place) for little
> > gain.
> You *do* realize that django model (and form) fields are descriptors, and
> any access to a model or form field will result in a bunch of method calls
> right?

On Sat, Jun 18, 2011 at 10:07 AM, bruno desthuilliers <
bruno.desthuilli...@gmail.com> wrote:

> Would you say that the way the attribute lookup mechanism and
> descriptor protocol are used to turn function class attributes into
> methods "adds conceptual overhead for little gain"


These caricatures are a little unnecessary, aren't they?  Obviously this is
just the way that I like to lean in my own code (which was what the OP
asked) not a hard and fast rule that I want to apply to all Python code
regardless of the situation.

But even then, since adding extra params means you'll have to fix
> client code, the "less refactoring" argument doesn't stand IMHO.
>

My downstream code styles differ for the two cases -- for example, when I'm
accessing attributes I access them as needed, even if I re-get the same
attribute multiple times in a single code block; when I'm using the return
value of a function I store it in a local variable rather than doing
multiple calls.  So I still have to fix client code, but *less* of it.  Etc.

All this being said, I wholefully agree that while computed attributes
> are very handy, one should not go over the top and use them for no
> good reason - simple code is hard enough to maintain.
>

Exactly, that's really all I meant.  When I started out with Python I
totally overused @property including for things that were semantically
zero-argument methods (I'm really not sure why) and my code became
unnecessarily hard to maintain and reason about.  So now I like to lean in
the other direction.  I still use properties plenty, but I like to keep some
pushback in my head.  Generally I'd rather refactor a method into a property
than a property into a method.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to