Method default argument whose type is the class not yet defined

Oscar Benjamin oscar.j.benjamin at gmail.com
Sun Nov 11 15:21:19 CET 2012


On 11 November 2012 02:47, Chris Angelico <rosuav at gmail.com> wrote:
> On Sun, Nov 11, 2012 at 1:43 PM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
>> On Sat, Nov 10, 2012 at 7:13 PM, Chris Angelico <rosuav at gmail.com> wrote:
>>> I would not assume that. The origin is a point, just like any other.
>>> With a Line class, you could deem a zero-length line to be like a
>>> zero-element list, but Point(0,0) is more like the tuple (0,0) which
>>> is definitely True.
>>
>> It's more like the number 0 than the tuple (0,0).
>>
>> 0 is the origin on a 1-dimensional number line.
>> (0,0) is the origin on a 2-dimensional number plane.
>>
>> In fact, it might be pointed out that Point(0, 0) is a generalization
>> of 0+0j, which is equal to 0.
>
> Ah, good point. In any case, though, it'd be an utterly inconsequential bug.

You were right the first time, Chris. A point that happens to coincide
with the arbitrarily chosen origin is no more truthy or falsey than
any other. A vector of length 0 on the other hand is a very different
beast.

The significance of zero in real algebra is not that it is the origin
but rather that it is the additive and multiplicative zero:

   a + 0 = a  for any real number a
   a * 0 = 0 for any real number a

The same is true for a vector v0, of length 0:

   v + v0 = v for any vector v
   a * v0 = v0 for any scalar a

There is however no meaningful sense in which points (as opposed to
vectors) can be added to each other or multiplied by anything, so
there is no zero point.

The relationship between points and vectors is analogous to the
relationship between datetimes and timedeltas. Having Vector(0, 0)
evaluate to False is analogous to having timedelta(0) evaluate to
False and is entirely sensible. Having Point(0, 0) evaluate to False
is precisely the same conceptual folly that sees midnight evaluate as
False.


Oscar


More information about the Python-list mailing list