title: When to use "property" builtin: auxiliary functions and generators
body: <p>I recently discovered Python's <a href="http://docs.python.org/library/functions.html#property" rel="noreferrer"><code>property</code> built-in</a>, which disguises class method getters and setters as a class's property. I'm now being tempted to use it in ways that I'm pretty sure are inappropriate.</p>
  
  <p>Using the <code>property</code> keyword is clearly the right thing to do if class <code>A</code> has a property <code>_x</code> whose allowable values you want to restrict; i.e., it would replace the <code>getX()</code> and <code>setX()</code> construction one might write in C++.</p>
  
  <p>But where else is it appropriate to make a function a property? For example, if you have</p>
  
  <pre><code>class Vertex(object):
      def __init__(self):
          self.x = 0.0
          self.y = 1.0
  
  class Polygon(object):
      def __init__(self, list_of_vertices):
          self.vertices = list_of_vertices
      def get_vertex_positions(self):
          return zip( *( (v.x,v.y) for v in self.vertices ) )
  </code></pre>
  
  <p>is it appropriate to add</p>
  
  <pre><code>    vertex_positions = property( get_vertex_positions )
  </code></pre>
  
  <p>?</p>
  
  <p>Is it ever ok to make a generator look like a property? Imagine if a change in our code meant that we no longer stored <code>Polygon.vertices</code> the same way. Would it then be ok to add this to <code>Polygon</code>?</p>
  
  <pre><code>    @property
      def vertices(self):
          for v in self._new_v_thing:
              yield v.calculate_equivalent_vertex()
  </code></pre>