Re: Adding an interface to existing classes

2012-01-05 Thread Spencer Pearson
(I'm sorry for my delayed response -- I've been travelling and not had reliable Internet access.) On 2011-12-25, Ian Kelly wrote: > On Thu, Dec 22, 2011 at 1:21 AM, Spencer Pearson > wrote: >> I see a problem with this, though. The intersection of two lines is >> (usually) an object of type Point

Re: Adding an interface to existing classes

2012-01-05 Thread Spencer Pearson
On Dec 25 2011, 2:58 pm, Terry Reedy wrote: > On 12/24/2011 6:49 PM,SpencerPearsonwrote: > > > On Dec 23, 9:13 am, Terry Reedy  wrote: > >> On 12/22/2011 3:21 AM,SpencerPearsonwrote: > > >>> I'm writing a geometry package, with Points and Lines and Circles and > >>> so on, and eventually I want to

Re: Adding an interface to existing classes

2012-01-05 Thread Spencer Pearson
(I'm sorry for my delayed response -- I've been travelling and not had reliable Internet access.) >> Spencer, i would re-think this entire project from the >> beginning. You are trying to make an object out of everything. You >> don't need to make an object of EVERYTHING. > > Very true. I'm not s

Re: Adding an interface to existing classes

2011-12-25 Thread Chris Angelico
On Mon, Dec 26, 2011 at 12:46 AM, Steven D'Aprano wrote: > class DrawableLine(Line): >    intersection_kind = DrawablePoint Ha! That works. I was sure there'd be some simple way to do it! ChrisA -- http://mail.python.org/mailman/listinfo/python-list

Re: Adding an interface to existing classes

2011-12-25 Thread Steven D'Aprano
On Mon, 26 Dec 2011 00:37:22 +1100, Chris Angelico wrote: > On Mon, Dec 26, 2011 at 12:27 AM, Steven D'Aprano > wrote: >> There's nothing in the above that assumes that other has the same type >> as self. It's just that the type of other is ignored, and the type of >> self always wins. I find tha

Re: Adding an interface to existing classes

2011-12-25 Thread Chris Angelico
On Mon, Dec 26, 2011 at 12:27 AM, Steven D'Aprano wrote: > There's nothing in the above that assumes that other has the same type as > self. It's just that the type of other is ignored, and the type of self > always wins. I find that a nice, clear rule: x.intersection(y) always > returns a point w

Re: Adding an interface to existing classes

2011-12-25 Thread Steven D'Aprano
On Sun, 25 Dec 2011 23:32:41 +1100, Chris Angelico wrote: > On Sun, Dec 25, 2011 at 11:10 PM, Steven D'Aprano > wrote: >> class Point:  # An abstract class. >>    def intersect(self, other): >>        blah; blah; blah >>        return Point(x, y)  # No, wrong, bad!!! Don't do this. >> >> Instead:

Re: Adding an interface to existing classes

2011-12-25 Thread Chris Angelico
On Sun, Dec 25, 2011 at 11:10 PM, Steven D'Aprano wrote: > class Point:  # An abstract class. >    def intersect(self, other): >        blah; blah; blah >        return Point(x, y)  # No, wrong, bad!!! Don't do this. > > Instead: > >        return self.__class__(x, y)  # Better. This would work i

Re: Adding an interface to existing classes

2011-12-25 Thread Steven D'Aprano
On Sat, 24 Dec 2011 17:24:14 -0800, Rick Johnson wrote: >> class DrawablePoint( geometry.Point ): >>     class draw( self, ... ): >>         ... > > "DrawablePoint"? I suppose there is an "ImaginaryPoint" somewhere in > this API? Geez No, but there's an abstract Point, which presumably refers to

Re: Adding an interface to existing classes

2011-12-24 Thread Terry Reedy
On 12/24/2011 6:49 PM, Spencer Pearson wrote: On Dec 23, 9:13 am, Terry Reedy wrote: On 12/22/2011 3:21 AM, Spencer Pearson wrote: I'm writing a geometry package, with Points and Lines and Circles and so on, and eventually I want to be able to draw these things on the screen. I have two optio

Re: Adding an interface to existing classes

2011-12-24 Thread Rick Johnson
On Dec 22, 2:21 am, Spencer Pearson wrote: > I'm writing a geometry package, with Points and Lines and Circles and > so on, and eventually I want to be able to draw these things on the > screen. ...which is the main reason for creating a geometry package in the first place!. I mean, imaginary poi

Re: Adding an interface to existing classes

2011-12-24 Thread Ian Kelly
On Thu, Dec 22, 2011 at 1:21 AM, Spencer Pearson wrote: > I see a problem with this, though. The intersection of two lines is > (usually) an object of type Point. Since DrawableLine inherits from > Line, this means that unless I redefine the "intersect" method in > DrawableLine, the intersection o

Re: Adding an interface to existing classes

2011-12-24 Thread Spencer Pearson
On Dec 23, 9:13 am, Terry Reedy wrote: > On 12/22/2011 3:21 AM, Spencer Pearson wrote: > > > I'm writing a geometry package, with Points and Lines and Circles and > > so on, and eventually I want to be able to draw these things on the > > screen. I have two options so far for how to accomplish thi

Re: Adding an interface to existing classes

2011-12-22 Thread Terry Reedy
On 12/22/2011 3:21 AM, Spencer Pearson wrote: I'm writing a geometry package, with Points and Lines and Circles and so on, and eventually I want to be able to draw these things on the screen. I have two options so far for how to accomplish this, but neither of them sits quite right with me, and I

Adding an interface to existing classes

2011-12-22 Thread Spencer Pearson
I'm writing a geometry package, with Points and Lines and Circles and so on, and eventually I want to be able to draw these things on the screen. I have two options so far for how to accomplish this, but neither of them sits quite right with me, and I'd like the opinion of comp.lang.python's wizene